-
Notifications
You must be signed in to change notification settings - Fork 1
/
cron.php
133 lines (111 loc) · 3.72 KB
/
cron.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
ini_set('memory_limit','9240M');
ini_set('auto_detect_line_endings', true);
ob_start();
define("DEBUG", True);
define("APP_PATH", dirname(__FILE__));
define("CDN", "/assets/");
define("GCDN", "https://static.vnative.co/");
try {
// 1. load the Core class that includes an autoloader
require_once(APP_PATH. "/framework/core.php");
Framework\Core::initialize();
// 2. Additional Path's which
Framework\Core::autoLoadPaths([
"/application/libraries",
"/application/Command",
"/application"
]);
// plugins
// $path = APP_PATH . "/application/plugins";
// $iterator = new DirectoryIterator($path);
// foreach ($iterator as $item) {
// if (!$item->isDot() && $item->isDir()) {
// include($path . "/" . $item->getFilename() . "/initialize.php");
// }
// }
// 3. load and initialize the Configuration class
$configuration = new Framework\Configuration(array(
"type" => "ini"
));
Framework\Registry::set("configuration", $configuration->initialize());
// Load the logger
$logger = new Framework\Logger();
Framework\Registry::setLogger($logger->initialize());
unset($logger);
// 4. load and initialize the Database class – does not connect
$database = new Framework\Database();
Framework\Registry::set("database", $database->initialize());
// 5. load and initialize the Cache class – does not connect
$cache = new Framework\Cache();
Framework\Registry::set("cache", $cache->initialize());
$redisCache = new Framework\Cache(['type' => 'redis']);
Framework\Registry::set("redis", $redisCache->initialize());
// 6. load and initialize the Session class
$session = new Framework\Session();
Framework\Registry::set("session", $session->initialize());
// 7. load the Router class and provide the url + extension
$c = (isset($argv[1])) ? $argv[1] : "cron";
$a = (isset($argv[2])) ? $argv[2] : "index";
$router = new Framework\Router(array(
"url" => "$c/$a",
"extension" => !empty($_GET["extension"]) ? $_GET["extension"] : "html"
));
Framework\Registry::set("router", $router);
// include custom routes
include("public/routes.php");
// 8. dispatch the current request
$router->dispatch();
// 9. unset global variables
unset($configuration);
unset($database);
unset($cache);
unset($session);
unset($router);
} catch (Exception $e) {
// list exceptions
$exceptions = array(
"401" => array(
"Framework\Router\Exception\Inactive"
),
"404" => array(
"Framework\Router\Exception\Action",
"Framework\Router\Exception\Controller"
),
"500" => array(
"Framework\Cache\Exception",
"Framework\Configuration\Exception",
"Framework\Controller\Exception",
"Framework\Core\Exception",
"Framework\Database\Exception",
"Framework\Model\Exception",
"Framework\Request\Exception",
"Framework\Router\Exception",
"Framework\Session\Exception",
"Framework\Template\Exception",
"Framework\View\Exception",
"MongoDB\Driver\Exception\Exception"
)
);
$exception = get_class($e);
// attempt to find the approapriate template, and render
foreach ($exceptions as $template => $classes) {
foreach ($classes as $class) {
if ($class == $exception || is_subclass_of($exception, $class)) {
header("Content-type: text/html");
include(APP_PATH . "/application/views/layouts/errors/{$template}.php");
exit;
}
}
}
// log or email any error
// render fallback template
header("Content-type: text/html");
include(APP_PATH . "/application/views/layouts/errors/500.php");
exit;
} catch (Error $e) {
header("Content-type: text/html");
include(APP_PATH . "/application/views/layouts/errors/500.php");
exit;
}
?>