Created
July 25, 2013 06:10
-
-
Save ThaDafinser/6077277 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyNamespace\View\Strategy; | |
use Zend\EventManager\ListenerAggregateInterface; | |
use Zend\ServiceManager\ServiceLocatorAwareInterface; | |
use Zend\ServiceManager\ServiceLocatorInterface; | |
use Zend\View\ViewEvent; | |
class MyStrategy implements ListenerAggregateInterface, ServiceLocatorAwareInterface | |
{ | |
public function selectRenderer (ViewEvent $e) | |
{ | |
$viewModel = $e->getModel(); | |
switch(get_class($viewModel)){ | |
case 'Zend\View\Model\JsonModel': | |
return $this->getServiceLocator()->get('viewJsonRenderer'); | |
break; | |
case 'Zend\View\Model\ViewModel': | |
return $this->getServiceLocator()->get('viewRenderer'); | |
break; | |
case 'MyNamespace\MyModel': | |
return $this->getServiceLocator()->get('myCustomRenderer'); | |
break; | |
default: | |
throw new \Exception('not supported renderer'); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment