Skip to content
Snippets Groups Projects
Select Git revision
  • a28e7fa5494031eb607c484cd60f8c087ec1c89f
  • develop default
  • master protected
  • unicaen_authentification
  • 5.x
  • 4.x
  • release_4.0.0
  • bootstrap4_migration
  • laminas_migration
  • zf-3.x
  • 7.1.0
  • 7.0.0
  • 6.1.0
  • 6.0.1
  • 6.0.0
  • 5.0.1
  • 5.0.0
  • 4.0.2
  • 4.0.1
  • 4.0.0
  • 3.0.0
  • 1.0.5
  • 1.0.4
  • 1.0.3
  • 1.0.2
  • 1.0.1
  • 1.0.0
27 results

Module.php

  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Module.php 1.70 KiB
    <?php
    
    namespace UnicaenFaq;
    
    use UnicaenApp\Exception\RuntimeException;
    use UnicaenFaq\Service\FaqService;
    use Zend\Mvc\ModuleRouteListener;
    use Zend\Mvc\MvcEvent;
    
    class Module
    {
        public function onBootstrap(MvcEvent $e)
        {
            $application = $e->getApplication();
            $application->getServiceManager()->get('translator');
            $eventManager = $application->getEventManager();
            $moduleRouteListener = new ModuleRouteListener();
            $moduleRouteListener->attach($eventManager);
    
            $this->checkModuleRequirements($e);
        }
    
        public function getConfig()
        {
            return include __DIR__ . '/config/module.config.php';
        }
    
        public function getAutoloaderConfig()
        {
            return [
                'Zend\Loader\StandardAutoloader' => [
                    'namespaces' => [
                        __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                    ],
                ],
            ];
        }
    
        public function checkModuleRequirements(MvcEvent $event)
        {
            $sl = $event->getApplication()->getServiceManager();
    
            /** @var FaqService $service */
            $service = $sl->get('UnicaenFaq\Service\FaqService');
    
            try {
                $service->checkSchema();
            }
            catch (\Exception $e) {
                $config = $sl->get('config');
                $pathsArray = glob($config['unicaen-faq']['db_schema_glob_paths']);
                throw new RuntimeException(sprintf(
                    "Vous avez activé le module UnicaenFaq mais le schéma de base de données est incorrect: %s. " .
                    "Reportez-vous aux scripts suivants : %s.",
                    $e->getMessage(),
                    implode(', ', array_map('realpath', $pathsArray))
                ));
            }
        }
    }