|
1 | 1 | <?php |
2 | | -namespace WebFiori; |
3 | | - |
4 | | -use Exception; |
5 | | -use WebFiori\Framework\App; |
6 | | -use WebFiori\Framework\Router\Router; |
7 | | -use WebFiori\Framework\Session\SessionsManager; |
8 | | -use WebFiori\http\Request; |
9 | | -use WebFiori\http\Response; |
10 | | -/** |
11 | | - * The name of the directory at which the developer will have his own application |
12 | | - * code. |
13 | | - * |
14 | | - * @since 2.3.0 |
15 | | - */ |
16 | | -define('APP_DIR', 'App'); |
17 | 2 |
|
| 3 | +namespace WebFiori; |
18 | 4 |
|
19 | | -/** |
20 | | - * The entry point of all requests. |
21 | | - * |
22 | | - * @author Ibrahim |
23 | | - */ |
24 | | -class Index { |
25 | | - private static $instance; |
26 | | - private function __construct() { |
27 | | - $DS = DIRECTORY_SEPARATOR; |
28 | | - /** |
29 | | - * The root directory that is used to load all other required system files. |
30 | | - */ |
31 | | - if (!defined('ROOT_PATH')) { |
32 | | - $publicFolder = $DS.'public'; |
| 5 | +$DS = DIRECTORY_SEPARATOR; |
33 | 6 |
|
34 | | - if (substr(__DIR__, strlen(__DIR__) - strlen($publicFolder)) == $publicFolder) { |
35 | | - //HTTP run |
36 | | - define('ROOT_PATH', substr(__DIR__,0, strlen(__DIR__) - strlen($DS.'public'))); |
37 | | - } else { |
38 | | - //CLI run |
39 | | - define('ROOT_PATH', __DIR__); |
40 | | - } |
41 | | - } |
42 | | - $this->loadAppClass(); |
43 | | - /** |
44 | | - * This where magic will start. |
45 | | - * |
46 | | - * Planting application seed into the ground and make your work bloom. |
47 | | - */ |
48 | | - App::start(); |
| 7 | +require __DIR__.$DS.'..'.$DS.'vendor'.$DS.'autoload.php'; |
49 | 8 |
|
50 | | - if (App::getRunner()->isCLI() === true) { |
51 | | - App::getRunner()->start(); |
52 | | - } else { |
53 | | - //route user request. |
54 | | - SessionsManager::start('wf-session'); |
55 | | - Router::route(Request::getRequestedURI()); |
56 | | - Response::send(); |
57 | | - } |
58 | | - } |
59 | | - /** |
60 | | - * Creates a single instance of the class. |
61 | | - */ |
62 | | - public static function create() { |
63 | | - if (self::$instance === null) { |
64 | | - self::$instance = new Index(); |
65 | | - } |
66 | | - } |
67 | | - /** |
68 | | - * Try to load the class 'App'. |
69 | | - * |
70 | | - * @throws Exception |
71 | | - */ |
72 | | - private function loadAppClass() { |
73 | | - $DS = DIRECTORY_SEPARATOR; |
74 | | - $frameworkPath = ROOT_PATH.$DS.'WebFiori'.$DS.'framework'; |
75 | | - $corePath = $frameworkPath; |
76 | | - $rootClass = $DS.'App.php'; |
| 9 | +use WebFiori\Framework\App; |
77 | 10 |
|
78 | | - if (file_exists($corePath.$rootClass)) { |
79 | | - define('WF_CORE_PATH', $corePath); |
80 | | - require_once $corePath.$rootClass; |
81 | | - } else { |
82 | | - throw new Exception('Unable to locate the class "App".'); |
83 | | - } |
84 | | - } |
85 | | -} |
86 | | -Index::create(); |
| 11 | +App::initiate('App', 'public', __DIR__); |
| 12 | +App::start(); |
| 13 | +App::handle(); |
0 commit comments