Remove $env parameter from initAutoloader method
[zf2.biz/galerie.git] / modules / Application / Module.php
1 <?php
2
3 namespace Application;
4
5 use Zend\Module\Manager,
6     Zend\EventManager\StaticEventManager,
7     Zend\Loader\AutoloaderFactory;
8
9 class Module
10 {
11     protected $view;
12     protected $viewListener;
13
14     public function init(Manager $moduleManager)
15     {
16         $this->initAutoloader();
17         $events = StaticEventManager::getInstance();
18         $events->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100);
19     }
20
21     protected function initAutoloader()
22     {
23         AutoloaderFactory::factory(array(
24             'Zend\Loader\ClassMapAutoloader' => array(
25                 __DIR__ . '/autoload_classmap.php',
26             ),
27             'Zend\Loader\StandardAutoloader' => array(
28                 'namespaces' => array(
29                     __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
30                 ),
31             ),
32         ));
33     }
34
35     public function getConfig($env = null)
36     {
37         return include __DIR__ . '/configs/module.config.php';
38     }
39     
40     public function initializeView($e)
41     {
42         $app          = $e->getParam('application');
43         $locator      = $app->getLocator();
44         $config       = $e->getParam('modules')->getMergedConfig();
45         $view         = $this->getView($app);
46         $viewListener = $this->getViewListener($view, $config);
47         $app->events()->attachAggregate($viewListener);
48         $events       = StaticEventManager::getInstance();
49         $viewListener->registerStaticListeners($events, $locator);
50     }
51
52     protected function getViewListener($view, $config)
53     {
54         if ($this->viewListener instanceof View\Listener) {
55             return $this->viewListener;
56         }
57
58         $viewListener       = new View\Listener($view, $config->layout);
59         $viewListener->setDisplayExceptionsFlag($config->display_exceptions);
60
61         $this->viewListener = $viewListener;
62         return $viewListener;
63     }
64
65     protected function getView($app)
66     {
67         if ($this->view) {
68             return $this->view;
69         }
70
71         $di     = $app->getLocator();
72         $view   = $di->get('view');
73         $url    = $view->plugin('url');
74         $url->setRouter($app->getRouter());
75
76         $view->plugin('headTitle')->setSeparator(' - ')
77                                   ->setAutoEscape(false)
78                                   ->append('Application');
79         $this->view = $view;
80         return $view;
81     }
82 }