1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
|-------------------------------------------------------------------------- |
5
|
|
|
| Autoload |
6
|
|
|
|-------------------------------------------------------------------------- |
7
|
|
|
| |
8
|
|
|
| After running "composer install", we can use the autoloader file created. |
9
|
|
|
| |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
require '../vendor/autoload.php'; |
13
|
|
|
|
14
|
|
|
/* |
15
|
|
|
|-------------------------------------------------------------------------- |
16
|
|
|
| Define Application Configuration Constants |
17
|
|
|
|-------------------------------------------------------------------------- |
18
|
|
|
| |
19
|
|
|
| PUBLIC_ROOT: the root URL for the application (see below). |
20
|
|
|
| BASE_DIR: path to the directory that has all of your "app", "public", "vendor", ... directories. |
21
|
|
|
| IMAGES: path to upload images, don't use it for displaying images, use Config::get('root') . "/img/" instead. |
22
|
|
|
| APP: path to app directory. |
23
|
|
|
| |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
// Config::set('base', str_replace("\\", "/", dirname(__DIR__))); |
|
|
|
|
27
|
|
|
// Config::set('images', str_replace("\\", "/", __DIR__) . "/img/"); |
28
|
|
|
// Config::set('app', Config::get('base') . "/app/"); |
29
|
|
|
|
30
|
|
|
define('BASE_DIR', str_replace("\\", "/", dirname(__DIR__))); |
31
|
|
|
define('IMAGES', str_replace("\\", "/", __DIR__) . "/img/"); |
32
|
|
|
define('APP', BASE_DIR . "/app/"); |
33
|
|
|
|
34
|
|
|
/* |
35
|
|
|
|-------------------------------------------------------------------------- |
36
|
|
|
| Register Error & Exception handlers |
37
|
|
|
|-------------------------------------------------------------------------- |
38
|
|
|
| |
39
|
|
|
| Here we will register the methods that will fire whenever there is an error |
40
|
|
|
| or an exception has been thrown. |
41
|
|
|
| |
42
|
|
|
*/ |
43
|
|
|
|
44
|
|
|
Handler::register(); |
45
|
|
|
|
46
|
|
|
/* |
47
|
|
|
|-------------------------------------------------------------------------- |
48
|
|
|
| Start Session |
49
|
|
|
|-------------------------------------------------------------------------- |
50
|
|
|
| |
51
|
|
|
*/ |
52
|
|
|
|
53
|
|
|
Session::init(); |
54
|
|
|
|
55
|
|
|
/* |
56
|
|
|
|-------------------------------------------------------------------------- |
57
|
|
|
| Create The Application |
58
|
|
|
|-------------------------------------------------------------------------- |
59
|
|
|
| |
60
|
|
|
| Here we will create the application instance which will take care of routing |
61
|
|
|
| the incoming request to the corresponding controller and action method if valid |
62
|
|
|
| |
63
|
|
|
*/ |
64
|
|
|
|
65
|
|
|
$app = new App(); |
66
|
|
|
|
67
|
|
|
// Config::set('root', $app->request->root()); |
|
|
|
|
68
|
|
|
define('PUBLIC_ROOT', $app->request->root()); |
69
|
|
|
|
70
|
|
|
/* |
71
|
|
|
|-------------------------------------------------------------------------- |
72
|
|
|
| Run The Application |
73
|
|
|
|-------------------------------------------------------------------------- |
74
|
|
|
| |
75
|
|
|
| Once we have the application instance, we can handle the incoming request |
76
|
|
|
| and send a response back to the client's browser. |
77
|
|
|
| |
78
|
|
|
*/ |
79
|
|
|
|
80
|
|
|
$app->run(); |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.