-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
30 lines (25 loc) · 1006 Bytes
/
index.php
File metadata and controls
30 lines (25 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
if (!defined('PROJECT_ROOT_DIR')) {
define('PROJECT_ROOT_DIR', __DIR__);
// Ensure basic class auto-loading
require_once __DIR__ . DIRECTORY_SEPARATOR . 'Utils/Autoader.php';
spl_autoload_register(__NAMESPACE__ . '\Utils\Autoader::load');
}
// Running app
try {
$config = include PROJECT_ROOT_DIR . DIRECTORY_SEPARATOR . 'config.php';
// Decision whether CLI or Web environment
$environment = PHP_SAPI;
if ($environment === 'cli') {
$router = new Utils\CliRouter();
$factoryClass = 'Factory\\' . ucfirst($router->getController()) . 'Cli';
} else {
$router = new Utils\WebRouter();
$factoryClass = 'Factory\\' . ucfirst($router->getController()) . 'Web';
}
/* @var $controller \Controller\IController */
$controller = $factoryClass::instance($environment, $config)->create();
$controller->execute();
} catch (Exception $exception) {
echo $exception->getMessage() . ($environment === 'cli' ? PHP_EOL : '');
}