src/Mvc/Listener/ViewModelIdentity.php
public function injectIdentityModel(MvcEvent $event)
	{
	    $viewModel = $event->getViewModel();
	    if ($viewModel->getTemplate() == 'layout/layout') {
	        $servies = $event->getApplication()->getServiceManager();
	        $appConfig = $servies->get('config');
	        if (isset($appConfig['view_model_identity'])) {
	            $config = $appConfig['view_model_identity'];
	        } else {
	            throw new \Exception('view_model_identity key not found in configuration');
	        }
	        if (!$servies->has($config['authenticationService'])) {
	            throw new \Exception('Auththentication service not found');
	        }
	        if (!$servies->has($config['identity'])) {
	            throw new \Exception('Identity not found');
	        }
	        $childViewModel = new IdentityViewModel(array(
	            'auth'     => $servies->get($config['authenticationService']),
	            'identity' => $servies->get($config['identity']),
	        ));
	        if (isset($config['template'])) {
	            $childViewModel->setTemplate($config['template']);
	        }
	        if (isset($config['captureTo'])) {
	            $childViewModel->setCaptureTo($config['captureTo']);
	        }
	        $viewModel->addChild($childViewModel);
	    }
	}
public function injectIdentityModel(MvcEvent $event)
	{
	    $viewModel = $event->getViewModel();
	    if ($viewModel->getTemplate() == 'layout/layout') {
	        $servies = $event->getApplication()->getServiceManager();
	        $appConfig = $servies->get('config');
	        if (isset($appConfig['view_model_identity'])) {
	            $config = $appConfig['view_model_identity'];
	        } else {
	            throw new \Exception('view_model_identity key not found in configuration');
	        }
	        if (!$servies->has($config['authenticationService'])) {
	            throw new \Exception('Auththentication service not found');
	        }
	        if (!$servies->has($config['identity'])) {
	            throw new \Exception('Identity not found');
	        }
	        $childViewModel = new IdentityViewModel(array(
	            'auth'     => $servies->get($config['authenticationService']),
	            'identity' => $servies->get($config['identity']),
	        ));
	        if (isset($config['template'])) {
	            $childViewModel->setTemplate($config['template']);
	        }
	        if (isset($config['captureTo'])) {
	            $childViewModel->setCaptureTo($config['captureTo']);
	        }
	        $viewModel->addChild($childViewModel);
	    }
	}
public function injectIdentityModel ( MvcEvent $ event ) { $ viewModel = $ event -> getViewModel ( ) ; if ( $ viewModel -> getTemplate ( ) == 'layout/layout' ) { $ servies = $ event -> getApplication ( ) -> getServiceManager ( ) ; $ appConfig = $ servies -> get ( 'config' ) ; if ( isset ( $ appConfig [ 'view_model_identity' ] ) ) { $ config = $ appConfig [ 'view_model_identity' ] ; } else { throw new \ Exception ( 'view_model_identity key not found in configuration' ) ; } if ( ! $ servies -> has ( $ config [ 'authenticationService' ] ) ) { throw new \ Exception ( 'Auththentication service not found' ) ; } if ( ! $ servies -> has ( $ config [ 'identity' ] ) ) { throw new \ Exception ( 'Identity not found' ) ; } $ childViewModel = new IdentityViewModel ( array ( 'auth' => $ servies -> get ( $ config [ 'authenticationService' ] ) , 'identity' => $ servies -> get ( $ config [ 'identity' ] ) , ) ) ; if ( isset ( $ config [ 'template' ] ) ) { $ childViewModel -> setTemplate ( $ config [ 'template' ] ) ; } if ( isset ( $ config [ 'captureTo' ] ) ) { $ childViewModel -> setCaptureTo ( $ config [ 'captureTo' ] ) ; } $ viewModel -> addChild ( $ childViewModel ) ; } }
Inject identity view model into layout

@param MvcEvent $event
@throws \Exception
Inject identity view model into layout