Skip to content
Snippets Groups Projects
Select Git revision
  • 96d165db913723c227191f878527b9b73b77a4cc
  • master default protected
  • update-min-openvox-version-07f8cb2
  • cleanup_fixtures
  • add-openvox
  • freebsd-14
  • remove-legacy-top-scope-syntax
  • rel430
  • tests
  • revert-363-augeas-module-cleanup
  • release-4.1.0
  • puppet8
  • relax-dependencies
  • rel400
  • mode
  • puppet7
  • release-3.1.0
  • freebsd13
  • freebsd11
  • stdlib
  • centos
  • v6.0.0
  • v5.1.0
  • v5.0.0
  • v4.5.0
  • v4.4.0
  • v4.3.0
  • v4.2.1
  • v4.2.0
  • v4.1.0
  • v4.0.0
  • v3.1.0
  • v3.0.0
  • v2.0.0
  • 1.12.0
  • 1.11.0
  • 1.10.0
  • 1.9.0
  • 1.8.0
  • 1.7.0
  • 1.6.0
41 results

mailman.pp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AbstractFactory.php 2.06 KiB
    <?php
    namespace UnicaenAuth\Authentication\Adapter;
    
    use UnicaenApp\Exception;
    use UnicaenAuth\Authentication\Adapter\Cas;
    use UnicaenAuth\Authentication\Adapter\Db;
    use UnicaenAuth\Authentication\Adapter\Ldap;
    use Zend\ServiceManager\AbstractFactoryInterface;
    use Zend\ServiceManager\ServiceLocatorInterface;
    
    /**
     * Description of AbstractFactory
     *
     * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
     */
    class AbstractFactory implements AbstractFactoryInterface
    {
        /**
         * Determine if we can create a service with name
         *
         * @param ServiceLocatorInterface $serviceLocator
         * @param $name
         * @param $requestedName
         * @return bool
         */
        public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
        {
            return strpos($requestedName, __NAMESPACE__) === 0 && class_exists($requestedName);
        }
    
        /**
         * Create service with name
         *
         * @param ServiceLocatorInterface $serviceLocator
         * @param $name
         * @param $requestedName
         * @return mixed
         */
        public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
        {
            switch ($requestedName) {
                case __NAMESPACE__ . '\Ldap':
                    $adapter = new Ldap();
                    break;
                case __NAMESPACE__ . '\Db':
                    $adapter = new Db();
                    break;
                case __NAMESPACE__ . '\Cas':
                    $adapter = new Cas();
                    break;
                default:
                    throw new Exception("Service demandé inattendu : '$requestedName'!");
                    break;
            }
            
            if ($adapter instanceof \Zend\EventManager\EventManagerAwareInterface) {
                $userService  = $serviceLocator->get('unicaen-auth_user_service');
                $eventManager = $serviceLocator->get('event_manager');
                $eventManager->attach('userAuthenticated', array($userService, 'userAuthenticated'), 1);
                $adapter->setEventManager($eventManager);
            }
            
            return $adapter;
        }
    }