5 use Zend\Module\Manager,
7 Zend\EventManager\StaticEventManager,
8 Zend\Loader\AutoloaderFactory;
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 AutoloaderFactory::factory(array(
25 'Zend\Loader\ClassMapAutoloader' => array(
26 __DIR__ . '/autoload_classmap.php',
28 'Zend\Loader\StandardAutoloader' => array(
29 'namespaces' => array(
30 __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
36 public function getConfig()
38 return new Config(include __DIR__ . '/configs/module.config.php');
41 public function initializeView($e)
43 $app = $e->getParam('application');
44 $locator = $app->getLocator();
45 $config = $e->getParam('modules')->getMergedConfig();
46 $view = $this->getView($app);
47 $viewListener = $this->getViewListener($view, $config);
48 $app->events()->attachAggregate($viewListener);
49 $events = StaticEventManager::getInstance();
50 $viewListener->registerStaticListeners($events, $locator);
53 protected function getViewListener($view, $config)
55 if ($this->viewListener instanceof View\Listener) {
56 return $this->viewListener;
59 $viewListener = new View\Listener($view, $config->layout);
60 $viewListener->setDisplayExceptionsFlag($config->display_exceptions);
62 $this->viewListener = $viewListener;
66 protected function getView($app)
72 $di = $app->getLocator();
73 $view = $di->get('view');
74 $url = $view->plugin('url');
75 $url->setRouter($app->getRouter());
77 $view->plugin('headTitle')->setSeparator(' - ')
78 ->setAutoEscape(false)
79 ->append('Application');