-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
index.php
executable file
·259 lines (228 loc) · 6.14 KB
/
index.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
declare(strict_types=1);
/**
* Flextype (https://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
namespace Flextype;
use function define;
use function getcwd;
use function is_file;
use function sprintf;
use function str_replace;
use function version_compare;
use const DIRECTORY_SEPARATOR;
use const PHP_VERSION;
class Debug
{
/**
* Time
*
* @var array
*/
protected static $time = [];
/**
* Memory
*
* @var array
*/
protected static $memory = [];
/**
* Save current time for current point
*
* Debug::elapsedTimeSetPoint('point_name');
*
* @param string $point_name Point name
*/
public static function elapsedTimeSetPoint(string $point_name) : void
{
Debug::$time[$point_name] = microtime(true);
}
/**
* Get elapsed time for current point
*
* echo Debug::elapsedTime('point_name');
*
* @param string $point_name Point name
* @return string
*/
public static function elapsedTime(string $point_name) : string
{
if (isset(Debug::$time[$point_name])) return sprintf("%01.4f", microtime(true) - Debug::$time[$point_name]);
}
/**
* Save current memory for current point
*
* Debug::memoryUsageSetPoint('point_name');
*
* @param string $point_name Point name
*/
public static function memoryUsageSetPoint(string $point_name) : void
{
Debug::$memory[$point_name] = memory_get_usage();
}
/**
* Get memory usage for current point
*
* echo Debug::memoryUsage('point_name');
*
* @param string $point_name Point name
* @return string
*/
public static function memoryUsage(string $point_name) : string
{
if (isset(Debug::$memory[$point_name])) {
$unit = array('B', 'KB', 'MB', 'GB', 'TiB', 'PiB');
$size = memory_get_usage() - Debug::$memory[$point_name];
$memory_usage = @round($size/pow(1024, ($i=floor(log($size, 1024)))), 2).' '.$unit[($i < 0 ? 0 : $i)];
return $memory_usage;
}
}
/**
* Print the variable $data and exit if exit = true
*
* Debug::dump($data);
*
* @param mixed $data Data
* @param bool $exit Exit
*/
public static function dump($data, bool $exit = false) : void
{
echo "<pre>dump \n---------------------- \n\n" . print_r($data, true) . "\n----------------------</pre>";
if ($exit) exit;
}
/**
* Prints a list of all currently declared classes.
*
* Debug::classes();
*
* @access public
* @return string
*/
public static function classes()
{
return Debug::dump(get_declared_classes());
}
/**
* Prints a list of all currently declared interfaces.
*
* Debug::interfaces();
*
* @access public
* @return string
*/
public static function interfaces()
{
return Debug::dump(get_declared_interfaces());
}
/**
* Prints a list of all currently included (or required) files.
*
* Debug::includes();
*
* @access public
* @return string
*/
public static function includes()
{
return Debug::dump(get_included_files());
}
/**
* Prints a list of all currently declared functions.
*
* Debug::functions();
*
* @access public
* @return string
*/
public static function functions()
{
return Debug::dump(get_defined_functions());
}
/**
* Prints a list of all currently declared constants.
*
* Debug::constants();
*
* @access public
* @return string
*/
public static function constants()
{
return Debug::dump(get_defined_constants());
}
/**
* Prints a list of all currently loaded PHP extensions.
*
* Debug::extensions();
*
* @access public
* @return string
*/
public static function extensions()
{
return Debug::dump(get_loaded_extensions());
}
/**
* Prints a list of the configuration settings read from php.ini
*
* Debug::phpini();
*
* @access public
* @return string
*/
public static function phpini()
{
if (!is_readable(get_cfg_var('cfg_file_path'))) {
return false;
}
return Debug::dump(parse_ini_file(get_cfg_var('cfg_file_path'), true));
}
}
Debug::elapsedTimeSetPoint('flextype');
Debug::memoryUsageSetPoint('flextype');
/**
* Define the application minimum supported PHP version.
*/
define('FLEXTYPE_MINIMUM_PHP', '7.4.0');
/**
* Define the PATH to the root directory (without trailing slash).
*/
define('ROOT_DIR', str_replace(DIRECTORY_SEPARATOR, '/', getcwd()));
/**
* Define the PATH (without trailing slash).
*/
define('PATH', [
'project' => ROOT_DIR . '/project',
'tmp' => ROOT_DIR . '/var/tmp',
]);
/**
* Check PHP Version
*/
version_compare($ver = PHP_VERSION, $req = FLEXTYPE_MINIMUM_PHP, '<') and exit(sprintf('You are running PHP %s, but Flextype needs at least <strong>PHP %s</strong> to run.', $ver, $req));
/**
* Ensure vendor libraries exist
*/
! is_file($flextypeAutoload = __DIR__ . '/vendor/autoload.php') and exit('Please run: <i>composer install</i> for flextype');
/**
* Register The Auto Loader
*
* Composer provides a convenient, automatically generated class loader for
* our application. We just need to utilize it! We'll simply require it
* into the script here so that we don't have to worry about manual
* loading any of our classes later on. It feels nice to relax.
* Register The Auto Loader
*/
$flextypeLoader = require_once $flextypeAutoload;
/**
* Bootstraps the Flextype
*
* This bootstraps the Flextype and gets it ready for use, then it
* will load up this application so that we can run it and send
* the responses back to the browser and delight our users.
*/
include __DIR__ . '/src/flextype/flextype.php';
echo "<div style='position:absolute; bottom: 10px; left: 10px;'>";
echo "Time: " . Debug::elapsedTime('flextype');
echo " Memory: " . Debug::memoryUsage('flextype');
echo "</div>";