src/CarteBlanche/App/Kernel.php
public function init($config_files = null, array $user_config = null, $mode_arg = null)
    {
        $this->getContainer()->set('kernel', $this);
        $this->getContainer()->set('config', new \CarteBlanche\App\Config);
        $config = $this->getContainer()->get('config');

        if (!defined('_ROOTFILE')) {
            die('You need to define the "_ROOTFILE" constant to run CarteBlanche!');
        }
        if (!defined('_ROOTPATH')) {
            die('You need to define the "_ROOTPATH" constant to run CarteBlanche!');
        }

        spl_autoload_register(array('\CarteBlanche\App\Loader', 'autoload'));
        register_shutdown_function(array($this, 'shutdown'));
        set_include_path( get_include_path().PATH_SEPARATOR._ROOTPATH );

        // base required paths
        $this
            ->initConstantPath('_ROOTFILE', 'root_file')
            ->initConstantPath('_ROOTPATH', 'root_path', true)
            ->addPath('carte_blanche_core', realpath(__DIR__.'/../'))
            ;
        if (!$this->isCli()) {
            if (!defined('_ROOTHTTP')) {
                self::__getHttpRoot();
            }
            $this->initConstantPath('_ROOTHTTP', 'root_http');
        }

        // user config file
        $_defconf = false;
        if (!is_array($config_files)) $config_files = array($config_files);
        $config_files = array_filter($config_files);
        if (!empty($config_files)) {
            foreach($config_files as $cfgf) {
                if (substr_count($cfgf, self::CARTE_BLANCHE_CONFIG_FILE)) {
                    $_defconf = true;
                }
            }
        }
        if (true!==$_defconf) {
            $this->__loadDefaultConfig();
        }
        if (!empty($config_files)) {
            foreach($config_files as $cfgf) {
                if ( ! file_exists($cfgf)) {
                    $cfgf = $this->getPath('root_path').$cfgf;
                }
                $config->load($cfgf);
            }
        }

        // server config
        if (!empty($_SERVER)) {
            foreach ($_SERVER as $_name=>$_conf) {
                if (substr($_name, 0, strlen(self::CARTE_BLANCHE_SERVER_SETTING_PREFIX))===self::CARTE_BLANCHE_SERVER_SETTING_PREFIX) {
                    $config->set(array(
                            str_replace(self::CARTE_BLANCHE_SERVER_SETTING_PREFIX, '', $_name) => $_conf
                        ), true, 'server');
                }
            }
        }

        // user config
        if (!empty($user_config)) {
            $config->set($user_config, true, 'user');
        }

        // error reporting
        if (!empty($mode_arg)) {
            $this->__setMode($mode_arg);
        }

        // manifest file
        $_f = $this->getPath('root_path').'/composer.json';
        if (file_exists($_f = $this->getPath('root_path').self::CARTE_BLANCHE_MANIFEST)) {
            $manifest = @json_decode(@file_get_contents($_f), true);
            $config->set($manifest, false, 'manifest');
        }

        // application directories
        $app_dirs = $config->get('carte_blanche.app_dirs', null, true);
        foreach ($app_dirs as $name=>$dir) {
            $this->addPath($name, $dir);
        }

        // application required directories
        $app_dirs = $config->get('carte_blanche.required_dirs', Config::NOT_FOUND_GRACEFULLY, array());
        foreach ($app_dirs as $i=>$name) {
            try {
                $this->addPath($name, $this->getPath($name), true);
            } catch (ErrorException $e) {
                $this->addBootError(
                    sprintf('An error occurred while booting: "%s" [03]', $e->getMessage())
                );
            } catch (Exception $e) {
                $this->addBootError(
                    sprintf('An error occurred while booting: "%s" [04]', $e->getMessage())
                );
            }
        }

        // application required directories
        $app_dirs = $config->get('carte_blanche.writable_dirs', Config::NOT_FOUND_GRACEFULLY, array());
        foreach ($app_dirs as $i=>$name) {
            try {
                $this->addPath($name, $this->getPath($name), true, true);
            } catch (ErrorException $e) {
                $this->addBootError(
                    sprintf('An error occurred while booting: "%s" [05]', $e->getMessage())
                );
            } catch (Exception $e) {
                $this->addBootError(
                    sprintf('An error occurred while booting: "%s" [06]', $e->getMessage())
                );
            }
        }

        $base_objects = $config->get('carte_blanche.base_objects');
        foreach(array('loader', 'locator', 'response') as $type) {
            $class_name = isset($base_objects[$type]) ?
                $base_objects[$type] : '\CarteBlanche\App\\'.ucfirst($type);
            if (class_exists($class_name)) {
                $this->getContainer()->set($type, new $class_name);
            } else {
                $this->addBootError(
                    sprintf('Required base object type "%s" not found! (searching class "%s")',
                        $type,
                        $class_name
                    )
                );
            }
        }
    }
