@@ -42,428 +42,428 @@ |
||
42 | 42 | */ |
43 | 43 | class GDebug implements DebugContract |
44 | 44 | { |
45 | - /** |
|
46 | - * Allow Handlers to force the script to quit. |
|
47 | - * |
|
48 | - * @var bool $allowQuit |
|
49 | - */ |
|
50 | - protected $allowQuit = true; |
|
45 | + /** |
|
46 | + * Allow Handlers to force the script to quit. |
|
47 | + * |
|
48 | + * @var bool $allowQuit |
|
49 | + */ |
|
50 | + protected $allowQuit = true; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Benchmark instance. |
|
54 | - * |
|
55 | - * @var string $benchmark |
|
56 | - */ |
|
57 | - protected $benchmark; |
|
58 | - |
|
59 | - /** |
|
60 | - * The handler stack. |
|
61 | - * |
|
62 | - * @var array $handlerStack |
|
63 | - */ |
|
64 | - protected $handlerStack = []; |
|
65 | - |
|
66 | - /** |
|
67 | - * The send Http code by default: 500 Internal Server Error. |
|
68 | - * |
|
69 | - * @var bool $sendHttpCode |
|
70 | - */ |
|
71 | - protected $sendHttpCode = 500; |
|
72 | - |
|
73 | - /** |
|
74 | - * The send output. |
|
75 | - * |
|
76 | - * @var bool $sendOutput |
|
77 | - */ |
|
78 | - protected $sendOutput = true; |
|
79 | - |
|
80 | - /** |
|
81 | - * The functions of system what control errors and exceptions. |
|
82 | - * |
|
83 | - * @var string $system |
|
84 | - */ |
|
85 | - protected $system; |
|
86 | - |
|
87 | - /** |
|
88 | - * In certain scenarios, like in shutdown handler, we can not throw exceptions. |
|
89 | - * |
|
90 | - * @var bool $throwExceptions |
|
91 | - */ |
|
92 | - protected $throwExceptions = true; |
|
93 | - |
|
94 | - /** |
|
95 | - * Constructor. The Debug class instance. |
|
96 | - * |
|
97 | - * @param \Syscodes\Debug\Util\System|null $system |
|
98 | - * |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - public function __construct(System $system = null) |
|
102 | - { |
|
103 | - $this->system = $system ?: new System; |
|
104 | - $this->benchmark = new Benchmark; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Catches any uncaught errors and exceptions, including most Fatal errors. Will log the |
|
109 | - * error, display it if display_errors is on, and fire an event that allows custom actions |
|
110 | - * to be taken at this point. |
|
111 | - * |
|
112 | - * @param \Throwable $exception |
|
113 | - * |
|
114 | - * @return string |
|
115 | - */ |
|
116 | - public function handleException(Throwable $exception) |
|
117 | - { |
|
118 | - // The start benchmark |
|
119 | - $this->benchmark->start('total_execution', LENEVOR_START); |
|
120 | - |
|
121 | - $supervisor = $this->getSupervisor($exception); |
|
122 | - |
|
123 | - // Start buffer |
|
124 | - $this->system->startOutputBuferring(); |
|
125 | - |
|
126 | - $handlerResponse = null; |
|
127 | - $handlerContentType = null; |
|
52 | + /** |
|
53 | + * Benchmark instance. |
|
54 | + * |
|
55 | + * @var string $benchmark |
|
56 | + */ |
|
57 | + protected $benchmark; |
|
58 | + |
|
59 | + /** |
|
60 | + * The handler stack. |
|
61 | + * |
|
62 | + * @var array $handlerStack |
|
63 | + */ |
|
64 | + protected $handlerStack = []; |
|
65 | + |
|
66 | + /** |
|
67 | + * The send Http code by default: 500 Internal Server Error. |
|
68 | + * |
|
69 | + * @var bool $sendHttpCode |
|
70 | + */ |
|
71 | + protected $sendHttpCode = 500; |
|
72 | + |
|
73 | + /** |
|
74 | + * The send output. |
|
75 | + * |
|
76 | + * @var bool $sendOutput |
|
77 | + */ |
|
78 | + protected $sendOutput = true; |
|
79 | + |
|
80 | + /** |
|
81 | + * The functions of system what control errors and exceptions. |
|
82 | + * |
|
83 | + * @var string $system |
|
84 | + */ |
|
85 | + protected $system; |
|
86 | + |
|
87 | + /** |
|
88 | + * In certain scenarios, like in shutdown handler, we can not throw exceptions. |
|
89 | + * |
|
90 | + * @var bool $throwExceptions |
|
91 | + */ |
|
92 | + protected $throwExceptions = true; |
|
93 | + |
|
94 | + /** |
|
95 | + * Constructor. The Debug class instance. |
|
96 | + * |
|
97 | + * @param \Syscodes\Debug\Util\System|null $system |
|
98 | + * |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + public function __construct(System $system = null) |
|
102 | + { |
|
103 | + $this->system = $system ?: new System; |
|
104 | + $this->benchmark = new Benchmark; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Catches any uncaught errors and exceptions, including most Fatal errors. Will log the |
|
109 | + * error, display it if display_errors is on, and fire an event that allows custom actions |
|
110 | + * to be taken at this point. |
|
111 | + * |
|
112 | + * @param \Throwable $exception |
|
113 | + * |
|
114 | + * @return string |
|
115 | + */ |
|
116 | + public function handleException(Throwable $exception) |
|
117 | + { |
|
118 | + // The start benchmark |
|
119 | + $this->benchmark->start('total_execution', LENEVOR_START); |
|
120 | + |
|
121 | + $supervisor = $this->getSupervisor($exception); |
|
122 | + |
|
123 | + // Start buffer |
|
124 | + $this->system->startOutputBuferring(); |
|
125 | + |
|
126 | + $handlerResponse = null; |
|
127 | + $handlerContentType = null; |
|
128 | 128 | |
129 | - try |
|
130 | - { |
|
131 | - foreach ($this->handlerStack as $handler) |
|
132 | - { |
|
133 | - $handler->setDebug($this); |
|
134 | - $handler->setException($exception); |
|
135 | - $handler->setSupervisor($supervisor); |
|
129 | + try |
|
130 | + { |
|
131 | + foreach ($this->handlerStack as $handler) |
|
132 | + { |
|
133 | + $handler->setDebug($this); |
|
134 | + $handler->setException($exception); |
|
135 | + $handler->setSupervisor($supervisor); |
|
136 | 136 | |
137 | - $handlerResponse = $handler->handle(); |
|
137 | + $handlerResponse = $handler->handle(); |
|
138 | 138 | |
139 | - // Collect the content type for possible sending in the headers |
|
140 | - $handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null; |
|
139 | + // Collect the content type for possible sending in the headers |
|
140 | + $handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null; |
|
141 | 141 | |
142 | - if (in_array($handlerResponse, [MainHandler::LAST_HANDLER, MainHandler::QUIT])) |
|
143 | - { |
|
144 | - break; |
|
145 | - } |
|
146 | - } |
|
142 | + if (in_array($handlerResponse, [MainHandler::LAST_HANDLER, MainHandler::QUIT])) |
|
143 | + { |
|
144 | + break; |
|
145 | + } |
|
146 | + } |
|
147 | 147 | |
148 | - $Quit = $handlerResponse == MainHandler::QUIT && $this->allowQuit(); |
|
149 | - } |
|
150 | - finally |
|
151 | - { |
|
152 | - // Returns the contents of the output buffer |
|
153 | - $output = $this->system->CleanOutputBuffer(); |
|
154 | - } |
|
155 | - |
|
156 | - // Returns the contents of the output buffer for loading time of page |
|
157 | - $totalTime = $this->benchmark->getElapsedTime('total_execution'); |
|
158 | - $output = str_replace('{elapsed_time}', $totalTime, $output); |
|
159 | - |
|
160 | - if ($this->writeToOutput()) |
|
161 | - { |
|
162 | - if ($Quit) |
|
163 | - { |
|
164 | - while ($this->system->getOutputBufferLevel() > 0) |
|
165 | - { |
|
166 | - // Cleanes the output buffer |
|
167 | - $this->system->endOutputBuffering(); |
|
168 | - } |
|
169 | - |
|
170 | - if (Misc::sendHeaders() && $handlerContentType) |
|
171 | - { |
|
172 | - header("Content-Type: {$handlerContentType}"); |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - $this->writeToOutputBuffer($output); |
|
177 | - } |
|
178 | - |
|
179 | - if ($Quit) |
|
180 | - { |
|
181 | - $this->system->flushOutputBuffer(); |
|
182 | - $this->system->stopException(1); |
|
183 | - } |
|
184 | - |
|
185 | - return $output; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Allow Handlers to force the script to quit. |
|
190 | - * |
|
191 | - * @param bool|int $exit |
|
192 | - * |
|
193 | - * @return bool |
|
194 | - */ |
|
195 | - public function allowQuit($exit = null) |
|
196 | - { |
|
197 | - if (func_num_args() == 0) |
|
198 | - { |
|
199 | - return $this->allowQuit; |
|
200 | - } |
|
201 | - |
|
202 | - return $this->allowQuit = (bool) $exit; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Lenevor Exception push output directly to the client it the data |
|
207 | - * if they are true, but if it is false, the output will be returned |
|
208 | - * by exception. |
|
209 | - * |
|
210 | - * @param bool|int $send |
|
211 | - * |
|
212 | - * @return bool |
|
213 | - */ |
|
214 | - public function writeToOutput($send = null) |
|
215 | - { |
|
216 | - if (func_num_args() == 0) |
|
217 | - { |
|
218 | - return $this->sendOutput; |
|
219 | - } |
|
148 | + $Quit = $handlerResponse == MainHandler::QUIT && $this->allowQuit(); |
|
149 | + } |
|
150 | + finally |
|
151 | + { |
|
152 | + // Returns the contents of the output buffer |
|
153 | + $output = $this->system->CleanOutputBuffer(); |
|
154 | + } |
|
155 | + |
|
156 | + // Returns the contents of the output buffer for loading time of page |
|
157 | + $totalTime = $this->benchmark->getElapsedTime('total_execution'); |
|
158 | + $output = str_replace('{elapsed_time}', $totalTime, $output); |
|
159 | + |
|
160 | + if ($this->writeToOutput()) |
|
161 | + { |
|
162 | + if ($Quit) |
|
163 | + { |
|
164 | + while ($this->system->getOutputBufferLevel() > 0) |
|
165 | + { |
|
166 | + // Cleanes the output buffer |
|
167 | + $this->system->endOutputBuffering(); |
|
168 | + } |
|
169 | + |
|
170 | + if (Misc::sendHeaders() && $handlerContentType) |
|
171 | + { |
|
172 | + header("Content-Type: {$handlerContentType}"); |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + $this->writeToOutputBuffer($output); |
|
177 | + } |
|
178 | + |
|
179 | + if ($Quit) |
|
180 | + { |
|
181 | + $this->system->flushOutputBuffer(); |
|
182 | + $this->system->stopException(1); |
|
183 | + } |
|
184 | + |
|
185 | + return $output; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Allow Handlers to force the script to quit. |
|
190 | + * |
|
191 | + * @param bool|int $exit |
|
192 | + * |
|
193 | + * @return bool |
|
194 | + */ |
|
195 | + public function allowQuit($exit = null) |
|
196 | + { |
|
197 | + if (func_num_args() == 0) |
|
198 | + { |
|
199 | + return $this->allowQuit; |
|
200 | + } |
|
201 | + |
|
202 | + return $this->allowQuit = (bool) $exit; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Lenevor Exception push output directly to the client it the data |
|
207 | + * if they are true, but if it is false, the output will be returned |
|
208 | + * by exception. |
|
209 | + * |
|
210 | + * @param bool|int $send |
|
211 | + * |
|
212 | + * @return bool |
|
213 | + */ |
|
214 | + public function writeToOutput($send = null) |
|
215 | + { |
|
216 | + if (func_num_args() == 0) |
|
217 | + { |
|
218 | + return $this->sendOutput; |
|
219 | + } |
|
220 | 220 | |
221 | - return $this->sendOutput = (bool) $send; |
|
222 | - } |
|
221 | + return $this->sendOutput = (bool) $send; |
|
222 | + } |
|
223 | 223 | |
224 | - /** |
|
225 | - * Generate output to the browser. |
|
226 | - * |
|
227 | - * @param string $output |
|
228 | - * |
|
229 | - * @return $this |
|
230 | - */ |
|
231 | - protected function writeToOutputBuffer($output) |
|
232 | - { |
|
233 | - if ($this->sendHttpCode() && Misc::sendHeaders()) |
|
234 | - { |
|
235 | - $this->system->setHttpResponseCode($this->sendHttpCode()); |
|
236 | - } |
|
224 | + /** |
|
225 | + * Generate output to the browser. |
|
226 | + * |
|
227 | + * @param string $output |
|
228 | + * |
|
229 | + * @return $this |
|
230 | + */ |
|
231 | + protected function writeToOutputBuffer($output) |
|
232 | + { |
|
233 | + if ($this->sendHttpCode() && Misc::sendHeaders()) |
|
234 | + { |
|
235 | + $this->system->setHttpResponseCode($this->sendHttpCode()); |
|
236 | + } |
|
237 | 237 | |
238 | - echo $output; |
|
238 | + echo $output; |
|
239 | 239 | |
240 | - return $this; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Error handler |
|
245 | - * |
|
246 | - * This will catch the php native error and treat it as a exception which will |
|
247 | - * provide a full back trace on all errors. |
|
248 | - * |
|
249 | - * @param int $level |
|
250 | - * @param string $message |
|
251 | - * @param string|null $file |
|
252 | - * @param int|null $line |
|
253 | - * |
|
254 | - * @throws \ErrorException |
|
255 | - */ |
|
256 | - public function handleError(int $level, string $message, string $file = null, int $line = null) |
|
257 | - { |
|
258 | - if ($level & $this->system->getErrorReportingLevel()) |
|
259 | - { |
|
260 | - $exception = new ErrorException($message, $level, $level, $file, $line); |
|
261 | - |
|
262 | - if ($this->throwExceptions) |
|
263 | - { |
|
264 | - throw $exception; |
|
265 | - } |
|
266 | - else |
|
267 | - { |
|
268 | - $this->handleException($exception); |
|
269 | - } |
|
270 | - |
|
271 | - return true; |
|
272 | - } |
|
273 | - |
|
274 | - return false; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Pushes a handler to the end of the stack. |
|
279 | - * |
|
280 | - * @param \Callable|\Syscodes\Contracts\Debug\Handler $handler |
|
281 | - * |
|
282 | - * @return \Syscodes\Contracts\Debug\Handler |
|
283 | - */ |
|
284 | - public function pushHandler($handler) |
|
285 | - { |
|
286 | - return $this->prependHandler($handler); |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Appends a handler to the end of the stack. |
|
291 | - * |
|
292 | - * @param \Callable|\Syscodes\Contracts\Debug\Handler $handler |
|
293 | - * |
|
294 | - * @return $this |
|
295 | - */ |
|
296 | - public function appendHandler($handler) |
|
297 | - { |
|
298 | - array_unshift($this->handlerStack, $this->resolveHandler($handler)); |
|
299 | - |
|
300 | - return $this; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Prepends a handler to the start of the stack. |
|
305 | - * |
|
306 | - * @param \Callable|\Syscodes\Contracts\Debug\Handler $handler |
|
307 | - * |
|
308 | - * @return $this |
|
309 | - */ |
|
310 | - public function prependHandler($handler) |
|
311 | - { |
|
312 | - array_unshift($this->handlerStack, $this->resolveHandler($handler)); |
|
313 | - |
|
314 | - return $this; |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * Create a CallbackHandler from callable and throw if handler is invalid. |
|
319 | - * |
|
320 | - * @param \Callable|\Syscodes\Contracts\Debug\Handler $handler |
|
321 | - * |
|
322 | - * @return \Syscodes\Contracts\Debug\Handler |
|
323 | - * |
|
324 | - * @throws \InvalidArgumentException If argument is not callable or instance of \Syscodes\Contracts\Debug\Handler |
|
325 | - */ |
|
326 | - protected function resolveHandler($handler) |
|
327 | - { |
|
328 | - if (is_callable($handler)) |
|
329 | - { |
|
330 | - $handler = new CallbackHandler($handler); |
|
331 | - } |
|
332 | - |
|
333 | - if ( ! $handler instanceof MainHandler) { |
|
334 | - throw new InvalidArgumentException( |
|
335 | - "Argument to " . __METHOD__ . " must be a callable, or instance of ". |
|
336 | - "Syscodes\\Contracts\\Debug\\Handler" |
|
337 | - ); |
|
338 | - } |
|
339 | - |
|
340 | - return $handler; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Returns an array with all handlers, in the order they were added to the stack. |
|
345 | - * |
|
346 | - * @return array |
|
347 | - */ |
|
348 | - public function getHandlers() |
|
349 | - { |
|
350 | - return $this->handlerStack; |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Clears all handlers in the handlerStack, including the default PleasingPage handler. |
|
355 | - * |
|
356 | - * @return $this |
|
357 | - */ |
|
358 | - public function clearHandlers() |
|
359 | - { |
|
360 | - $this->handlerStack = []; |
|
361 | - |
|
362 | - return $this; |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Removes the last handler in the stack and returns it. |
|
367 | - * |
|
368 | - * @return array|null |
|
369 | - */ |
|
370 | - public function popHandler() |
|
371 | - { |
|
372 | - return array_pop($this->handlerStack); |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Gets supervisor already specified. |
|
377 | - * |
|
378 | - * @param \Throwable $exception |
|
379 | - * |
|
380 | - * @return \Syscodes\Debug\Engine\Supervisor |
|
381 | - */ |
|
382 | - protected function getSupervisor(Throwable $exception) |
|
383 | - { |
|
384 | - return new Supervisor($exception); |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Unregisters all handlers registered by this Debug instance. |
|
389 | - * |
|
390 | - * @return void |
|
391 | - */ |
|
392 | - public function off() |
|
393 | - { |
|
394 | - $this->system->restoreExceptionHandler(); |
|
395 | - $this->system->restoreErrorHandler(); |
|
396 | - } |
|
240 | + return $this; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Error handler |
|
245 | + * |
|
246 | + * This will catch the php native error and treat it as a exception which will |
|
247 | + * provide a full back trace on all errors. |
|
248 | + * |
|
249 | + * @param int $level |
|
250 | + * @param string $message |
|
251 | + * @param string|null $file |
|
252 | + * @param int|null $line |
|
253 | + * |
|
254 | + * @throws \ErrorException |
|
255 | + */ |
|
256 | + public function handleError(int $level, string $message, string $file = null, int $line = null) |
|
257 | + { |
|
258 | + if ($level & $this->system->getErrorReportingLevel()) |
|
259 | + { |
|
260 | + $exception = new ErrorException($message, $level, $level, $file, $line); |
|
261 | + |
|
262 | + if ($this->throwExceptions) |
|
263 | + { |
|
264 | + throw $exception; |
|
265 | + } |
|
266 | + else |
|
267 | + { |
|
268 | + $this->handleException($exception); |
|
269 | + } |
|
270 | + |
|
271 | + return true; |
|
272 | + } |
|
273 | + |
|
274 | + return false; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Pushes a handler to the end of the stack. |
|
279 | + * |
|
280 | + * @param \Callable|\Syscodes\Contracts\Debug\Handler $handler |
|
281 | + * |
|
282 | + * @return \Syscodes\Contracts\Debug\Handler |
|
283 | + */ |
|
284 | + public function pushHandler($handler) |
|
285 | + { |
|
286 | + return $this->prependHandler($handler); |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Appends a handler to the end of the stack. |
|
291 | + * |
|
292 | + * @param \Callable|\Syscodes\Contracts\Debug\Handler $handler |
|
293 | + * |
|
294 | + * @return $this |
|
295 | + */ |
|
296 | + public function appendHandler($handler) |
|
297 | + { |
|
298 | + array_unshift($this->handlerStack, $this->resolveHandler($handler)); |
|
299 | + |
|
300 | + return $this; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Prepends a handler to the start of the stack. |
|
305 | + * |
|
306 | + * @param \Callable|\Syscodes\Contracts\Debug\Handler $handler |
|
307 | + * |
|
308 | + * @return $this |
|
309 | + */ |
|
310 | + public function prependHandler($handler) |
|
311 | + { |
|
312 | + array_unshift($this->handlerStack, $this->resolveHandler($handler)); |
|
313 | + |
|
314 | + return $this; |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * Create a CallbackHandler from callable and throw if handler is invalid. |
|
319 | + * |
|
320 | + * @param \Callable|\Syscodes\Contracts\Debug\Handler $handler |
|
321 | + * |
|
322 | + * @return \Syscodes\Contracts\Debug\Handler |
|
323 | + * |
|
324 | + * @throws \InvalidArgumentException If argument is not callable or instance of \Syscodes\Contracts\Debug\Handler |
|
325 | + */ |
|
326 | + protected function resolveHandler($handler) |
|
327 | + { |
|
328 | + if (is_callable($handler)) |
|
329 | + { |
|
330 | + $handler = new CallbackHandler($handler); |
|
331 | + } |
|
332 | + |
|
333 | + if ( ! $handler instanceof MainHandler) { |
|
334 | + throw new InvalidArgumentException( |
|
335 | + "Argument to " . __METHOD__ . " must be a callable, or instance of ". |
|
336 | + "Syscodes\\Contracts\\Debug\\Handler" |
|
337 | + ); |
|
338 | + } |
|
339 | + |
|
340 | + return $handler; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Returns an array with all handlers, in the order they were added to the stack. |
|
345 | + * |
|
346 | + * @return array |
|
347 | + */ |
|
348 | + public function getHandlers() |
|
349 | + { |
|
350 | + return $this->handlerStack; |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Clears all handlers in the handlerStack, including the default PleasingPage handler. |
|
355 | + * |
|
356 | + * @return $this |
|
357 | + */ |
|
358 | + public function clearHandlers() |
|
359 | + { |
|
360 | + $this->handlerStack = []; |
|
361 | + |
|
362 | + return $this; |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Removes the last handler in the stack and returns it. |
|
367 | + * |
|
368 | + * @return array|null |
|
369 | + */ |
|
370 | + public function popHandler() |
|
371 | + { |
|
372 | + return array_pop($this->handlerStack); |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Gets supervisor already specified. |
|
377 | + * |
|
378 | + * @param \Throwable $exception |
|
379 | + * |
|
380 | + * @return \Syscodes\Debug\Engine\Supervisor |
|
381 | + */ |
|
382 | + protected function getSupervisor(Throwable $exception) |
|
383 | + { |
|
384 | + return new Supervisor($exception); |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Unregisters all handlers registered by this Debug instance. |
|
389 | + * |
|
390 | + * @return void |
|
391 | + */ |
|
392 | + public function off() |
|
393 | + { |
|
394 | + $this->system->restoreExceptionHandler(); |
|
395 | + $this->system->restoreErrorHandler(); |
|
396 | + } |
|
397 | 397 | |
398 | - /** |
|
399 | - * Registers this instance as an error handler. |
|
400 | - * |
|
401 | - * @return void |
|
402 | - */ |
|
403 | - public function on() |
|
404 | - { |
|
405 | - // Set the exception handler |
|
406 | - $this->system->setExceptionHandler([$this, self::EXCEPTION_HANDLER]); |
|
407 | - // Set the error handler |
|
408 | - $this->system->setErrorHandler([$this, self::ERROR_HANDLER]); |
|
409 | - // Set the handler for shutdown to catch Parse errors |
|
410 | - $this->system->registerShutdownFunction([$this, self::SHUTDOWN_HANDLER]); |
|
411 | - } |
|
412 | - |
|
413 | - /** |
|
414 | - * Lenevor Exception will by default send HTTP code 500, but you may wish |
|
415 | - * to use 502, 503, or another 5xx family code. |
|
416 | - * |
|
417 | - * @param bool|int $code |
|
418 | - * |
|
419 | - * @return int|false |
|
420 | - * |
|
421 | - * @throws \InvalidArgumentException |
|
422 | - */ |
|
423 | - public function sendHttpCode($code = null) |
|
424 | - { |
|
425 | - if (func_num_args() == 0) |
|
426 | - { |
|
427 | - return $this->sendHttpCode; |
|
428 | - } |
|
398 | + /** |
|
399 | + * Registers this instance as an error handler. |
|
400 | + * |
|
401 | + * @return void |
|
402 | + */ |
|
403 | + public function on() |
|
404 | + { |
|
405 | + // Set the exception handler |
|
406 | + $this->system->setExceptionHandler([$this, self::EXCEPTION_HANDLER]); |
|
407 | + // Set the error handler |
|
408 | + $this->system->setErrorHandler([$this, self::ERROR_HANDLER]); |
|
409 | + // Set the handler for shutdown to catch Parse errors |
|
410 | + $this->system->registerShutdownFunction([$this, self::SHUTDOWN_HANDLER]); |
|
411 | + } |
|
412 | + |
|
413 | + /** |
|
414 | + * Lenevor Exception will by default send HTTP code 500, but you may wish |
|
415 | + * to use 502, 503, or another 5xx family code. |
|
416 | + * |
|
417 | + * @param bool|int $code |
|
418 | + * |
|
419 | + * @return int|false |
|
420 | + * |
|
421 | + * @throws \InvalidArgumentException |
|
422 | + */ |
|
423 | + public function sendHttpCode($code = null) |
|
424 | + { |
|
425 | + if (func_num_args() == 0) |
|
426 | + { |
|
427 | + return $this->sendHttpCode; |
|
428 | + } |
|
429 | 429 | |
430 | - if ( ! $code) |
|
431 | - { |
|
432 | - return $this->sendHttpCode = false; |
|
433 | - } |
|
430 | + if ( ! $code) |
|
431 | + { |
|
432 | + return $this->sendHttpCode = false; |
|
433 | + } |
|
434 | 434 | |
435 | - if ($code === true) |
|
436 | - { |
|
437 | - $code = 500; |
|
438 | - } |
|
435 | + if ($code === true) |
|
436 | + { |
|
437 | + $code = 500; |
|
438 | + } |
|
439 | 439 | |
440 | - if ($code < 400 || 600 <= $code) |
|
441 | - { |
|
442 | - throw new InvalidArgumentException("Invalid status code {$code}, must be 4xx or 5xx"); |
|
443 | - } |
|
440 | + if ($code < 400 || 600 <= $code) |
|
441 | + { |
|
442 | + throw new InvalidArgumentException("Invalid status code {$code}, must be 4xx or 5xx"); |
|
443 | + } |
|
444 | 444 | |
445 | - return $this->sendHttpCode = $code; |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * This will catch errors that are generated at the shutdown level of execution. |
|
450 | - * |
|
451 | - * @return void |
|
452 | - * |
|
453 | - * @throws \ErrorException |
|
454 | - */ |
|
455 | - public function handleShutdown() |
|
456 | - { |
|
457 | - $this->throwExceptions = false; |
|
458 | - |
|
459 | - $error = $this->system->getLastError(); |
|
460 | - |
|
461 | - // If we've got an error that hasn't been displayed, then convert |
|
462 | - // it to an Exception and use the Exception handler to display it |
|
463 | - // to the user |
|
464 | - if ($error && Misc::isFatalError($error['type'])) |
|
465 | - { |
|
466 | - $this->errorHandler($error['type'], $error['message'], $error['file'], $error['line']); |
|
467 | - } |
|
468 | - } |
|
445 | + return $this->sendHttpCode = $code; |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * This will catch errors that are generated at the shutdown level of execution. |
|
450 | + * |
|
451 | + * @return void |
|
452 | + * |
|
453 | + * @throws \ErrorException |
|
454 | + */ |
|
455 | + public function handleShutdown() |
|
456 | + { |
|
457 | + $this->throwExceptions = false; |
|
458 | + |
|
459 | + $error = $this->system->getLastError(); |
|
460 | + |
|
461 | + // If we've got an error that hasn't been displayed, then convert |
|
462 | + // it to an Exception and use the Exception handler to display it |
|
463 | + // to the user |
|
464 | + if ($error && Misc::isFatalError($error['type'])) |
|
465 | + { |
|
466 | + $this->errorHandler($error['type'], $error['message'], $error['file'], $error['line']); |
|
467 | + } |
|
468 | + } |
|
469 | 469 | } |
470 | 470 | \ No newline at end of file |
@@ -332,7 +332,7 @@ |
||
332 | 332 | |
333 | 333 | if ( ! $handler instanceof MainHandler) { |
334 | 334 | throw new InvalidArgumentException( |
335 | - "Argument to " . __METHOD__ . " must be a callable, or instance of ". |
|
335 | + "Argument to ".__METHOD__." must be a callable, or instance of ". |
|
336 | 336 | "Syscodes\\Contracts\\Debug\\Handler" |
337 | 337 | ); |
338 | 338 | } |
@@ -146,8 +146,7 @@ discard block |
||
146 | 146 | } |
147 | 147 | |
148 | 148 | $Quit = $handlerResponse == MainHandler::QUIT && $this->allowQuit(); |
149 | - } |
|
150 | - finally |
|
149 | + } finally |
|
151 | 150 | { |
152 | 151 | // Returns the contents of the output buffer |
153 | 152 | $output = $this->system->CleanOutputBuffer(); |
@@ -262,8 +261,7 @@ discard block |
||
262 | 261 | if ($this->throwExceptions) |
263 | 262 | { |
264 | 263 | throw $exception; |
265 | - } |
|
266 | - else |
|
264 | + } else |
|
267 | 265 | { |
268 | 266 | $this->handleException($exception); |
269 | 267 | } |
@@ -56,12 +56,10 @@ |
||
56 | 56 | if ($exception instanceof ParseError) |
57 | 57 | { |
58 | 58 | $severity = E_PARSE; |
59 | - } |
|
60 | - elseif ($exception instanceof TypeError) |
|
59 | + } elseif ($exception instanceof TypeError) |
|
61 | 60 | { |
62 | 61 | $severity = E_RECOVERABLE_ERROR; |
63 | - } |
|
64 | - else |
|
62 | + } else |
|
65 | 63 | { |
66 | 64 | $severity = E_ERROR; |
67 | 65 | } |
@@ -219,13 +219,13 @@ |
||
219 | 219 | return $this->file; |
220 | 220 | } |
221 | 221 | |
222 | - /** |
|
223 | - * Sets the file path. |
|
224 | - * |
|
225 | - * @param string $file |
|
226 | - * |
|
227 | - * @return $this |
|
228 | - */ |
|
222 | + /** |
|
223 | + * Sets the file path. |
|
224 | + * |
|
225 | + * @param string $file |
|
226 | + * |
|
227 | + * @return $this |
|
228 | + */ |
|
229 | 229 | public function setFile($file) |
230 | 230 | { |
231 | 231 | $this->file = $file; |
@@ -487,43 +487,34 @@ |
||
487 | 487 | if ($value instanceof \__PHP_Incomplete_Class) |
488 | 488 | { |
489 | 489 | $result[$key] = ['incomplete-object', $this->getClassNameFromIncomplete($value)]; |
490 | - } |
|
491 | - elseif (is_object($value)) |
|
490 | + } elseif (is_object($value)) |
|
492 | 491 | { |
493 | 492 | $result[$key] = ['object', get_class($value)]; |
494 | - } |
|
495 | - elseif (is_array($value)) |
|
493 | + } elseif (is_array($value)) |
|
496 | 494 | { |
497 | 495 | if ($level > 10) |
498 | 496 | { |
499 | 497 | $result[$key] = ['array', '*DEEP NESTED ARRAY*']; |
500 | - } |
|
501 | - else |
|
498 | + } else |
|
502 | 499 | { |
503 | 500 | $result[$key] = ['array', $this->flattenArgs($value, $level + 1, $count)]; |
504 | 501 | } |
505 | - } |
|
506 | - elseif ($value === null) |
|
502 | + } elseif ($value === null) |
|
507 | 503 | { |
508 | 504 | $result[$key] = ['null', null]; |
509 | - } |
|
510 | - elseif (is_bool($value)) |
|
505 | + } elseif (is_bool($value)) |
|
511 | 506 | { |
512 | 507 | $result[$key] = ['boolean', $value]; |
513 | - } |
|
514 | - elseif (is_int($value)) |
|
508 | + } elseif (is_int($value)) |
|
515 | 509 | { |
516 | 510 | $result[$key] = ['integer', $value]; |
517 | - } |
|
518 | - elseif (is_float($value)) |
|
511 | + } elseif (is_float($value)) |
|
519 | 512 | { |
520 | 513 | $result[$key] = ['float', $value]; |
521 | - } |
|
522 | - elseif (is_resource($value)) |
|
514 | + } elseif (is_resource($value)) |
|
523 | 515 | { |
524 | 516 | $result[$key] = ['resource', get_resource_type($value)]; |
525 | - } |
|
526 | - else |
|
517 | + } else |
|
527 | 518 | { |
528 | 519 | $result[$key] = ['string', (string) $value]; |
529 | 520 | } |
@@ -74,8 +74,7 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | $this->setTrace($trace); |
77 | - } |
|
78 | - elseif (null !== $traceOffset) |
|
77 | + } elseif (null !== $traceOffset) |
|
79 | 78 | { |
80 | 79 | if (function_exists('xdebug_get_function_stack')) |
81 | 80 | { |
@@ -94,12 +93,10 @@ discard block |
||
94 | 93 | { |
95 | 94 | $frame['type'] = '::'; |
96 | 95 | } |
97 | - } |
|
98 | - elseif ('dynamic' === $frame['type']) |
|
96 | + } elseif ('dynamic' === $frame['type']) |
|
99 | 97 | { |
100 | 98 | $frame['type'] = '->'; |
101 | - } |
|
102 | - elseif ('static' === $frame['type']) |
|
99 | + } elseif ('static' === $frame['type']) |
|
103 | 100 | { |
104 | 101 | $frame['type'] = '::'; |
105 | 102 | } |
@@ -107,8 +104,7 @@ discard block |
||
107 | 104 | if ( ! $traceArgs) |
108 | 105 | { |
109 | 106 | unset($frame['params'], $frame['args']); |
110 | - } |
|
111 | - elseif (isset($frame['params']) && ! $frame['args']) |
|
107 | + } elseif (isset($frame['params']) && ! $frame['args']) |
|
112 | 108 | { |
113 | 109 | $frame['args'] = $frame['params']; |
114 | 110 | unset($frame['params']); |
@@ -117,8 +113,7 @@ discard block |
||
117 | 113 | |
118 | 114 | unset($frame); |
119 | 115 | $trace = array_reverse($trace); |
120 | - } |
|
121 | - else |
|
116 | + } else |
|
122 | 117 | { |
123 | 118 | $trace = []; |
124 | 119 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | */ |
40 | 40 | public function register() |
41 | 41 | { |
42 | - $this->app->singleton('events', function ($app) { |
|
42 | + $this->app->singleton('events', function($app) { |
|
43 | 43 | return new Dispatcher($app); |
44 | 44 | }); |
45 | 45 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | return $this->createClassListener($listener, $wilcard); |
137 | 137 | } |
138 | 138 | |
139 | - return function ($event, $payload) use ($listener, $wilcard) { |
|
139 | + return function($event, $payload) use ($listener, $wilcard) { |
|
140 | 140 | |
141 | 141 | if ($wilcard) |
142 | 142 | { |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function createClassListener($listener, $wilcard = false) |
160 | 160 | { |
161 | - return function ($event, $payload) use ($listener, $wilcard) { |
|
161 | + return function($event, $payload) use ($listener, $wilcard) { |
|
162 | 162 | |
163 | 163 | if ($wilcard) |
164 | 164 | { |
@@ -98,8 +98,7 @@ discard block |
||
98 | 98 | if (Str::contains($event, '*')) |
99 | 99 | { |
100 | 100 | $this->setupWilcardListen($event, $listener); |
101 | - } |
|
102 | - else |
|
101 | + } else |
|
103 | 102 | { |
104 | 103 | $this->listeners[$event][$priority][] = $this->makeListener($listener); |
105 | 104 | |
@@ -336,8 +335,7 @@ discard block |
||
336 | 335 | if (is_object($event)) |
337 | 336 | { |
338 | 337 | list($payload, $event) = [[$event], getClass($event, false)]; |
339 | - } |
|
340 | - elseif ( ! is_array($payload)) |
|
338 | + } elseif ( ! is_array($payload)) |
|
341 | 339 | { |
342 | 340 | $payload = [$payload]; |
343 | 341 | } |
@@ -422,8 +420,7 @@ discard block |
||
422 | 420 | if (Str::contains($event, '*')) |
423 | 421 | { |
424 | 422 | unset($this->wilcards[$event]); |
425 | - } |
|
426 | - else |
|
423 | + } else |
|
427 | 424 | { |
428 | 425 | unset($this->listeners[$event], $this->sorted[$event]); |
429 | 426 | } |
@@ -33,40 +33,40 @@ discard block |
||
33 | 33 | */ |
34 | 34 | class Arr |
35 | 35 | { |
36 | - /** |
|
37 | - * Determine whether the value is accessible in a array. |
|
38 | - * |
|
39 | - * @param mixed $value The default value |
|
40 | - * |
|
41 | - * @return bool |
|
42 | - * |
|
43 | - * @uses instanceof ArrayAccess |
|
44 | - */ |
|
45 | - public static function access($value) |
|
46 | - { |
|
47 | - return is_array($value) || $value instanceof ArrayAccess; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Add an element to an array using "dot" notation if it doesn't exist. |
|
52 | - * |
|
53 | - * @param array $array The search array |
|
54 | - * @param string $key The key exist |
|
55 | - * @param mixed $value The default value |
|
56 | - * |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public static function add($array, $key, $value) |
|
60 | - { |
|
61 | - if (is_null(static::get($array, $key))) |
|
62 | - { |
|
63 | - static::set($array, $key, $value); |
|
64 | - } |
|
65 | - |
|
66 | - return $array; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
36 | + /** |
|
37 | + * Determine whether the value is accessible in a array. |
|
38 | + * |
|
39 | + * @param mixed $value The default value |
|
40 | + * |
|
41 | + * @return bool |
|
42 | + * |
|
43 | + * @uses instanceof ArrayAccess |
|
44 | + */ |
|
45 | + public static function access($value) |
|
46 | + { |
|
47 | + return is_array($value) || $value instanceof ArrayAccess; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Add an element to an array using "dot" notation if it doesn't exist. |
|
52 | + * |
|
53 | + * @param array $array The search array |
|
54 | + * @param string $key The key exist |
|
55 | + * @param mixed $value The default value |
|
56 | + * |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public static function add($array, $key, $value) |
|
60 | + { |
|
61 | + if (is_null(static::get($array, $key))) |
|
62 | + { |
|
63 | + static::set($array, $key, $value); |
|
64 | + } |
|
65 | + |
|
66 | + return $array; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | 70 | * Collapse the collection items into a single array. |
71 | 71 | * |
72 | 72 | * @return static |
@@ -77,387 +77,387 @@ discard block |
||
77 | 77 | |
78 | 78 | foreach ($array as $values) |
79 | 79 | { |
80 | - if ($values instanceof Collection) |
|
81 | - { |
|
82 | - $values = $values->all(); |
|
83 | - } |
|
84 | - elseif ( ! is_array($values)) |
|
85 | - { |
|
86 | - continue; |
|
87 | - } |
|
88 | - |
|
89 | - $results[] = $values; |
|
80 | + if ($values instanceof Collection) |
|
81 | + { |
|
82 | + $values = $values->all(); |
|
83 | + } |
|
84 | + elseif ( ! is_array($values)) |
|
85 | + { |
|
86 | + continue; |
|
87 | + } |
|
88 | + |
|
89 | + $results[] = $values; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | return array_merge([], ...$results); |
93 | 93 | } |
94 | 94 | |
95 | - /** |
|
96 | - * Divide an array into two arrays. One with keys and the other with values. |
|
97 | - * |
|
98 | - * @param array $array |
|
99 | - * |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - public static function divide($array) |
|
103 | - { |
|
104 | - return [array_keys($array), array_values($array)]; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Get all of the given array except for a specified array of items. |
|
109 | - * |
|
110 | - * @param array $array |
|
111 | - * @param string|array $keys |
|
112 | - * |
|
113 | - * @return array |
|
114 | - */ |
|
115 | - public static function except($array, $keys) |
|
116 | - { |
|
117 | - static::erase($array, $keys); |
|
118 | - |
|
119 | - return $array; |
|
120 | - } |
|
95 | + /** |
|
96 | + * Divide an array into two arrays. One with keys and the other with values. |
|
97 | + * |
|
98 | + * @param array $array |
|
99 | + * |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + public static function divide($array) |
|
103 | + { |
|
104 | + return [array_keys($array), array_values($array)]; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Get all of the given array except for a specified array of items. |
|
109 | + * |
|
110 | + * @param array $array |
|
111 | + * @param string|array $keys |
|
112 | + * |
|
113 | + * @return array |
|
114 | + */ |
|
115 | + public static function except($array, $keys) |
|
116 | + { |
|
117 | + static::erase($array, $keys); |
|
118 | + |
|
119 | + return $array; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Determine if the given key exists in the provided array. |
|
124 | - * |
|
125 | - * @param ArrayAccess|array $array The search array |
|
126 | - * @param string|int $key The key exist |
|
127 | - * |
|
128 | - * @return bool |
|
129 | - * |
|
130 | - * @uses instaceof ArrayAccess |
|
131 | - */ |
|
132 | - public static function exists($array, $key) |
|
133 | - { |
|
134 | - if ($array instanceof ArrayAccess) |
|
135 | - { |
|
136 | - return $array->offsetExists($key); |
|
137 | - } |
|
122 | + /** |
|
123 | + * Determine if the given key exists in the provided array. |
|
124 | + * |
|
125 | + * @param ArrayAccess|array $array The search array |
|
126 | + * @param string|int $key The key exist |
|
127 | + * |
|
128 | + * @return bool |
|
129 | + * |
|
130 | + * @uses instaceof ArrayAccess |
|
131 | + */ |
|
132 | + public static function exists($array, $key) |
|
133 | + { |
|
134 | + if ($array instanceof ArrayAccess) |
|
135 | + { |
|
136 | + return $array->offsetExists($key); |
|
137 | + } |
|
138 | 138 | |
139 | - return array_key_exists($key, $array); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Unsets dot-notated key from an array. |
|
144 | - * |
|
145 | - * @param array $array The search array |
|
146 | - * @param mixed $keys The dot-notated key or array of keys |
|
147 | - * |
|
148 | - * @return mixed |
|
149 | - */ |
|
150 | - public static function erase(&$array, $keys) |
|
151 | - { |
|
152 | - $original = &$array; |
|
153 | - |
|
154 | - $keys = (array) $keys; |
|
155 | - |
|
156 | - if (count($keys) === 0) |
|
157 | - { |
|
158 | - return; |
|
159 | - } |
|
160 | - |
|
161 | - foreach ($keys as $key) |
|
162 | - { |
|
163 | - if (static::exists($array, $key)) |
|
164 | - { |
|
165 | - unset($array[$key]); |
|
166 | - |
|
167 | - continue; |
|
168 | - } |
|
139 | + return array_key_exists($key, $array); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Unsets dot-notated key from an array. |
|
144 | + * |
|
145 | + * @param array $array The search array |
|
146 | + * @param mixed $keys The dot-notated key or array of keys |
|
147 | + * |
|
148 | + * @return mixed |
|
149 | + */ |
|
150 | + public static function erase(&$array, $keys) |
|
151 | + { |
|
152 | + $original = &$array; |
|
153 | + |
|
154 | + $keys = (array) $keys; |
|
155 | + |
|
156 | + if (count($keys) === 0) |
|
157 | + { |
|
158 | + return; |
|
159 | + } |
|
160 | + |
|
161 | + foreach ($keys as $key) |
|
162 | + { |
|
163 | + if (static::exists($array, $key)) |
|
164 | + { |
|
165 | + unset($array[$key]); |
|
166 | + |
|
167 | + continue; |
|
168 | + } |
|
169 | 169 | |
170 | - $parts = explode('.', $key); |
|
170 | + $parts = explode('.', $key); |
|
171 | 171 | |
172 | - // Clean up after each pass |
|
173 | - $array = &$original; |
|
172 | + // Clean up after each pass |
|
173 | + $array = &$original; |
|
174 | 174 | |
175 | - // traverse the array into the second last key |
|
176 | - while (count($parts) > 1) |
|
177 | - { |
|
178 | - $part = array_shift($parts); |
|
175 | + // traverse the array into the second last key |
|
176 | + while (count($parts) > 1) |
|
177 | + { |
|
178 | + $part = array_shift($parts); |
|
179 | 179 | |
180 | - if (isset($array[$part]) && is_array($array[$part])) |
|
181 | - { |
|
182 | - $array = &$array[$key]; |
|
183 | - } |
|
184 | - else |
|
185 | - { |
|
186 | - continue 2; |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - unset($array[array_shift($parts)]); |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Flatten a multi-dimensional array into a single level. |
|
196 | - * |
|
197 | - * @param array $array |
|
198 | - * |
|
199 | - * @return array |
|
200 | - */ |
|
201 | - public static function flatten($array) |
|
202 | - { |
|
203 | - $result = []; |
|
204 | - |
|
205 | - array_walk_recursive($array, function ($value) use (&$result) { |
|
206 | - $result[] = $value; |
|
207 | - }); |
|
208 | - |
|
209 | - return $result; |
|
210 | - } |
|
180 | + if (isset($array[$part]) && is_array($array[$part])) |
|
181 | + { |
|
182 | + $array = &$array[$key]; |
|
183 | + } |
|
184 | + else |
|
185 | + { |
|
186 | + continue 2; |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + unset($array[array_shift($parts)]); |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Flatten a multi-dimensional array into a single level. |
|
196 | + * |
|
197 | + * @param array $array |
|
198 | + * |
|
199 | + * @return array |
|
200 | + */ |
|
201 | + public static function flatten($array) |
|
202 | + { |
|
203 | + $result = []; |
|
204 | + |
|
205 | + array_walk_recursive($array, function ($value) use (&$result) { |
|
206 | + $result[] = $value; |
|
207 | + }); |
|
208 | + |
|
209 | + return $result; |
|
210 | + } |
|
211 | 211 | |
212 | - /** |
|
213 | - * Fetch a flattened array of a nested array element. |
|
214 | - * |
|
215 | - * @param array $array |
|
216 | - * @param string $key |
|
217 | - * |
|
218 | - * @return array |
|
219 | - */ |
|
220 | - public static function fetch($array, $key) |
|
221 | - { |
|
222 | - foreach (explode('.', $key) as $segment) |
|
223 | - { |
|
224 | - $results = array(); |
|
212 | + /** |
|
213 | + * Fetch a flattened array of a nested array element. |
|
214 | + * |
|
215 | + * @param array $array |
|
216 | + * @param string $key |
|
217 | + * |
|
218 | + * @return array |
|
219 | + */ |
|
220 | + public static function fetch($array, $key) |
|
221 | + { |
|
222 | + foreach (explode('.', $key) as $segment) |
|
223 | + { |
|
224 | + $results = array(); |
|
225 | 225 | |
226 | - foreach ($array as $value) |
|
227 | - { |
|
228 | - if (array_key_exists($segment, $value = (array) $value)) |
|
229 | - { |
|
230 | - $results[] = $value[$segment]; |
|
231 | - } |
|
232 | - } |
|
226 | + foreach ($array as $value) |
|
227 | + { |
|
228 | + if (array_key_exists($segment, $value = (array) $value)) |
|
229 | + { |
|
230 | + $results[] = $value[$segment]; |
|
231 | + } |
|
232 | + } |
|
233 | 233 | |
234 | - $array = array_values($results); |
|
235 | - } |
|
234 | + $array = array_values($results); |
|
235 | + } |
|
236 | 236 | |
237 | - return array_values($results); |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * Return the first element in an array passing a given truth test. |
|
242 | - * |
|
243 | - * @param array $array |
|
244 | - * @param \Closure $callback |
|
245 | - * @param mixed $default (null by default) |
|
246 | - * |
|
247 | - * @return mixed |
|
248 | - */ |
|
249 | - public static function first($array, callable $callback, $default = null) |
|
250 | - { |
|
251 | - foreach ($array as $key => $value) |
|
252 | - { |
|
253 | - if (call_user_func($callback, $key, $value)) return $value; |
|
254 | - } |
|
255 | - |
|
256 | - return value($default); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Get an item from an array using "dot" notation. |
|
261 | - * |
|
262 | - * @param \ArrayAccess|array $array The search array |
|
263 | - * @param string $key The dot-notated key or array of keys |
|
264 | - * @param mixed $default The default value |
|
265 | - * |
|
266 | - * @return mixed |
|
267 | - */ |
|
268 | - public static function get($array, $key, $default = null) |
|
269 | - { |
|
270 | - if ( ! static::access($array)) |
|
271 | - { |
|
272 | - return value($default); |
|
273 | - } |
|
274 | - |
|
275 | - if (static::exists($array, $key)) |
|
276 | - { |
|
277 | - return $array[$key]; |
|
278 | - } |
|
279 | - |
|
280 | - foreach (explode('.', $key) as $segm) |
|
281 | - { |
|
282 | - if (static::access($array) && static::exists($array, $segm)) |
|
283 | - { |
|
284 | - $array = $array[$segm]; |
|
285 | - } |
|
286 | - else |
|
287 | - { |
|
288 | - return value($default); |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - return $array; |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Return the last element in an array passing a given truth test. |
|
297 | - * |
|
298 | - * @param array $array |
|
299 | - * @param \Closure $callback |
|
300 | - * @param mixed $default |
|
301 | - * |
|
302 | - * @return mixed |
|
303 | - * |
|
304 | - * @uses \Syscodes\Support\Arr::first |
|
305 | - */ |
|
306 | - public static function last($array, $callback, $default = null) |
|
307 | - { |
|
308 | - return static::first(array_reverse($array), $callback, $default); |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * Check if an item exists in an array using "dot" notation. |
|
313 | - * |
|
314 | - * @param array $array |
|
315 | - * @param string $key |
|
316 | - * |
|
317 | - * @return bool |
|
318 | - */ |
|
319 | - public static function has($array, $key) |
|
320 | - { |
|
321 | - if (empty($array) || is_null($key)) return false; |
|
237 | + return array_values($results); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Return the first element in an array passing a given truth test. |
|
242 | + * |
|
243 | + * @param array $array |
|
244 | + * @param \Closure $callback |
|
245 | + * @param mixed $default (null by default) |
|
246 | + * |
|
247 | + * @return mixed |
|
248 | + */ |
|
249 | + public static function first($array, callable $callback, $default = null) |
|
250 | + { |
|
251 | + foreach ($array as $key => $value) |
|
252 | + { |
|
253 | + if (call_user_func($callback, $key, $value)) return $value; |
|
254 | + } |
|
255 | + |
|
256 | + return value($default); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Get an item from an array using "dot" notation. |
|
261 | + * |
|
262 | + * @param \ArrayAccess|array $array The search array |
|
263 | + * @param string $key The dot-notated key or array of keys |
|
264 | + * @param mixed $default The default value |
|
265 | + * |
|
266 | + * @return mixed |
|
267 | + */ |
|
268 | + public static function get($array, $key, $default = null) |
|
269 | + { |
|
270 | + if ( ! static::access($array)) |
|
271 | + { |
|
272 | + return value($default); |
|
273 | + } |
|
274 | + |
|
275 | + if (static::exists($array, $key)) |
|
276 | + { |
|
277 | + return $array[$key]; |
|
278 | + } |
|
279 | + |
|
280 | + foreach (explode('.', $key) as $segm) |
|
281 | + { |
|
282 | + if (static::access($array) && static::exists($array, $segm)) |
|
283 | + { |
|
284 | + $array = $array[$segm]; |
|
285 | + } |
|
286 | + else |
|
287 | + { |
|
288 | + return value($default); |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + return $array; |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Return the last element in an array passing a given truth test. |
|
297 | + * |
|
298 | + * @param array $array |
|
299 | + * @param \Closure $callback |
|
300 | + * @param mixed $default |
|
301 | + * |
|
302 | + * @return mixed |
|
303 | + * |
|
304 | + * @uses \Syscodes\Support\Arr::first |
|
305 | + */ |
|
306 | + public static function last($array, $callback, $default = null) |
|
307 | + { |
|
308 | + return static::first(array_reverse($array), $callback, $default); |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * Check if an item exists in an array using "dot" notation. |
|
313 | + * |
|
314 | + * @param array $array |
|
315 | + * @param string $key |
|
316 | + * |
|
317 | + * @return bool |
|
318 | + */ |
|
319 | + public static function has($array, $key) |
|
320 | + { |
|
321 | + if (empty($array) || is_null($key)) return false; |
|
322 | 322 | |
323 | - if (array_key_exists($key, $array)) return true; |
|
323 | + if (array_key_exists($key, $array)) return true; |
|
324 | 324 | |
325 | - foreach (explode('.', $key) as $segment) |
|
326 | - { |
|
327 | - if ( ! is_array($array) || ! static::exists($array, $segment)) |
|
328 | - { |
|
329 | - return false; |
|
330 | - } |
|
325 | + foreach (explode('.', $key) as $segment) |
|
326 | + { |
|
327 | + if ( ! is_array($array) || ! static::exists($array, $segment)) |
|
328 | + { |
|
329 | + return false; |
|
330 | + } |
|
331 | 331 | |
332 | - $array = $array[$segment]; |
|
333 | - } |
|
332 | + $array = $array[$segment]; |
|
333 | + } |
|
334 | 334 | |
335 | - return true; |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Get a subset of the items from the given array. |
|
340 | - * |
|
341 | - * @param array $array |
|
342 | - * @param array|string $keys |
|
343 | - * |
|
344 | - * @return array |
|
345 | - */ |
|
346 | - public static function only($array, $keys) |
|
347 | - { |
|
348 | - return array_intersect_key($array, array_flip($array), $keys); |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Sets a value in an array using "dot" notation. |
|
353 | - * |
|
354 | - * @param array $array The search array |
|
355 | - * @param string $key The dot-notated key or array of keys |
|
356 | - * @param mixed $value The default value |
|
357 | - * |
|
358 | - * @return mixed |
|
359 | - */ |
|
360 | - public static function set(& $array, $key, $value = null) |
|
361 | - { |
|
362 | - $keys = explode('.', $key); |
|
363 | - |
|
364 | - while (count($keys) > 1) |
|
365 | - { |
|
366 | - $key = array_shift($keys); |
|
367 | - |
|
368 | - if ( ! static::exists($array, $key)) |
|
369 | - { |
|
370 | - $array[$key] = []; |
|
371 | - } |
|
372 | - |
|
373 | - $array =& $array[$key]; |
|
374 | - } |
|
375 | - |
|
376 | - $array[array_shift($keys)] = $value; |
|
377 | - |
|
378 | - return $array; |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Push an item onto the beginning of an array. |
|
383 | - * |
|
384 | - * @param mixed $array |
|
385 | - * @param mixed $value |
|
386 | - * @param mixed key (null by default) |
|
387 | - * |
|
388 | - * @return array |
|
389 | - */ |
|
390 | - public static function prepend($array, $value, $key = null) |
|
391 | - { |
|
392 | - if (func_num_args() == 2) |
|
393 | - { |
|
394 | - array_unshift($array, $value); |
|
395 | - } |
|
396 | - else |
|
397 | - { |
|
398 | - $array = [$key => $value] + $array; |
|
399 | - } |
|
400 | - |
|
401 | - return $array; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Get a value from the array, and remove it. |
|
406 | - * |
|
407 | - * @param array $array |
|
408 | - * @param string $key |
|
409 | - * @param mixed $default (null by default) |
|
410 | - * |
|
411 | - * @return mixed |
|
412 | - */ |
|
413 | - public static function pull(&$array, $key, $default = null) |
|
414 | - { |
|
415 | - $value = static::get($array, $key, $default); |
|
416 | - |
|
417 | - static::erase($array, $key); |
|
418 | - |
|
419 | - return $value; |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Convert the array into a query string. |
|
424 | - * |
|
425 | - * @param array $array |
|
426 | - * |
|
427 | - * @return array |
|
428 | - */ |
|
429 | - public static function query($array) |
|
430 | - { |
|
431 | - return http_build_query($array, null, '&', PHP_QUERY_RFC3986); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Filter the array using the given callback. |
|
436 | - * |
|
437 | - * @param array $array |
|
438 | - * @param \Callable $callback |
|
439 | - * |
|
440 | - * @return array |
|
441 | - */ |
|
442 | - public static function where($array, Callable $callback) |
|
443 | - { |
|
444 | - return array_filter($array, $callback, ARRAY_FILTER_USE_BOTH); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * If the given value is not an array and not null, wrap it in one. |
|
449 | - * |
|
450 | - * @param mixed $value |
|
451 | - * |
|
452 | - * @return array |
|
453 | - */ |
|
454 | - public static function wrap($value) |
|
455 | - { |
|
456 | - if (is_null($value)) |
|
457 | - { |
|
458 | - return []; |
|
459 | - } |
|
460 | - |
|
461 | - return is_array($value) ? $value : [$value]; |
|
462 | - } |
|
335 | + return true; |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Get a subset of the items from the given array. |
|
340 | + * |
|
341 | + * @param array $array |
|
342 | + * @param array|string $keys |
|
343 | + * |
|
344 | + * @return array |
|
345 | + */ |
|
346 | + public static function only($array, $keys) |
|
347 | + { |
|
348 | + return array_intersect_key($array, array_flip($array), $keys); |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Sets a value in an array using "dot" notation. |
|
353 | + * |
|
354 | + * @param array $array The search array |
|
355 | + * @param string $key The dot-notated key or array of keys |
|
356 | + * @param mixed $value The default value |
|
357 | + * |
|
358 | + * @return mixed |
|
359 | + */ |
|
360 | + public static function set(& $array, $key, $value = null) |
|
361 | + { |
|
362 | + $keys = explode('.', $key); |
|
363 | + |
|
364 | + while (count($keys) > 1) |
|
365 | + { |
|
366 | + $key = array_shift($keys); |
|
367 | + |
|
368 | + if ( ! static::exists($array, $key)) |
|
369 | + { |
|
370 | + $array[$key] = []; |
|
371 | + } |
|
372 | + |
|
373 | + $array =& $array[$key]; |
|
374 | + } |
|
375 | + |
|
376 | + $array[array_shift($keys)] = $value; |
|
377 | + |
|
378 | + return $array; |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Push an item onto the beginning of an array. |
|
383 | + * |
|
384 | + * @param mixed $array |
|
385 | + * @param mixed $value |
|
386 | + * @param mixed key (null by default) |
|
387 | + * |
|
388 | + * @return array |
|
389 | + */ |
|
390 | + public static function prepend($array, $value, $key = null) |
|
391 | + { |
|
392 | + if (func_num_args() == 2) |
|
393 | + { |
|
394 | + array_unshift($array, $value); |
|
395 | + } |
|
396 | + else |
|
397 | + { |
|
398 | + $array = [$key => $value] + $array; |
|
399 | + } |
|
400 | + |
|
401 | + return $array; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Get a value from the array, and remove it. |
|
406 | + * |
|
407 | + * @param array $array |
|
408 | + * @param string $key |
|
409 | + * @param mixed $default (null by default) |
|
410 | + * |
|
411 | + * @return mixed |
|
412 | + */ |
|
413 | + public static function pull(&$array, $key, $default = null) |
|
414 | + { |
|
415 | + $value = static::get($array, $key, $default); |
|
416 | + |
|
417 | + static::erase($array, $key); |
|
418 | + |
|
419 | + return $value; |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Convert the array into a query string. |
|
424 | + * |
|
425 | + * @param array $array |
|
426 | + * |
|
427 | + * @return array |
|
428 | + */ |
|
429 | + public static function query($array) |
|
430 | + { |
|
431 | + return http_build_query($array, null, '&', PHP_QUERY_RFC3986); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Filter the array using the given callback. |
|
436 | + * |
|
437 | + * @param array $array |
|
438 | + * @param \Callable $callback |
|
439 | + * |
|
440 | + * @return array |
|
441 | + */ |
|
442 | + public static function where($array, Callable $callback) |
|
443 | + { |
|
444 | + return array_filter($array, $callback, ARRAY_FILTER_USE_BOTH); |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * If the given value is not an array and not null, wrap it in one. |
|
449 | + * |
|
450 | + * @param mixed $value |
|
451 | + * |
|
452 | + * @return array |
|
453 | + */ |
|
454 | + public static function wrap($value) |
|
455 | + { |
|
456 | + if (is_null($value)) |
|
457 | + { |
|
458 | + return []; |
|
459 | + } |
|
460 | + |
|
461 | + return is_array($value) ? $value : [$value]; |
|
462 | + } |
|
463 | 463 | } |
464 | 464 | \ No newline at end of file |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | { |
203 | 203 | $result = []; |
204 | 204 | |
205 | - array_walk_recursive($array, function ($value) use (&$result) { |
|
205 | + array_walk_recursive($array, function($value) use (&$result) { |
|
206 | 206 | $result[] = $value; |
207 | 207 | }); |
208 | 208 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | $array[$key] = []; |
371 | 371 | } |
372 | 372 | |
373 | - $array =& $array[$key]; |
|
373 | + $array = & $array[$key]; |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | $array[array_shift($keys)] = $value; |
@@ -80,8 +80,7 @@ discard block |
||
80 | 80 | if ($values instanceof Collection) |
81 | 81 | { |
82 | 82 | $values = $values->all(); |
83 | - } |
|
84 | - elseif ( ! is_array($values)) |
|
83 | + } elseif ( ! is_array($values)) |
|
85 | 84 | { |
86 | 85 | continue; |
87 | 86 | } |
@@ -180,8 +179,7 @@ discard block |
||
180 | 179 | if (isset($array[$part]) && is_array($array[$part])) |
181 | 180 | { |
182 | 181 | $array = &$array[$key]; |
183 | - } |
|
184 | - else |
|
182 | + } else |
|
185 | 183 | { |
186 | 184 | continue 2; |
187 | 185 | } |
@@ -250,7 +248,9 @@ discard block |
||
250 | 248 | { |
251 | 249 | foreach ($array as $key => $value) |
252 | 250 | { |
253 | - if (call_user_func($callback, $key, $value)) return $value; |
|
251 | + if (call_user_func($callback, $key, $value)) { |
|
252 | + return $value; |
|
253 | + } |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | return value($default); |
@@ -282,8 +282,7 @@ discard block |
||
282 | 282 | if (static::access($array) && static::exists($array, $segm)) |
283 | 283 | { |
284 | 284 | $array = $array[$segm]; |
285 | - } |
|
286 | - else |
|
285 | + } else |
|
287 | 286 | { |
288 | 287 | return value($default); |
289 | 288 | } |
@@ -318,9 +317,13 @@ discard block |
||
318 | 317 | */ |
319 | 318 | public static function has($array, $key) |
320 | 319 | { |
321 | - if (empty($array) || is_null($key)) return false; |
|
320 | + if (empty($array) || is_null($key)) { |
|
321 | + return false; |
|
322 | + } |
|
322 | 323 | |
323 | - if (array_key_exists($key, $array)) return true; |
|
324 | + if (array_key_exists($key, $array)) { |
|
325 | + return true; |
|
326 | + } |
|
324 | 327 | |
325 | 328 | foreach (explode('.', $key) as $segment) |
326 | 329 | { |
@@ -392,8 +395,7 @@ discard block |
||
392 | 395 | if (func_num_args() == 2) |
393 | 396 | { |
394 | 397 | array_unshift($array, $value); |
395 | - } |
|
396 | - else |
|
398 | + } else |
|
397 | 399 | { |
398 | 400 | $array = [$key => $value] + $array; |
399 | 401 | } |
@@ -275,11 +275,11 @@ |
||
275 | 275 | return new static(array_combine($keys, $items)); |
276 | 276 | } |
277 | 277 | |
278 | - /** |
|
279 | - * Reset the keys of the collection. |
|
280 | - * |
|
281 | - * @return static |
|
282 | - */ |
|
278 | + /** |
|
279 | + * Reset the keys of the collection. |
|
280 | + * |
|
281 | + * @return static |
|
282 | + */ |
|
283 | 283 | public function keys() |
284 | 284 | { |
285 | 285 | return new static(array_keys($this->items)); |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | return array_search($value, $this->items, $strict); |
525 | 525 | } |
526 | 526 | |
527 | - foreach($this->items as $key => $item) |
|
527 | + foreach ($this->items as $key => $item) |
|
528 | 528 | { |
529 | 529 | if ($value($item, $key)) |
530 | 530 | { |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | { |
693 | 693 | return $items; |
694 | 694 | } |
695 | - elseif($items instanceof Arrayable) |
|
695 | + elseif ($items instanceof Arrayable) |
|
696 | 696 | { |
697 | 697 | return $items->toArray(); |
698 | 698 | } |
@@ -203,8 +203,7 @@ discard block |
||
203 | 203 | if (is_null($callback)) |
204 | 204 | { |
205 | 205 | return count($this->items) > 0 ? head($this->items) : null; |
206 | - } |
|
207 | - else |
|
206 | + } else |
|
208 | 207 | { |
209 | 208 | return Arr::first($this->items, $callback, $default); |
210 | 209 | } |
@@ -691,16 +690,13 @@ discard block |
||
691 | 690 | if (is_array($items)) |
692 | 691 | { |
693 | 692 | return $items; |
694 | - } |
|
695 | - elseif($items instanceof Arrayable) |
|
693 | + } elseif($items instanceof Arrayable) |
|
696 | 694 | { |
697 | 695 | return $items->toArray(); |
698 | - } |
|
699 | - elseif ($items instanceof Jsonable) |
|
696 | + } elseif ($items instanceof Jsonable) |
|
700 | 697 | { |
701 | 698 | return json_decode($items->toJson(), true); |
702 | - } |
|
703 | - elseif ($items instanceof Collection) |
|
699 | + } elseif ($items instanceof Collection) |
|
704 | 700 | { |
705 | 701 | return $items->all(); |
706 | 702 | } |
@@ -783,8 +779,7 @@ discard block |
||
783 | 779 | if (is_null($offset)) |
784 | 780 | { |
785 | 781 | $this->items[] = $value; |
786 | - } |
|
787 | - else |
|
782 | + } else |
|
788 | 783 | { |
789 | 784 | $this->items[$offset] = $value; |
790 | 785 | } |
@@ -31,66 +31,66 @@ |
||
31 | 31 | */ |
32 | 32 | class FileMimeType |
33 | 33 | { |
34 | - /** |
|
35 | - * Map of extensions to mime types. |
|
36 | - * |
|
37 | - * @var array $mimes |
|
38 | - */ |
|
39 | - public static $mimes = []; |
|
34 | + /** |
|
35 | + * Map of extensions to mime types. |
|
36 | + * |
|
37 | + * @var array $mimes |
|
38 | + */ |
|
39 | + public static $mimes = []; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor with an optional verification that the path is |
|
43 | - * really a mimes. |
|
44 | - * |
|
45 | - * @return mixed |
|
46 | - */ |
|
47 | - public function __construct() |
|
48 | - { |
|
49 | - static::$mimes = (array) require CON_PATH.'mimes.php'; |
|
50 | - } |
|
41 | + /** |
|
42 | + * Constructor with an optional verification that the path is |
|
43 | + * really a mimes. |
|
44 | + * |
|
45 | + * @return mixed |
|
46 | + */ |
|
47 | + public function __construct() |
|
48 | + { |
|
49 | + static::$mimes = (array) require CON_PATH.'mimes.php'; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Attempts to determine the best mime type for the given file extension. |
|
54 | - * |
|
55 | - * @param string $extension |
|
56 | - * |
|
57 | - * @return string|null The mime type found, or none if unable to determine |
|
58 | - */ |
|
59 | - public static function guessTypeFromExtension($extension) |
|
60 | - { |
|
61 | - $extension = trim(strtolower($extension), '. '); |
|
52 | + /** |
|
53 | + * Attempts to determine the best mime type for the given file extension. |
|
54 | + * |
|
55 | + * @param string $extension |
|
56 | + * |
|
57 | + * @return string|null The mime type found, or none if unable to determine |
|
58 | + */ |
|
59 | + public static function guessTypeFromExtension($extension) |
|
60 | + { |
|
61 | + $extension = trim(strtolower($extension), '. '); |
|
62 | 62 | |
63 | - if ( ! array_key_exists($extension, static::$mimes)) |
|
64 | - { |
|
65 | - return null; |
|
66 | - } |
|
63 | + if ( ! array_key_exists($extension, static::$mimes)) |
|
64 | + { |
|
65 | + return null; |
|
66 | + } |
|
67 | 67 | |
68 | - return is_array(static::$mimes[$extension]) ? static::$mimes[$extension][0] : static::$mimes[$extension]; |
|
69 | - } |
|
68 | + return is_array(static::$mimes[$extension]) ? static::$mimes[$extension][0] : static::$mimes[$extension]; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Attempts to determine the best file extension for a given mime type. |
|
73 | - * |
|
74 | - * @param string $type |
|
75 | - * |
|
76 | - * @return string|null The extension determined, or null if unable to match |
|
77 | - */ |
|
78 | - public static function guessExtensionFromType($type) |
|
79 | - { |
|
80 | - $type = trim(strtolower($type), '. '); |
|
71 | + /** |
|
72 | + * Attempts to determine the best file extension for a given mime type. |
|
73 | + * |
|
74 | + * @param string $type |
|
75 | + * |
|
76 | + * @return string|null The extension determined, or null if unable to match |
|
77 | + */ |
|
78 | + public static function guessExtensionFromType($type) |
|
79 | + { |
|
80 | + $type = trim(strtolower($type), '. '); |
|
81 | 81 | |
82 | - foreach (static::$mimes as $ext => $types) |
|
83 | - { |
|
84 | - if (is_string($types) && $types == $type) |
|
85 | - { |
|
86 | - return $ext; |
|
87 | - } |
|
88 | - else if (is_array($types) && in_array($type, $types)) |
|
89 | - { |
|
90 | - return $ext; |
|
91 | - } |
|
92 | - } |
|
82 | + foreach (static::$mimes as $ext => $types) |
|
83 | + { |
|
84 | + if (is_string($types) && $types == $type) |
|
85 | + { |
|
86 | + return $ext; |
|
87 | + } |
|
88 | + else if (is_array($types) && in_array($type, $types)) |
|
89 | + { |
|
90 | + return $ext; |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - return null; |
|
95 | - } |
|
94 | + return null; |
|
95 | + } |
|
96 | 96 | } |
97 | 97 | \ No newline at end of file |
@@ -84,8 +84,7 @@ |
||
84 | 84 | if (is_string($types) && $types == $type) |
85 | 85 | { |
86 | 86 | return $ext; |
87 | - } |
|
88 | - else if (is_array($types) && in_array($type, $types)) |
|
87 | + } else if (is_array($types) && in_array($type, $types)) |
|
89 | 88 | { |
90 | 89 | return $ext; |
91 | 90 | } |