Skip to content
Snippets Groups Projects
Select Git revision
  • ll-php8-bs5
  • master default protected
  • 5.x
  • 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
31 results

Module.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Module.php 3.36 KiB
    <?php
    
    namespace UnicaenAuth;
    
    use Laminas\EventManager\EventInterface;
    use Laminas\ModuleManager\Feature\AutoloaderProviderInterface;
    use Laminas\ModuleManager\Feature\BootstrapListenerInterface;
    use Laminas\ModuleManager\Feature\ConfigProviderInterface;
    use Laminas\ModuleManager\Feature\ServiceProviderInterface;
    use Laminas\Mvc\MvcEvent;
    use UnicaenAuth\Event\Listener\LdapAuthenticationFailureLoggerListener;
    use UnicaenAuth\Options\ModuleOptions;
    
    /**
     * Point d'entrée du module d'authentification Unicaen.
     *
     * @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
     */
    class Module implements AutoloaderProviderInterface, ConfigProviderInterface, ServiceProviderInterface, BootstrapListenerInterface
    {
        /**
         * @var \UnicaenAuth\Options\ModuleOptions
         */
        private $moduleOptions;
    
        /**
         * @var \Laminas\EventManager\EventManagerInterface
         */
        private $eventManager;
    
        /**
         * @var \Laminas\ServiceManager\ServiceManager
         */
        private $serviceManager;
    
        /**
         * @return array
         * @see ConfigProviderInterface
         */
        public function getConfig()
        {
            return include __DIR__ . '/config/module.config.php';
        }
    
        /**
         * @return array
         * @see AutoloaderProviderInterface
         */
        public function getAutoloaderConfig()
        {
            return [
                'Laminas\Loader\StandardAutoloader' => [
                    'namespaces' => [
                        __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                    ],
                ],
            ];
        }
    
        /**
         * @inheritDoc
         */
        public function onBootstrap(EventInterface $e)
        {
            if ($e instanceof MvcEvent) {
                /** @var \Laminas\Mvc\Application $application */
                $application = $e->getApplication();
                $this->serviceManager = $application->getServiceManager();
                $this->eventManager = $application->getEventManager();
                $this->moduleOptions = $this->serviceManager->get(ModuleOptions::class);
    
                $this->attachEventListeners();
            }
        }
    
        protected function attachEventListeners()
        {
            // log éventuel des erreurs d'authentification LDAP
            $logLdapAuthenticationFailure = $this->moduleOptions->getLdap()['log_failures'] ?? false;
            if ($logLdapAuthenticationFailure) {
                /** @var LdapAuthenticationFailureLoggerListener $listener */
                $listener = $this->serviceManager->get(LdapAuthenticationFailureLoggerListener::class);
                $listener->attach($this->eventManager);
            }
        }
    
        /**
         * @return array
         * @see ServiceProviderInterface
         */
        public function getServiceConfig()
        {
            return [
                //========== repris du module zf-commons/zfc-user-doctrine-orm abandonné =========
                'aliases' => array(
                    'zfcuser_doctrine_em' => 'Doctrine\ORM\EntityManager',
                ),
                //===========================================
    
    
                'factories' => [
                    //========== repris du module zf-commons/zfc-user-doctrine-orm abandonné =========
                    'zfcuser_module_options' => function ($sm) {
                        $config = $sm->get('Configuration');
                        return new Options\ModuleOptions(isset($config['zfcuser']) ? $config['zfcuser'] : array());
                    },
                    //===========================================
    
                ],
            ];
        }
    }