Skip to content

Bootstrapping

Micro-Kernel

Bootstrapping is performed using a micro-kernel. It's just a few lines to set environment parameters, initialize the service container and run the app:

<?php

namespace DIMicroKernel;

class Kernel
{
    protected $environment;
    protected $debug;
    protected $appPath;

    public function __construct(
        $environment = 'app', $appPath = '', $debug = false)
    {
        $this->environment = $environment;
        $this->debug = $debug;
        $this->appPath = $appPath;

        $this->boot();
    }

    ...

    public function getApplication()
    {
        return $this->getContainer()->get('app');
    }

    public function run()
    {
        return $this->getApplication()->run();
    }
}

Customization

The kernel base class can be extended to customize it for a specific purpose (e.g. command line application):

<?php
namespace App\Kernel;

use DIMicroKernel\Kernel;

class ConsoleApp extends Kernel
{
    public function __construct($appPath, $debug = false)
    {
        parent::__construct('console', $appPath, $debug);
    }

    public function setUp()
    {
        chdir($this->getAppPath());
        set_time_limit(0);
        ini_set('memory_limit', '-1');
    }
}

Run an App

Creating a kernel instance and calling run() is enough to start any application (see app/console and web/app.php):

#!/usr/bin/env php
<?php

require_once __DIR__ . '/../vendor/autoload.php';

use App\Kernel\ConsoleApp;
$app = new ConsoleApp (__DIR__);
$app->run();