1 <?php
2
3 if (!defined('GEN_START')) {
4 http_response_code(404);
5 } else {
6
7 ob_start();
8 require_once DIR_SYS . 'core' . DIRECTORY_SEPARATOR . 'log.php';
9 include_once DIR_SYS . 'external' . DIRECTORY_SEPARATOR . 'kint' . DIRECTORY_SEPARATOR . 'Kint.class.php';
10 require_once DIR_SYS . 'core' . DIRECTORY_SEPARATOR . 'handler.php';
11
12 spl_autoload_register('\Alo\Handler::autoloader');
13 if (!defined('PHPUNIT_RUNNING')) {
14 set_error_handler('\Alo\Handler::error', ini_get('error_reporting'));
15 set_exception_handler('\Alo\Handler::ecxeption');
16 }
17
18 /**
19 * A shortcut to isset($var) ? $var : null
20 *
21 * @author Art <a.molcanovas@gmail.com>
22 *
23 * @param mixed $var The variable to "return"
24 *
25 * @return mixed
26 */
27 function get(&$var) {
28 return isset($var) ? $var : null;
29 }
30
31 /**
32 * Returns a debug string of the passed on variables
33 *
34 * @return string
35 */
36 function debug() {
37 if (!Kint::enabled()) {
38 return null;
39 } else {
40 ob_start();
41 $args = func_get_args();
42 call_user_func_array(['Kint', 'dump'], $args);
43
44 return ob_get_clean();
45 }
46 }
47
48 /**
49 * Check if the server is running Windows
50 *
51 * @author Art <a.molcanovas@gmail.com>
52 * @return bool
53 */
54 function serverIsWindows() {
55 return substr(strtoupper(php_uname('s')), 0, 3) === 'WIN';
56 }
57
58 /**
59 * Returns a lite debug string of passed on variables
60 *
61 * @return string
62 */
63 function debugLite() {
64 if (!Kint::enabled()) {
65 return '';
66 } else {
67 ob_start();
68 $argv = func_get_args();
69 echo '<pre>';
70 foreach ($argv as $k => $v) {
71 $k && print("\n\n");
72 echo s($v);
73 }
74 echo '</pre>' . "\n";
75
76 return ob_get_clean();
77 }
78 }
79
80 /**
81 * Returns a very precise timestamp
82 *
83 * @author Art <a.molcanovas@gmail.com>
84 *
85 * @param float $microtime Optionally, supply your own microtime
86 *
87 * @return string Y-m-d H:i:s:{milliseconds}
88 */
89 function timestampPrecise($microtime = null) {
90 if (!$microtime) {
91 $microtime = microtime(true);
92 }
93 $t = explode('.', $microtime);
94
95 return date('Y-m-d H:i:s', $t[0]) . ':' . round($t[1] / 10);
96 }
97
98 if (!function_exists('getallheaders')) {
99
100 /**
101 * Implement getallheaders() for non-apache servers
102 *
103 * @author Art <a.molcanovas@gmail.com>
104 * @return array
105 */
106 function getallheaders() {
107 $headers = [];
108 foreach ($_SERVER as $name => $value) {
109 if (substr($name, 0, 5) == 'HTTP_') {
110 $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] =
111 $value;
112 }
113 }
114
115 return $headers;
116 }
117 }
118
119 /**
120 * Escapes sensitive characters for HTML5 output
121 *
122 * @author Art <a.molcanovas@gmail.com>
123 *
124 * @param string $str The input string
125 *
126 * @return string
127 */
128 function escapeHTML($str) {
129 return htmlspecialchars($str, ENT_QUOTES | ENT_HTML5);
130 }
131
132 /**
133 * Performs include() only if a file exists
134 *
135 * @param string $path Path to the file
136 *
137 * @return bool true if the file exists, false if not.
138 */
139 function includeifexists($path) {
140 if (file_exists($path)) {
141 include $path;
142
143 return true;
144 }
145
146 return false;
147 }
148
149 /**
150 * Performs include_once() only if a file exists
151 *
152 * @param string $path Path to the file
153 *
154 * @return bool true if the file exists, false if not.
155 */
156 function includeonceifexists($path) {
157 if (file_exists($path)) {
158 include_once $path;
159
160 return true;
161 }
162
163 return false;
164 }
165
166 /**
167 * Triggers a PHP-level error with the level E_USER_ERROR
168 *
169 * @author Art <a.molcanovas@gmail.com>
170 *
171 * @param string $msg Error message
172 *
173 * @link http://php.net/manual/en/function.trigger-error.php
174 * @return bool
175 */
176 function phpError($msg) {
177 return trigger_error($msg, E_USER_ERROR);
178 }
179
180 /**
181 * Triggers a PHP-level error with the level E_USER_WARNING
182 *
183 * @author Art <a.molcanovas@gmail.com>
184 *
185 * @param string $msg Error message
186 *
187 * @link http://php.net/manual/en/function.trigger-error.php
188 * @return bool
189 */
190 function phpWarning($msg) {
191 return trigger_error($msg, E_USER_WARNING);
192 }
193
194 /**
195 * Triggers a PHP-level error with the level E_USER_NOTICE
196 *
197 * @author Art <a.molcanovas@gmail.com>
198 *
199 * @param string $msg Error message
200 *
201 * @link http://php.net/manual/en/function.trigger-error.php
202 * @return bool
203 */
204 function phpNotice($msg) {
205 return trigger_error($msg, E_USER_NOTICE);
206 }
207
208 /**
209 * Triggers a PHP-level error with the level E_USER_DEPRECATED
210 *
211 * @author Art <a.molcanovas@gmail.com>
212 *
213 * @param string $msg Error message
214 *
215 * @link http://php.net/manual/en/function.trigger-error.php
216 * @return bool
217 */
218 function phpDeprecated($msg) {
219 return trigger_error($msg, E_USER_DEPRECATED);
220 }
221
222 require_once DIR_SYS . 'core' . DIRECTORY_SEPARATOR . 'alo.php';
223
224 includeonceifexists(DIR_APP . 'core' . DIRECTORY_SEPARATOR . 'autoload.php');
225
226 if (!defined('PHPUNIT_RUNNING')) {
227 Alo::$router = new Alo\Controller\Router();
228 Alo::$router->init();
229 }
230 }
231