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 * Returns a lite debug string of passed on variables
50 *
51 * @return string
52 */
53 function debugLite() {
54 if (!Kint::enabled()) {
55 return '';
56 } else {
57 ob_start();
58 $argv = func_get_args();
59 echo '<pre>';
60 foreach ($argv as $k => $v) {
61 $k && print("\n\n");
62 echo s($v);
63 }
64 echo '</pre>' . "\n";
65
66 return ob_get_clean();
67 }
68 }
69
70 /**
71 * Returns a very precise timestamp
72 *
73 * @author Art <a.molcanovas@gmail.com>
74 *
75 * @param float $microtime Optionally, supply your own microtime
76 *
77 * @return string Y-m-d H:i:s:{milliseconds}
78 */
79 function timestampPrecise($microtime = null) {
80 if (!$microtime) {
81 $microtime = microtime(true);
82 }
83 $t = explode('.', $microtime);
84
85 return date('Y-m-d H:i:s', $t[0]) . ':' . round($t[1] / 10);
86 }
87
88 if (!function_exists('getallheaders')) {
89
90 /**
91 * Implement getallheaders() for non-apache servers
92 *
93 * @author Art <a.molcanovas@gmail.com>
94 * @return array
95 */
96 function getallheaders() {
97 $headers = [];
98 foreach ($_SERVER as $name => $value) {
99 if (substr($name, 0, 5) == 'HTTP_') {
100 $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] =
101 $value;
102 }
103 }
104
105 return $headers;
106 }
107 }
108
109 /**
110 * Triggers a PHP-level error with the level E_USER_ERROR
111 *
112 * @author Art <a.molcanovas@gmail.com>
113 *
114 * @param string $msg Error message
115 *
116 * @link http://php.net/manual/en/function.trigger-error.php
117 * @return bool
118 */
119 function phpError($msg) {
120 return trigger_error($msg, E_USER_ERROR);
121 }
122
123 /**
124 * Triggers a PHP-level error with the level E_USER_WARNING
125 *
126 * @author Art <a.molcanovas@gmail.com>
127 *
128 * @param string $msg Error message
129 *
130 * @link http://php.net/manual/en/function.trigger-error.php
131 * @return bool
132 */
133 function phpWarning($msg) {
134 return trigger_error($msg, E_USER_WARNING);
135 }
136
137 /**
138 * Triggers a PHP-level error with the level E_USER_NOTICE
139 *
140 * @author Art <a.molcanovas@gmail.com>
141 *
142 * @param string $msg Error message
143 *
144 * @link http://php.net/manual/en/function.trigger-error.php
145 * @return bool
146 */
147 function phpNotice($msg) {
148 return trigger_error($msg, E_USER_NOTICE);
149 }
150
151 /**
152 * Triggers a PHP-level error with the level E_USER_DEPRECATED
153 *
154 * @author Art <a.molcanovas@gmail.com>
155 *
156 * @param string $msg Error message
157 *
158 * @link http://php.net/manual/en/function.trigger-error.php
159 * @return bool
160 */
161 function phpDeprecated($msg) {
162 return trigger_error($msg, E_USER_DEPRECATED);
163 }
164
165 require_once DIR_SYS . 'core' . DIRECTORY_SEPARATOR . 'alo.php';
166
167 if (!defined('PHPUNIT_RUNNING')) {
168 Alo::$router = new Alo\Controller\Router();
169 Alo::includeonceifexists(DIR_APP . 'core' . DIRECTORY_SEPARATOR . 'autoload.php');
170 Alo::$router->init();
171 } else {
172 Alo::includeonceifexists(DIR_APP . 'core' . DIRECTORY_SEPARATOR . 'autoload.php');
173 }
174 }
175