Module.php 1.61 KB
Newer Older
Bertrand Gauthier's avatar
Bertrand Gauthier committed
1
2
3
4
<?php

namespace Application;

5
6
7
8
use Laminas\Mvc\ModuleRouteListener;
use Laminas\Mvc\MvcEvent;
use Laminas\Http\Request as HttpRequest;
use Laminas\Session\SessionManager;
Bertrand Gauthier's avatar
Bertrand Gauthier committed
9
10
11
12
13

class Module
{
    public function onBootstrap(MvcEvent $e)
    {
Bertrand Gauthier's avatar
Bertrand Gauthier committed
14
15
16
17
        $application = $e->getApplication();
        $serviceManager = $application->getServiceManager();
        $serviceManager->get('translator');
        $eventManager = $application->getEventManager();
Bertrand Gauthier's avatar
Bertrand Gauthier committed
18
19
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);
20
21

        /* Active un layout spécial si la requête est de type AJAX. Valable pour TOUS les modules de l'application. */
22
        $eventManager->getSharedManager()->attach('Laminas\Mvc\Controller\AbstractActionController', 'dispatch',
23
24
25
26
27
28
29
            function (MvcEvent $e) {
                $request = $e->getRequest();
                if ($request instanceof HttpRequest && $request->isXmlHttpRequest()) {
                    $e->getTarget()->layout('layout/ajax.phtml');
                }
            }
        );
Bertrand Gauthier's avatar
Bertrand Gauthier committed
30
31
32
33

        // The following line instantiates the SessionManager and automatically
        // makes the SessionManager the 'default' one.
//        $serviceManager->get(SessionManager::class);
Bertrand Gauthier's avatar
Bertrand Gauthier committed
34
35
36
37
38
39
40
41
42
    }

    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function getAutoloaderConfig()
    {
43
        return [
44
            'Laminas\Loader\StandardAutoloader' => [
45
                'namespaces' => [
Bertrand Gauthier's avatar
Bertrand Gauthier committed
46
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
47
48
49
                ],
            ],
        ];
Bertrand Gauthier's avatar
Bertrand Gauthier committed
50
51
    }
}