3.2 Project configuration & bootstrap
The bootstrap file index.php, which must be inside the public directory “httpdocs”, is very short and simple, and all it has to do is to define some fundamental constants and start the framework Kernel. Here it is the typical bootstrap code:
<?php
define('TRACE', true);
define('metadigit\core\BOOTSTRAP', __FILE__);
define('metadigit\core\PUBLIC_DIR', __DIR__.'/');
define('metadigit\core\BASE_DIR', '/var/www/myproject.com/private/');
define('metadigit\core\DATA_DIR', '/var/www/myproject.com/data/');
define('metadigit\core\ASSETS_DIR', '/var/www/myproject.com/data/assets/');
define('metadigit\core\BACKUP_DIR', '/var/www/myproject.com/data/backup/');
define('metadigit\core\CACHE_DIR', '/var/www/myproject.com/data/cache/');
define('metadigit\core\LOG_DIR', '/var/www/myproject.com/data/log/');
define('metadigit\core\TMP_DIR', '/var/www/myproject.com/tmp/');
define('metadigit\core\UPLOAD_DIR', '/var/www/myproject.com/data/upload/');
define('metadigit\core\ENVIRONMENT', (gethostname()=='server')?'PROD':'DEVEL');
require __DIR__.'/../private/lib/metadigit-core-2.0.6.phar';
metadigit\core\Kernel::init();
metadigit\core\Kernel::dispatch();
After having defined the framework required constants (which names are auto explaining), we defined the ENVIRONMENT in which we are running (production, develop, testing) and we include the framework .phar. Now just call Kernel::init() and Kernel::dispatch().
The Kernel during the init() method parse its configuration, which is store inside metadigit-core.ini.
Here your are an example, with sensible defaults.
[settings]
traceLevel = 7
charset = UTF-8
locale = it_IT.UTF-8
timeZone = Europe/Rome
[namespaces]
myproject = myproject
PHPTAL = "phar://lib/phptal-1.2.2.phar"
Swift = "phar://lib/swift-mailer-4.3.0.phar/classes"
[apps-http]
;name = “port|url|namespace”
CP = "80|/ControlPanel/|myproject.apps.cp"
Web = "80|/|myproject.apps.web"
[apps-cli]
batch = myproject.batch
[constants]
SWIFT_DIR = "phar:///var/www/myproject.com/private/lib/swift-mailer-4.3.0.phar/"
UPLOAD_DIR = "/var/www/myproject.com/data/upload/"
[databases]
system = "sqlite:/var/www/myproject.com/data/system.sqlite|null|null"
master = "mysql:host=localhost;dbname=myDB|myUser|myPwd"
[logs]
kernel = "LOG_INFO|kernel|metadigit\core\log\writer\FileWriter|kernel.log|null"
system = "LOG_ERR||metadigit\core\log\writer\SqliteWriter|system|log"
The configuration file is divided in 7 sections.
a)
…. TODO …..
<?xml version="1.0" encoding="UTF-8"?>
<context namespace="system">
<objects>
<object id="system.Example" class="StdClass">
</object>
</objects>
<events>
<event name="kernel:shutdown">
<listeners>
<listener>metadigit\webconsole\Kernel::onShutdown</listener>
</listeners>
</event>
</events>
</context>
Updated about 1 month ago