5 use Zend\Module\Manager,
6 Zend\EventManager\StaticEventManager,
7 Zend\Loader\AutoloaderFactory;
12 protected $viewListener;
14 public function init(Manager $moduleManager)
16 $this->initAutoloader($moduleManager->getOptions()->getApplicationEnv());
17 $events = StaticEventManager::getInstance();
18 $events->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100);
21 protected function initAutoloader($env = null)
23 AutoloaderFactory::factory(array(
24 'Zend\Loader\ClassMapAutoloader' => array(
25 __DIR__ . '/autoload_classmap.php',
27 'Zend\Loader\StandardAutoloader' => array(
28 'namespaces' => array(
29 __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
35 public function getConfig()
37 return include __DIR__ . '/configs/module.config.php';
40 public function initializeView($e)
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);
52 protected function getViewListener($view, $config)
54 if ($this->viewListener instanceof View\Listener) {
55 return $this->viewListener;
58 $viewListener = new View\Listener($view, $config->layout);
59 $viewListener->setDisplayExceptionsFlag($config->display_exceptions);
61 $this->viewListener = $viewListener;
65 protected function getView($app)
71 $di = $app->getLocator();
72 $view = $di->get('view');
73 $url = $view->plugin('url');
74 $url->setRouter($app->getRouter());
76 $view->plugin('headTitle')->setSeparator(' - ')
77 ->setAutoEscape(false)
78 ->append('Application');