Hi Guys,

Would you be interested in Bootstrap component I developed and happy to submit into incubator? The purpose of it to simplify bootstrapping of a Phalcon application. I built it when initialization file of my app became very messy and hit more than 2k lines of code.

The idea is that you break your initialization routine into separate files aka modules and use Bootstrap class to construct initalization process. Multiple applications can share modules. Bootstrap supports environments, passing parameters between modules and has built-in exceptions handler capable of catching PHP errors including fatal once.


Bootstrap::init( new Environment((isset($_SERVER['APP_ENV']) ? $_SERVER['APP_ENV'] : Environmant::DEVELOPMENT)) /* optional */, new Container(array(

     * Initial variables

    'di' => new Phalcon\DI\FactoryDefault(),
    'config' => new \Phalcon\Config(array(/* ... */))
)) /* optional */ )

    ->addStage(include 'bootstrap/module.database.php' /*, $priority = 100 (optional) */)

    ->addStage(include 'bootstrap/module.routes.php' /*, $priority = 200 (optional) */)

    ->addStage(function(Container $container, Environment $environment) {
        $di = $container->di; // retrieve from user-space

        $app = new \Phalcon\Mvc\Application($di);
        echo $app->handle()->getContent();
    } /*, $priority = 400 (optional) */ )

    ->addStageIf(Environmant::DEVELOPMENT, function(Container $container, Environment $environment) {

         * This stage is called only if current environment is Environmant::DEVELOPMENT

        $debug = new \Phalcon\Debug();
    } /*, $priority = 300 (optional) */ )

    ->execute(); // execute bootstrap chain

bootstrap/module.database.php and bootstrap/module.routes.php both should return anonymous functions, for example

return function(Container $container, Environment $environment) {
    $router = new \Phalcon\Mvc\Router();
    $router->add("/admin/:controller/a/:action/:params", array(
        "controller" => 1,
        "action"     => 2,
        "params"     => 3,

    $container->di->setShared('router', $router);

Container and Environment are passed into each module. Container is used to pass variables between modules. Environment simply indicates current environment the application is running under.

Environment accepts a string into the constructor or an anonymous function in case if environment detection is complicated, e.g, you set environment based on a hostname or similar.