public function init($config_files = null, array $user_config = null, $mode_arg = null)
    {
        $this->getContainer()->set('kernel', $this);
        $this->getContainer()->set('config', new \CarteBlanche\App\Config);
        $config = $this->getContainer()->get('config');

        if (!defined('_ROOTFILE')) {
            die('You need to define the "_ROOTFILE" constant to run CarteBlanche!');
        }
        if (!defined('_ROOTPATH')) {
            die('You need to define the "_ROOTPATH" constant to run CarteBlanche!');
        }

        spl_autoload_register(array('\CarteBlanche\App\Loader', 'autoload'));
        register_shutdown_function(array($this, 'shutdown'));
        set_include_path( get_include_path().PATH_SEPARATOR._ROOTPATH );

        // base required paths
        $this
            ->initConstantPath('_ROOTFILE', 'root_file')
            ->initConstantPath('_ROOTPATH', 'root_path', true)
            ->addPath('carte_blanche_core', realpath(__DIR__.'/../'))
            ;
        if (!$this->isCli()) {
            if (!defined('_ROOTHTTP')) {
                self::__getHttpRoot();
            }
            $this->initConstantPath('_ROOTHTTP', 'root_http');
        }

        // user config file
        $_defconf = false;
        if (!is_array($config_files)) $config_files = array($config_files);
        $config_files = array_filter($config_files);
        if (!empty($config_files)) {
            foreach($config_files as $cfgf) {
                if (substr_count($cfgf, self::CARTE_BLANCHE_CONFIG_FILE)) {
                    $_defconf = true;
                }
            }
        }
        if (true!==$_defconf) {
            $this->__loadDefaultConfig();
        }
        if (!empty($config_files)) {
            foreach($config_files as $cfgf) {
                if ( ! file_exists($cfgf)) {
                    $cfgf = $this->getPath('root_path').$cfgf;
                }
                $config->load($cfgf);
            }
        }

        // server config
        if (!empty($_SERVER)) {
            foreach ($_SERVER as $_name=>$_conf) {
                if (substr($_name, 0, strlen(self::CARTE_BLANCHE_SERVER_SETTING_PREFIX))===self::CARTE_BLANCHE_SERVER_SETTING_PREFIX) {
                    $config->set(array(
                            str_replace(self::CARTE_BLANCHE_SERVER_SETTING_PREFIX, '', $_name) => $_conf
                        ), true, 'server');
                }
            }
        }

        // user config
        if (!empty($user_config)) {
            $config->set($user_config, true, 'user');
        }

        // error reporting
        if (!empty($mode_arg)) {
            $this->__setMode($mode_arg);
        }

        // manifest file
        $_f = $this->getPath('root_path').'/composer.json';
        if (file_exists($_f = $this->getPath('root_path').self::CARTE_BLANCHE_MANIFEST)) {
            $manifest = @json_decode(@file_get_contents($_f), true);
            $config->set($manifest, false, 'manifest');
        }

        // application directories
        $app_dirs = $config->get('carte_blanche.app_dirs', null, true);
        foreach ($app_dirs as $name=>$dir) {
            $this->addPath($name, $dir);
        }

        // application required directories
        $app_dirs = $config->get('carte_blanche.required_dirs', Config::NOT_FOUND_GRACEFULLY, array());
        foreach ($app_dirs as $i=>$name) {
            try {
                $this->addPath($name, $this->getPath($name), true);
            } catch (ErrorException $e) {
                $this->addBootError(
                    sprintf('An error occurred while booting: "%s" [03]', $e->getMessage())
                );
            } catch (Exception $e) {
                $this->addBootError(
                    sprintf('An error occurred while booting: "%s" [04]', $e->getMessage())
                );
            }
        }

        // application required directories
        $app_dirs = $config->get('carte_blanche.writable_dirs', Config::NOT_FOUND_GRACEFULLY, array());
        foreach ($app_dirs as $i=>$name) {
            try {
                $this->addPath($name, $this->getPath($name), true, true);
            } catch (ErrorException $e) {
                $this->addBootError(
                    sprintf('An error occurred while booting: "%s" [05]', $e->getMessage())
                );
            } catch (Exception $e) {
                $this->addBootError(
                    sprintf('An error occurred while booting: "%s" [06]', $e->getMessage())
                );
            }
        }

        $base_objects = $config->get('carte_blanche.base_objects');
        foreach(array('loader', 'locator', 'response') as $type) {
            $class_name = isset($base_objects[$type]) ?
                $base_objects[$type] : '\CarteBlanche\App\\'.ucfirst($type);
            if (class_exists($class_name)) {
                $this->getContainer()->set($type, new $class_name);
            } else {
                $this->addBootError(
                    sprintf('Required base object type "%s" not found! (searching class "%s")',
                        $type,
                        $class_name
                    )
                );
            }
        }
    }
Initializer : defines required paths and parse configuration

@param   null/string/array    $config_files
@param   null/array           $user_config
@param   null/string          $mode_arg       The kernel mode, can be 'prod' or 'dev' (for now)
@return  void