Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.

Commit

Permalink
bootstrap.php returns DI container and index.php runs the application
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 7, 2012
1 parent 6656c1c commit a62ff78
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
9 changes: 1 addition & 8 deletions app/bootstrap.php
@@ -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
Expand All @@ -27,6 +22,4 @@
$configurator->addConfig(__DIR__ . '/config/config.local.neon');
$container = $configurator->createContainer();


// Configure and run the application!
$container->application->run();
return $container;
9 changes: 6 additions & 3 deletions www/index.php
@@ -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

@juzna
Copy link

@juzna juzna commented on a62ff78 Nov 28, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@dg
Copy link
Member Author

@dg dg commented on a62ff78 Nov 28, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what is your reason? ;)

@juzna
Copy link

@juzna juzna commented on a62ff78 Nov 28, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@dg
Copy link
Member Author

@dg dg commented on a62ff78 Nov 28, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I have the same reasons.

@rostenkowski
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just great! 👍

Please sign in to comment.