Module class getConfig() method does not need to be static
[zf2.biz/galerie.git] / modules / Application / Module.php
1 <?php
2
3 namespace Application;
4
5 use InvalidArgumentException,
6     Zend\Module\Manager,
7     Zend\Config\Config,
8     Zend\Di\Locator,
9     Zend\EventManager\EventCollection,
10     Zend\EventManager\StaticEventCollection;
11
12 class Module
13 {
14     protected $appListeners    = array();
15     protected $staticListeners = array();
16     protected $viewListener;
17
18     public function init(Manager $moduleManager)
19     {
20         $this->initAutoloader($moduleManager->getOptions()->getApplicationEnv());
21     }
22
23     protected function initAutoloader($env = null)
24     {
25         require __DIR__ . '/autoload_register.php';
26     }
27
28     public function getConfig()
29     {
30         return new Config(include __DIR__ . '/configs/module.config.php');
31     }
32     
33     public function registerApplicationListeners(EventCollection $events, Locator $locator, Config $config)
34     {
35         $view          = $locator->get('view');
36         $viewListener  = $this->getViewListener($view, $config);
37         $events->attachAggregate($viewListener);
38     }
39
40     public function registerStaticListeners(StaticEventCollection $events, Locator $locator, Config $config)
41     {
42         $view         = $locator->get('view');
43         $viewListener = $this->getViewListener($view, $config);
44
45         $viewListener->registerStaticListeners($events, $locator);
46     }
47
48     protected function getViewListener($view, $config)
49     {
50         if ($this->viewListener instanceof View\Listener) {
51             return $this->viewListener;
52         }
53
54         $viewListener       = new View\Listener($view, $config->layout);
55         $viewListener->setDisplayExceptionsFlag($config->display_exceptions);
56
57         $this->viewListener = $viewListener;
58         return $viewListener;
59     }
60 }