4 use Zend\Config\Config,
5 Zend\Di\Configuration as DiConfiguration,
7 Zend\Di\DefinitionList,
9 Zend\EventManager\StaticEventManager,
10 Zend\Module\Manager as ModuleManager,
18 public function __construct(Config $config, ModuleManager $modules)
20 $this->config = $config;
21 $this->modules = $modules;
24 public function bootstrap(Application $app)
26 $this->setupLocator($app);
27 $this->setupRoutes($app);
28 $this->setupEvents($app);
31 protected function setupLocator(Application $app)
34 $di->instanceManager()->addTypePreference('Zend\Di\Locator', $di);
36 $config = new DiConfiguration($this->config->di);
37 $config->configure($di);
39 $app->setLocator($di);
42 protected function setupRoutes(Application $app)
44 $router = $app->getLocator()->get('Zend\Mvc\Router\SimpleRouteStack');
45 foreach ($this->config->routes as $name => $config) {
46 $class = $config->type;
47 $options = $config->options;
48 $route = new $class($options);
49 $router->addRoute($name, $route);
51 $app->setRouter($router);
54 protected function setupEvents(Application $app)
56 $view = $this->getView($app);
57 $locator = $app->getLocator();
58 $events = $app->events();
59 $staticEvents = StaticEventManager::getInstance();
61 foreach ($this->modules->getLoadedModules() as $name => $module) {
62 if (method_exists($module, 'registerApplicationListeners')) {
63 $module->registerApplicationListeners($events, $locator, $this->config);
66 if (method_exists($module, 'registerStaticListeners')) {
67 $module->registerStaticListeners($staticEvents, $locator, $this->config);
72 protected function getView($app)
74 $di = $app->getLocator();
75 $view = $di->get('view');
76 $url = $view->plugin('url');
77 $url->setRouter($app->getRouter());
79 $view->plugin('headTitle')->setSeparator(' - ')
80 ->setAutoEscape(false)
81 ->append('Application');