1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Load, configure, run application |
7
|
|
|
*/ |
8
|
|
|
function boot() |
9
|
|
|
{ |
10
|
|
|
if (session_status() == PHP_SESSION_NONE) { |
11
|
|
|
ini_set('session.auto_start', 'Off'); |
12
|
|
|
} else { |
13
|
|
|
ini_set('session.lazy_write', 'On'); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
chdir(realpath(__DIR__ . '/../../')); |
17
|
|
|
require_once '../lib/autoload.php'; |
18
|
|
|
|
19
|
|
|
// bootstrap initial environment |
20
|
|
|
$f3 = \Base::instance(); |
21
|
|
|
|
22
|
|
|
if (empty($f3->get('CLI'))) { |
23
|
|
|
die('This can only be executed in CLI mode.'); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
\FFMVC\App::start(); |
27
|
|
|
$f3->set('UNLOAD', function () { |
28
|
|
|
\FFMVC\App::finish(); |
29
|
|
|
}); |
30
|
|
|
|
31
|
|
|
// load dependency injection container |
32
|
|
|
$dice = new \Dice\Dice; |
33
|
|
|
|
34
|
|
|
// logging for application |
35
|
|
|
$logfile = $f3->get('log.file'); |
36
|
|
|
$dice->addRule('Log', ['shared' => true, 'constructParams' => [$logfile]]); |
37
|
|
|
|
38
|
|
|
// database connection used by app |
39
|
|
|
$dbConfig = $f3->get('db'); |
40
|
|
|
$dice->addRule('DB\\SQL', ['shared' => true, 'constructParams' => [ |
41
|
|
|
\FFMVC\Helpers\DB::createDbDsn($dbConfig), |
42
|
|
|
$dbConfig['user'], |
43
|
|
|
$dbConfig['pass'], |
44
|
|
|
[\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION], |
45
|
|
|
]]); |
46
|
|
|
|
47
|
|
|
// auto-create database if options set |
48
|
|
|
\App\Setup::database($dice); |
49
|
|
|
|
50
|
|
|
// run the main application |
51
|
|
|
require_once 'lib/App/App.php'; |
52
|
|
|
$app = $dice->create('App\\App'); |
53
|
|
|
$app->Main(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// run the application |
57
|
|
|
boot(); |
58
|
|
|
|
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.