-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
86 lines (80 loc) · 2.27 KB
/
index.php
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace webfiori;
use Exception;
use webfiori\framework\App;
use webfiori\framework\router\Router;
use webfiori\framework\session\SessionsManager;
use webfiori\http\Request;
use webfiori\http\Response;
/**
* The name of the directory at which the developer will have his own application
* code.
*
* @since 2.3.0
*/
define('APP_DIR', 'app');
/**
* The entry point of all requests.
*
* @author Ibrahim
*/
class Index {
private static $instance;
private function __construct() {
$DS = DIRECTORY_SEPARATOR;
/**
* The root directory that is used to load all other required system files.
*/
if (!defined('ROOT_PATH')) {
$publicFolder = $DS.'public';
if (substr(__DIR__, strlen(__DIR__) - strlen($publicFolder)) == $publicFolder) {
//HTTP run
define('ROOT_PATH', substr(__DIR__,0, strlen(__DIR__) - strlen($DS.'public')));
} else {
//CLI run
define('ROOT_PATH', __DIR__);
}
}
$this->loadAppClass();
/**
* This where magic will start.
*
* Planting application seed into the ground and make your work bloom.
*/
App::start();
if (App::getRunner()->isCLI() === true) {
App::getRunner()->start();
} else {
//route user request.
SessionsManager::start('wf-session');
Router::route(Request::getRequestedURI());
Response::send();
}
}
/**
* Creates a single instance of the class.
*/
public static function create() {
if (self::$instance === null) {
self::$instance = new Index();
}
}
/**
* Try to load the class 'App'.
*
* @throws Exception
*/
private function loadAppClass() {
$DS = DIRECTORY_SEPARATOR;
$frameworkPath = ROOT_PATH.$DS.'webfiori'.$DS.'framework';
$corePath = $frameworkPath;
$rootClass = $DS.'App.php';
if (file_exists($corePath.$rootClass)) {
define('WF_CORE_PATH', $corePath);
require_once $corePath.$rootClass;
} else {
throw new Exception('Unable to locate the class "App".');
}
}
}
Index::create();