4 use Zend\Config\Config,
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)
33 $definition = new Definition\RuntimeDefinition;
34 $definition->getIntrospectionStrategy()->setUseAnnotations(false);
35 $di = new Di(new DefinitionList($definition), null, new Configuration($this->config->di));
36 $di->instanceManager()->addTypePreference('Zend\Di\Locator', $di);
37 $app->setLocator($di);
40 protected function setupRoutes(Application $app)
42 $router = $app->getLocator()->get('Zend\Mvc\Router\SimpleRouteStack');
43 foreach ($this->config->routes as $name => $config) {
44 $class = $config->type;
45 $options = $config->options;
46 $route = new $class($options);
47 $router->addRoute($name, $route);
49 $app->setRouter($router);
52 protected function setupEvents(Application $app)
54 $view = $this->getView($app);
55 $locator = $app->getLocator();
56 $events = $app->events();
57 $staticEvents = StaticEventManager::getInstance();
59 foreach ($this->modules->getLoadedModules() as $name => $module) {
60 if (method_exists($module, 'registerApplicationListeners')) {
61 $module->registerApplicationListeners($events, $locator, $this->config);
64 if (method_exists($module, 'registerStaticListeners')) {
65 $module->registerStaticListeners($staticEvents, $locator, $this->config);
70 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');