Permalink
Browse files

bootstrap.php returns DI container and index.php runs the application

  • Loading branch information...
dg committed Nov 2, 2012
1 parent 6656c1c commit a62ff788250ed00bc4f50417870b775ef0e35237
Showing with 7 additions and 11 deletions.
  1. +1 −8 app/bootstrap.php
  2. +6 −3 www/index.php
View
@@ -1,14 +1,9 @@
<?php
-/**
- * My Application bootstrap file.
- */
-
// Load Nette Framework or autoloader generated by Composer
require __DIR__ . '/../libs/autoload.php';
-// Configure application
$configurator = new Nette\Config\Configurator;
// Enable Nette Debugger for error visualisation & logging
@@ -27,6 +22,4 @@
$configurator->addConfig(__DIR__ . '/config/config.local.neon');
$container = $configurator->createContainer();
-
-// Configure and run the application!
-$container->application->run();
+return $container;
View
@@ -1,7 +1,10 @@
<?php
-// uncomment this line if you must temporarily take down your site for maintenance
+// Uncomment this line if you must temporarily take down your site for maintenance.
// require '.maintenance.php';
-// load bootstrap file
-require __DIR__ . '/../app/bootstrap.php';
+// Let bootstrap create Dependency Injection container.
+$container = require __DIR__ . '/../app/bootstrap.php';
+
+// Run application.
+$container->application->run();

5 comments on commit a62ff78

👍
Great to see this! I wanted to propose this change for some time but have never find a moment to write down my reasoning.

Owner

dg replied Nov 28, 2012

And what is your reason? ;)

Bootstrapping (preparing) the whole application but not executing it's default entry point. That's useful for

  • testing - load the app and test only part
  • phpsh - load the app and then play with CLI
  • CLI scripts, because I don't want to run presenters from cron

The approach is similar to Misko's main() method - which is index.php in our case

Owner

dg replied Nov 28, 2012

Thanks. I have the same reasons.

This is just great! 👍

Please sign in to comment.