Skip to content
Snippets Groups Projects
Select Git revision
  • dd5c8b6035f04ee211dd5b4fe4077c882b4136e2
  • master default protected
  • 5.x
  • ll-php8-bs5
  • release_5_bs5
  • ll-php8
  • 4.x
  • laminas_migration
  • release_1.0.0.2
  • release_4.0.0
  • release_3.2.8
  • bootstrap4_migration
  • 1.0.0.3
  • 6.0.7
  • 6.0.6
  • 6.0.5
  • 6.0.4
  • 6.0.3
  • 6.0.2
  • 6.0.1
  • 5.1.1
  • 6.0.0
  • 5.1.0
  • 5.0.0
  • 4.0.2
  • 3.2.11
  • 4.0.1
  • 3.2.10
  • 4.0.0
  • 1.0.0.2
  • 3.2.9
  • 3.2.8
32 results

LocalAdapterFactory.php

Blame
  • Bertrand GAUTHIER's avatar
    Bertrand Gauthier authored
    Configuration de la stratégie d'extraction d'un identifiant utile parmi les données d'authentification shibboleth (config 'shib_user_id_extractor').
    ca7e11b1
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    LocalAdapterFactory.php 1.81 KiB
    <?php
    
    namespace UnicaenAuth\Authentication\Adapter;
    
    use Interop\Container\ContainerInterface;
    use UnicaenAuth\Options\ModuleOptions;
    use Zend\Authentication\Storage\Session;
    use Zend\EventManager\EventManager;
    
    class LocalAdapterFactory
    {
        /**
         * @param ContainerInterface $container
         * @param string $requestedName
         * @return LocalAdapter
         */
        public function __invoke(ContainerInterface $container, string $requestedName)
        {
            /** @var ModuleOptions $options */
            $options = $container->get('unicaen-auth_module_options');
    
            $localAdapter = new LocalAdapter();
            $localAdapter->setEventManager(new EventManager());
            $localAdapter->setStorage(new Session(LocalAdapter::class));
            $localAdapter->setModuleOptions($options);
    
            $localConfig = $options->getLocal();
    
            // db adapter
            if (array_key_exists('db', $localConfig)) {
                $this->attachSubAdapter($localAdapter, $container, $localConfig['db'], 20); // en 1er
            }
            // ldap adapter
            if (array_key_exists('ldap', $localConfig)) {
                $this->attachSubAdapter($localAdapter, $container, $localConfig['ldap'], 10); // en 2e
            }
    
            return $localAdapter;
        }
    
        /**
         * @param LocalAdapter $localAdapter
         * @param ContainerInterface $container
         * @param array $config
         * @param int $priority
         */
        private function attachSubAdapter(LocalAdapter $localAdapter, ContainerInterface $container, array $config, int $priority)
        {
            $enabled = isset($config['enabled']) && $config['enabled'] === true;
            if (! $enabled) {
                return;
            }
    
            /** @var AbstractAdapter $subAdapter */
            $subAdapter = $container->get($config['adapter']);
            $subAdapter->attach($localAdapter->getEventManager(), $priority);
        }
    
    }