コード例 #1
0
 /**
  * {@inheritDoc}
  *
  * @return \Zend\Mvc\Controller\Plugin\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;
 }
コード例 #2
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  *
  * @return Identity
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var PluginManager $serviceLocator */
     $serviceLocator = $serviceLocator->getServiceLocator();
     $authentication = $serviceLocator->get(AuthenticationService::class);
     $identity = new Identity();
     $identity->setAuthenticationService($authentication);
     return $identity;
 }
コード例 #3
0
 /**
  * Constructor
  *
  * After invoking parent constructor, add an initializer to inject the
  * attached controller, if any, to the currently requested plugin.
  *
  * @param null|ConfigInterface $configuration
  */
 public function __construct(ConfigInterface $configuration = null)
 {
     parent::__construct($configuration);
     $this->setFactory('identity', function ($plugins) {
         $services = $plugins->getServiceLocator();
         $plugin = new Plugin\Identity();
         if (!$services->has('Zend\\Authentication\\AuthenticationService')) {
             return $plugin;
         }
         $plugin->setAuthenticationService($services->get('Zend\\Authentication\\AuthenticationService'));
         return $plugin;
     });
 }
コード例 #4
0
 public function testGetIdentity()
 {
     $identity = new TestAsset\IdentityObject();
     $identity->setUsername('a username');
     $identity->setPassword('a password');
     $authenticationService = new AuthenticationService(new NonPersistentStorage(), new TestAsset\AuthenticationAdapter());
     $identityPlugin = new IdentityPlugin();
     $identityPlugin->setAuthenticationService($authenticationService);
     $this->assertNull($identityPlugin());
     $this->assertFalse($authenticationService->hasIdentity());
     $authenticationService->getAdapter()->setIdentity($identity);
     $result = $authenticationService->authenticate();
     $this->assertTrue($result->isValid());
     $this->assertEquals($identity, $identityPlugin());
 }