5 use InvalidArgumentException,
8 Zend\EventManager\StaticEventManager;
13 protected $viewListener;
15 public function init(Manager $moduleManager)
17 $this->initAutoloader($moduleManager->getOptions()->getApplicationEnv());
18 $events = StaticEventManager::getInstance();
19 $events->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100);
22 protected function initAutoloader($env = null)
24 require __DIR__ . '/autoload_register.php';
27 public function getConfig()
29 return new Config(include __DIR__ . '/configs/module.config.php');
32 public function initializeView($e)
34 $app = $e->getParam('application');
35 $locator = $app->getLocator();
36 $config = $e->getParam('modules')->getMergedConfig();
37 $view = $this->getView($app);
38 $viewListener = $this->getViewListener($view, $config);
39 $app->events()->attachAggregate($viewListener);
40 $events = StaticEventManager::getInstance();
41 $viewListener->registerStaticListeners($events, $locator);
44 protected function getViewListener($view, $config)
46 if ($this->viewListener instanceof View\Listener) {
47 return $this->viewListener;
50 $viewListener = new View\Listener($view, $config->layout);
51 $viewListener->setDisplayExceptionsFlag($config->display_exceptions);
53 $this->viewListener = $viewListener;
57 protected function getView($app)
63 $di = $app->getLocator();
64 $view = $di->get('view');
65 $url = $view->plugin('url');
66 $url->setRouter($app->getRouter());
68 $view->plugin('headTitle')->setSeparator(' - ')
69 ->setAutoEscape(false)
70 ->append('Application');