/** * {@inheritDoc} * * @return \Zend\View\Helper\Identity */ public function createService(ServiceLocatorInterface $serviceLocator) { $services = $serviceLocator->getServiceLocator(); $helper = new Identity(); if ($services->has('Zend\\Authentication\\AuthenticationService')) { $helper->setAuthenticationService($services->get('Zend\\Authentication\\AuthenticationService')); } return $helper; }
/** * Create service * * @param ServiceLocatorInterface $serviceLocator * * @return Identity */ public function createService(ServiceLocatorInterface $serviceLocator) { /** @var HelperPluginManager $serviceLocator */ $serviceLocator = $serviceLocator->getServiceLocator(); /** @var DbStorage $storage */ $storage = $serviceLocator->get(DbStorage::class); $authentication = new AuthenticationService($storage); $identity = new Identity(); $identity->setAuthenticationService($authentication); return $identity; }
/** * {@inheritDoc} * * @param ContainerInterface $container * @param string $name * @param null|array $options * @return \Zend\View\Helper\Identity */ public function __invoke(ContainerInterface $container, $name, array $options = null) { // test if we are using Zend\ServiceManager v2 or v3 if (!method_exists($container, 'configure')) { $container = $container->getServiceLocator(); } $helper = new Identity(); if ($container->has('Zend\\Authentication\\AuthenticationService')) { $helper->setAuthenticationService($container->get('Zend\\Authentication\\AuthenticationService')); } return $helper; }
/** * Constructor * * After invoking parent constructor, add an initializer to inject the * attached renderer and translator, if any, to the currently requested helper. * * @param null|ConfigInterface $configuration */ public function __construct(ConfigInterface $configuration = null) { parent::__construct($configuration); $this->setFactory('identity', function ($helpers) { $services = $helpers->getServiceLocator(); $helper = new Helper\Identity(); if (!$services->has('Zend\\Authentication\\AuthenticationService')) { return $helper; } $helper->setAuthenticationService($services->get('Zend\\Authentication\\AuthenticationService')); return $helper; }); $this->addInitializer(array($this, 'injectRenderer'))->addInitializer(array($this, 'injectTranslator')); }
public function testGetIdentity() { $identity = new TestAsset\IdentityObject(); $identity->setUsername('a username'); $identity->setPassword('a password'); $authenticationService = new AuthenticationService(new NonPersistentStorage(), new TestAsset\AuthenticationAdapter()); $identityHelper = new IdentityHelper(); $identityHelper->setAuthenticationService($authenticationService); $this->assertNull($identityHelper()); $this->assertFalse($authenticationService->hasIdentity()); $authenticationService->getAdapter()->setIdentity($identity); $result = $authenticationService->authenticate(); $this->assertTrue($result->isValid()); $this->assertEquals($identity, $identityHelper()); }
/** * Fetches the entity from the database * @return object|null */ public function __invoke() { //check whether the entity has alrady been fetched if (!is_null($this->entity)) { return $this->entity; } //get the identity $identity = parent::__invoke(); //check the entity is not null if (is_null($identity)) { return null; } //fetch the identity object $sm = $this->getServiceLocator()->getServiceLocator(); $options = $sm->get('deit_authentication_options'); $callback = $options->getFetchEntityFromIdentityCallback(); if (is_null($callback)) { $this->entity = $identity; } else { $this->entity = call_user_func_array($callback, array($identity, $sm)); } return $this->entity; }