From a7f22ba984ddda1d8d01ee027fa76b73b1074407 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 14 Oct 2011 12:44:05 -0500 Subject: [PATCH] Updates and cleanup - Routing: - Use TreeRouteStack instead of SimpleRouteStack - Do not pull router from locator; simply instantiate - Config object can now be passed directly to addRoutes - Bootstrap: - Accept ModuleManager as sole constructor argument, and pull merged configuration from it - index.php: - Do not use object notation for accessing config values; use array notation. Allows flexibility in how application configuration is returned --- configs/application.config.php | 1 + modules/Application/src/Application/Bootstrap.php | 21 ++++++++++++++------- public/index.php | 14 ++++++-------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/configs/application.config.php b/configs/application.config.php index daf929f..e280ee8 100644 --- a/configs/application.config.php +++ b/configs/application.config.php @@ -1,5 +1,6 @@ 'Application\Bootstrap', 'module_paths' => array( realpath(__DIR__ . '/../modules'), ), diff --git a/modules/Application/src/Application/Bootstrap.php b/modules/Application/src/Application/Bootstrap.php index e46649f..ae73d9e 100644 --- a/modules/Application/src/Application/Bootstrap.php +++ b/modules/Application/src/Application/Bootstrap.php @@ -1,22 +1,29 @@ config = $config; $this->modules = $modules; + $this->config = $modules->getMergedConfig(); } public function bootstrap(Application $app) @@ -39,8 +46,8 @@ class Bootstrap protected function setupRoutes(Application $app) { - $router = $app->getLocator()->get('Zend\Mvc\Router\SimpleRouteStack'); - $router->addRoutes($this->config->routes->toArray()); + $router = new Router(); + $router->addRoutes($this->config->routes); $app->setRouter($router); } diff --git a/public/index.php b/public/index.php index f56f4a6..cd83a90 100644 --- a/public/index.php +++ b/public/index.php @@ -14,19 +14,17 @@ Zend\Loader\AutoloaderFactory::factory(array('Zend\Loader\StandardAutoloader' => $appConfig = include __DIR__ . '/../configs/application.config.php'; -$moduleLoader = new Zend\Loader\ModuleAutoloader($appConfig->module_paths); +$moduleLoader = new Zend\Loader\ModuleAutoloader($appConfig['module_paths']); $moduleLoader->register(); $moduleManager = new Zend\Module\Manager( - $appConfig->modules, - new Zend\Module\ManagerOptions($appConfig->module_manager_options) + $appConfig['modules'], + new Zend\Module\ManagerOptions($appConfig['module_manager_options']) ); -// Get the merged config object -$config = $moduleManager->getMergedConfig(); - // Create application, bootstrap, and run -$bootstrap = new $config->bootstrap_class($config, $moduleManager); -$application = new Zend\Mvc\Application; +$bootstrapClass = $appConfig['bootstrap_class']; +$bootstrap = new $bootstrapClass($moduleManager); +$application = new Zend\Mvc\Application; $bootstrap->bootstrap($application); $application->run()->send(); -- 1.7.10.4