4 use Zend\Config\Config,
7 Zend\Di\DependencyInjector,
8 Zend\EventManager\StaticEventManager,
9 Zend\Module\Manager as ModuleManager,
17 public function __construct(Config $config, ModuleManager $modules)
19 $this->config = $config;
20 $this->modules = $modules;
23 public function bootstrap(Application $app)
25 $this->setupLocator($app);
26 $this->setupRoutes($app);
27 $this->setupEvents($app);
30 protected function setupLocator(Application $app)
32 $definition = new Definition\AggregateDefinition;
33 $definition->addDefinition(new Definition\RuntimeDefinition);
35 $di = new DependencyInjector;
36 $di->setDefinition($definition);
38 $config = new Configuration($this->config->di);
39 $config->configure($di);
41 $app->setLocator($di);
44 protected function setupRoutes(Application $app)
46 $router = $app->getLocator()->get('Zend\Mvc\Router\SimpleRouteStack');
47 foreach ($this->config->routes as $name => $config) {
48 $class = $config->type;
49 $options = $config->options;
50 $route = new $class($options);
51 $router->addRoute($name, $route);
53 $app->setRouter($router);
56 protected function setupEvents(Application $app)
58 $view = $this->getView($app);
59 $locator = $app->getLocator();
60 $events = $app->events();
61 $staticEvents = StaticEventManager::getInstance();
63 foreach ($this->modules->getLoadedModules() as $name => $module) {
64 if (method_exists($module, 'registerApplicationListeners')) {
65 $module->registerApplicationListeners($events, $locator, $this->config);
68 if (method_exists($module, 'registerStaticListeners')) {
69 $module->registerStaticListeners($staticEvents, $locator, $this->config);
74 protected function getView($app)
76 $di = $app->getLocator();
77 $view = $di->get('view');
78 $url = $view->plugin('url');
79 $url->setRouter($app->getRouter());
81 $view->plugin('headTitle')->setSeparator(' - ')
82 ->setAutoEscape(false)
83 ->append('Application');