Skip to content
Snippets Groups Projects
Select Git revision
  • ae116d6c77fa48524ac49658516dc43d22d07ea9
  • master default protected
  • update-2.0.0-dev
  • alc-refactoring-entity
  • sb-comments-update
  • alc-dev
  • 2.0.2
  • 2.0.1
  • 2.0.0
  • 1.0.7
  • 1.0.6
  • 1.0.5
  • 1.0.4
  • 1.0.3
  • 1.0.2
  • 1.0.1
  • 0.1.5
  • 1.0.0
  • 0.1.4
  • 0.1.3
  • 0.1.2
  • 0.1.1
  • 0.0.15
  • 0.0.14
  • 0.0.13
  • 0.0.12
26 results

ui.md

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AdapterChainServiceFactory.php 2.55 KiB
    <?php
    namespace ZfcUser\Authentication\Adapter;
    
    use Interop\Container\ContainerInterface;
    use Interop\Container\Exception\ContainerException;
    use Zend\ServiceManager\Exception\ServiceNotCreatedException;
    use Zend\ServiceManager\Exception\ServiceNotFoundException;
    use Zend\ServiceManager\Factory\FactoryInterface;
    use Zend\ServiceManager\ServiceLocatorInterface;
    use ZfcUser\Authentication\Adapter\AdapterChain;
    use ZfcUser\Options\ModuleOptions;
    use ZfcUser\Authentication\Adapter\Exception\OptionsNotFoundException;
    
    class AdapterChainServiceFactory implements FactoryInterface
    {
        public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
        {
            $chain = new AdapterChain();
    
            $options = $this->getOptions($serviceLocator);
    
            //iterate and attach multiple adapters and events if offered
            foreach ($options->getAuthAdapters() as $priority => $adapterName) {
                $adapter = $serviceLocator->get($adapterName);
    
                if (is_callable(array($adapter, 'authenticate'))) {
                    $chain->getEventManager()->attach('authenticate', array($adapter, 'authenticate'), $priority);
                }
    
                if (is_callable(array($adapter, 'logout'))) {
                    $chain->getEventManager()->attach('logout', array($adapter, 'logout'), $priority);
                }
            }
    
            return $chain;
        }
    
        /**
         * @var ModuleOptions
         */
        protected $options;
    
        public function createService(ServiceLocatorInterface $serviceLocator)
        {
            $this->__invoke($serviceLocator, null);
        }
    
    
        /**
         * set options
         *
         * @param ModuleOptions $options
         * @return AdapterChainServiceFactory
         */
        public function setOptions(ModuleOptions $options)
        {
            $this->options = $options;
            return $this;
        }
    
        /**
         * get options
         *
         * @param ServiceLocatorInterface $serviceLocator (optional) Service Locator
         * @return ModuleOptions $options
         * @throws OptionsNotFoundException If options tried to retrieve without being set but no SL was provided
         */
        public function getOptions(ServiceLocatorInterface $serviceLocator = null)
        {
            if (!$this->options) {
                if (!$serviceLocator) {
                    throw new OptionsNotFoundException(
                        'Options were tried to retrieve but not set ' .
                        'and no service locator was provided'
                    );
                }
    
                $this->setOptions($serviceLocator->get('zfcuser_module_options'));
            }
    
            return $this->options;
        }
    }