/** * {@inheritDoc} */ public function createService(ServiceLocatorInterface $helpers) { $locator = $helpers->getServiceLocator(); $viewHelper = new ZfcUserDisplayName(); $viewHelper->setAuthService($locator->get('zfcuser_auth_service')); return $viewHelper; }
public function setUp() { $helper = new ViewHelper(); $this->helper = $helper; $authService = $this->getMock('Zend\\Authentication\\AuthenticationService'); $this->authService = $authService; $user = $this->getMock('ZfcUser\\Entity\\User'); $this->user = $user; $helper->setAuthService($authService); }
/** * {@inheritDoc} */ public function createService(ServiceLocatorInterface $pluginManager) { /* @var $pluginManager HelperPluginManager */ $serviceManager = $pluginManager->getServiceLocator(); /* @var $authService AuthenticationService */ $authService = $serviceManager->get('zfcuser_auth_service'); $viewHelper = new ZfcUserDisplayName(); $viewHelper->setAuthService($authService); return $viewHelper; }
public function getViewHelperConfig() { return array('factories' => array('zfcUserDisplayName' => function ($sm) { $locator = $sm->getServiceLocator(); $viewHelper = new View\Helper\ZfcUserDisplayName(); $viewHelper->setAuthService($locator->get('zfcuser_auth_service')); return $viewHelper; }, 'zfcUserIdentity' => function ($sm) { $locator = $sm->getServiceLocator(); $viewHelper = new View\Helper\ZfcUserIdentity(); $viewHelper->setAuthService($locator->get('zfcuser_auth_service')); return $viewHelper; }, 'zfcUserLoginWidget' => function ($sm) { $locator = $sm->getServiceLocator(); $viewHelper = new View\Helper\ZfcUserLoginWidget(); $viewHelper->setLoginForm($locator->get('zfcuser_login_form')); return $viewHelper; })); }
/** * __invoke returns a string containing the display name of the 'real user' if impersonation is currently in * progress, otherwise returns false. * * The bulk of the work is delegated to the ZfcUserDisplayName view helper. * * @return String */ public function __invoke(UserInterface $user = null) { // Only continue if impersonation is currently in progress, otherwise return false. if ($this->getUserService()->isImpersonated()) { // Get the 'real user' from the storage container. $realUser = $this->getUserService()->getStorageForImpersonator()->read(); // If the stored 'real user' is not of the correct type, throw an exception. if (!$realUser instanceof UserInterface) { throw new DomainException('$realUser is not an instance of UserInterface', 500); } } else { // No impersonation is currently in progress. return false; } // The bulk of the work is delegated to the ZfcUserDisplayName view helper. return parent::__invoke($realUser); }