Permalink
Browse files

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
  • Loading branch information...
weierophinney committed Oct 14, 2011
1 parent 25f44b5 commit a7f22ba984ddda1d8d01ee027fa76b73b1074407
Showing with 21 additions and 15 deletions.
  1. +1 −0 configs/application.config.php
  2. +14 −7 modules/Application/src/Application/Bootstrap.php
  3. +6 −8 public/index.php
@@ -1,5 +1,6 @@
<?php
return new Zend\Config\Config(array(
+ 'bootstrap_class' => 'Application\Bootstrap',
'module_paths' => array(
realpath(__DIR__ . '/../modules'),
),
@@ -1,22 +1,29 @@
<?php
namespace Application;
-use Zend\Config\Config,
- Zend\Di\Configuration as DiConfiguration,
+use Zend\Di\Configuration as DiConfiguration,
Zend\Di\Di,
Zend\EventManager\StaticEventManager,
Zend\Module\Manager as ModuleManager,
- Zend\Mvc\Application;
+ Zend\Mvc\Application,
+ Zend\Mvc\Router\Http\TreeRouteStack as Router;
class Bootstrap
{
+ /**
+ * @var \Zend\Config\Config
+ */
protected $config;
+
+ /**
+ * @var ModuleManager
+ */
protected $modules;
- public function __construct(Config $config, ModuleManager $modules)
+ public function __construct(ModuleManager $modules)
{
- $this->config = $config;
$this->modules = $modules;
+ $this->config = $modules->getMergedConfig();
}
public function bootstrap(Application $app)
@@ -39,8 +46,8 @@ protected function setupLocator(Application $app)
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);
}
View
@@ -14,19 +14,17 @@
$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();

0 comments on commit a7f22ba

Please sign in to comment.