Skip to content
Snippets Groups Projects
Select Git revision
  • a81033a2ee7abca62e11013f5562a079f2677d05
  • 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

AbstractFactory.php

Blame
  • Bertrand Gauthier's avatar
    Bertrand Gauthier authored
    Ajout possibilité d'écouter l'événement \UnicaenAuth\Service\User::EVENT_USER_AUTHENTICATED_PRE_PERSIST pour modifier l'entité avant qu'elle de soit persistée dans la table des utilisateurs.
    4f5c6f4d
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AbstractFactory.php 2.11 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) {
                $eventManager = $serviceLocator->get('event_manager');
                $adapter->setEventManager($eventManager);
                $userService = $serviceLocator->get('unicaen-auth_user_service'); /* @var $userService \UnicaenAuth\Service\User */
                $eventManager->attach('userAuthenticated', array($userService, 'userAuthenticated'), 100);
            }
            
            return $adapter;
        }
    }