forked from Qbix/Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q.php
146 lines (134 loc) · 4.42 KB
/
Q.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
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Qbix Platform
* by Gregory Magarshak
*
* This file should be included by any PHP script that wants
* to use the Qbix Platform. (For example, a front controller.)
*
* @package Q
*/
// Enforce PHP version to be > 5.0
if (version_compare(PHP_VERSION, '5.0.0', '<')) {
die("Q requires PHP version 5.0 or higher. It works even better with PHP 7 and above.");
}
// Was this loaded? In that case, do nothing.
if (defined('Q_VERSION')) {
return;
}
define('Q_VERSION', '1.1');
//
// Constants
//
if (!defined('DS'))
define('DS', DIRECTORY_SEPARATOR);
if (!defined('PS'))
define('PS', PATH_SEPARATOR);
if (!defined('Q_DIR'))
define('Q_DIR', dirname(__FILE__));
if (!defined('Q_CONFIG_DIR'))
define('Q_CONFIG_DIR', Q_DIR.DS.'config');
if (!defined('Q_CLASSES_DIR'))
define('Q_CLASSES_DIR', Q_DIR.DS.'classes');
if (!defined('Q_FILES_DIR'))
define('Q_FILES_DIR', Q_DIR.DS.'files');
if (!defined('Q_HANDLERS_DIR'))
define('Q_HANDLERS_DIR', Q_DIR.DS.'handlers');
if (!defined('Q_PLUGINS_DIR'))
define('Q_PLUGINS_DIR', Q_DIR.DS.'plugins');
if (!defined('Q_SCRIPTS_DIR'))
define('Q_SCRIPTS_DIR', Q_DIR.DS.'scripts');
if (!defined('Q_TEXT_DIR'))
define('Q_TEXT_DIR', Q_DIR.DS.'text');
if (!defined('Q_VIEWS_DIR'))
define('Q_VIEWS_DIR', Q_DIR.DS.'views');
if (!defined('Q_TESTS_DIR'))
define('Q_TESTS_DIR', Q_DIR.DS.'tests');
if (defined('APP_DIR')) {
if (!defined('APP_CONFIG_DIR'))
define('APP_CONFIG_DIR', APP_DIR.DS.'config');
if (!defined('APP_LOCAL_DIR'))
define('APP_LOCAL_DIR', APP_DIR.DS.'local');
if (!defined('APP_CLASSES_DIR'))
define('APP_CLASSES_DIR', APP_DIR.DS.'classes');
if (!defined('APP_FILES_DIR'))
define('APP_FILES_DIR', APP_DIR.DS.'files');
if (!defined('APP_HANDLERS_DIR'))
define('APP_HANDLERS_DIR', APP_DIR.DS.'handlers');
if (!defined('APP_PLUGINS_DIR'))
define('APP_PLUGINS_DIR', APP_DIR.DS.'plugins');
if (!defined('APP_SCRIPTS_DIR'))
define('APP_SCRIPTS_DIR', APP_DIR.DS.'scripts');
if (!defined('APP_TESTS_DIR'))
define('APP_TESTS_DIR', APP_DIR.DS.'tests');
if (!defined('APP_VIEWS_DIR'))
define('APP_VIEWS_DIR', APP_DIR.DS.'views');
if (!defined('APP_TEXT_DIR'))
define('APP_TEXT_DIR', APP_DIR.DS.'text');
if (!defined('APP_WEB_DIR'))
define('APP_WEB_DIR', APP_DIR.DS.'web');
if (!defined('APP_TESTS_DIR'))
define('APP_TESTS_DIR', APP_DIR.DS.'tests');
if (!defined('APP_ROOT_DIR')) {
define(
'APP_ROOT_DIR',
strlen(APP_DIR) < strlen(APP_WEB_DIR) ? APP_DIR : APP_WEB_DIR
);
}
}
// For backwards compatibility
if (!defined('JSON_UNESCAPED_SLASHES')) define('JSON_UNESCAPED_SLASHES', 0);
if (!defined('JSON_PRETTY_PRINT')) define('JSON_PRETTY_PRINT', 0);
//
// Include core classes
//
require_once(Q_CLASSES_DIR.DS.'Q.php');
Q::milliseconds();
require_once(Q_CLASSES_DIR.DS.'Q'.DS.'Cache.php');
require_once(Q_CLASSES_DIR.DS.'Q'.DS.'Bootstrap.php');
require_once(Q_CLASSES_DIR.DS.'Q'.DS.'Tree.php');
require_once(Q_CLASSES_DIR.DS.'Q'.DS.'Config.php');
Q_Bootstrap::registerShutdownFunction();
Q_Bootstrap::setIncludePath();
Q_Bootstrap::defineFunctions();
require_once(Q_CLASSES_DIR.DS.'Q'.DS.'Text.php');
require_once(Q_CLASSES_DIR.DS.'Q'.DS.'Exception.php');
require_once(Q_CLASSES_DIR.DS.'Q'.DS.'Exception'.DS.'PHPError.php');
require_once(Q_CLASSES_DIR.DS.'Q'.DS.'Exception'.DS.'JsonDecode.php');
require_once(Q_CLASSES_DIR.DS.'Q'.DS.'Exception'.DS.'InvalidInput.php');
require_once(Q_CLASSES_DIR.DS.'Q'.DS.'Uri.php');
require_once(Q_CLASSES_DIR.DS.'Db.php');
require_once(Q_CLASSES_DIR.DS.'Db'.DS.'Expression.php');
require_once(Q_CLASSES_DIR.DS.'Db'.DS.'Query.php');
require_once(Q_CLASSES_DIR.DS.'PasswordCompat'.DS.'password.php');
require_once(Q_CLASSES_DIR.DS.'RandomCompat'.DS.'random.php');
//
// Set things up
//
Q_Bootstrap::setDefaultTimezone();
Q_Bootstrap::configure();
Q_Bootstrap::registerAutoload();
Q_Bootstrap::registerExceptionHandler();
Q_Bootstrap::registerErrorHandler();
// Q_Bootstrap::validateEarly();
Q_Bootstrap::revertSlashes();
Q_Bootstrap::alertAboutLocalConfiguration();
Q_Bootstrap::setDefaultTimezone();
Q_Bootstrap::setResponseBuffered();
Q_Bootstrap::setUrls();
Q_Response::setIgnoreUserAbort();
if (defined('APP_WEB_DIR')) {
Q_Bootstrap::addAlias();
Q_Request::baseUrl();
}
$clearCache = Q_Request::special('clearCache');
if (isset($clearCache)) {
if ($clearCache == Q_Config::get('Q', 'cache', 'secret', '')) {
Q_Cache::clear(true);
}
}
Q::$bootstrapped = true;
if (empty($Q_installing)) {
// Give the project a chance to load aggregated files, etc.
Q::event('Q/init');
}