Passed
Push — 0.7.0 ( f20096...1a66e7 )
by Alexander
03:34 queued 10s
created
src/components/Debug/GDebug.php 3 patches
Indentation   +387 added lines, -387 removed lines patch added patch discarded remove patch
@@ -41,406 +41,406 @@
 block discarded – undo
41 41
  */
42 42
 class GDebug implements DebugContract
43 43
 {
44
-	/**
45
-	 * Allow Handlers to force the script to quit.
46
-	 * 
47
-	 * @var bool $allowQuit
48
-	 */
49
-	protected $allowQuit = true;
44
+    /**
45
+     * Allow Handlers to force the script to quit.
46
+     * 
47
+     * @var bool $allowQuit
48
+     */
49
+    protected $allowQuit = true;
50 50
 	
51
-	/**
52
-	 * Benchmark instance.
53
-	 * 
54
-	 * @var string $benchmark
55
-	 */
56
-	protected $benchmark;
57
-
58
-	/**
59
-	 * The handler stack.
60
-	 * 
61
-	 * @var array $handlerStack
62
-	 */
63
-	protected $handlerStack = [];
64
-
65
-	/**
66
-	 * The send Http code by default: 500 Internal Server Error.
67
-	 * 
68
-	 * @var bool $sendHttpCode
69
-	 */
70
-	protected $sendHttpCode = 500;
71
-
72
-	/**
73
-	 * The send output.
74
-	 * 
75
-	 * @var bool $sendOutput
76
-	 */
77
-	protected $sendOutput = true;
78
-
79
-	/**
80
-	 * The functions of system what control errors and exceptions.
81
-	 * 
82
-	 * @var string $system
83
-	 */
84
-	protected $system;
85
-
86
-	/**
87
-	 * In certain scenarios, like in shutdown handler, we can not throw exceptions.
88
-	 * 
89
-	 * @var bool $throwExceptions
90
-	 */
91
-	protected $throwExceptions = true;
92
-
93
-	/**
94
-	 * Constructor. The Debug class instance.
95
-	 * 
96
-	 * @param  \Syscodes\Debug\Util\System|null  $system
97
-	 * 
98
-	 * @return void
99
-	 */
100
-	public function __construct(System $system = null)
101
-	{
102
-		$this->system    = $system ?: new System;
103
-		$this->benchmark = new Benchmark;
104
-	}
105
-
106
-	/**
107
-	 * Catches any uncaught errors and exceptions, including most Fatal errors. Will log the 
108
-	 * error, display it if display_errors is on, and fire an event that allows custom actions 
109
-	 * to be taken at this point.
110
-	 *
111
-	 * @param  \Throwable  $exception
112
-	 *
113
-	 * @return string
114
-	 */
115
-	public function handleException(Throwable $exception)
116
-	{	
117
-		// The start benchmark
118
-		$this->benchmark->start('total_execution', LENEVOR_START);
119
-
120
-		$supervisor = $this->getSupervisor($exception);
121
-
122
-		// Start buffer
123
-		$this->system->startOutputBuferring();
124
-
125
-		$handlerResponse    = null;
126
-		$handlerContentType = null;
51
+    /**
52
+     * Benchmark instance.
53
+     * 
54
+     * @var string $benchmark
55
+     */
56
+    protected $benchmark;
57
+
58
+    /**
59
+     * The handler stack.
60
+     * 
61
+     * @var array $handlerStack
62
+     */
63
+    protected $handlerStack = [];
64
+
65
+    /**
66
+     * The send Http code by default: 500 Internal Server Error.
67
+     * 
68
+     * @var bool $sendHttpCode
69
+     */
70
+    protected $sendHttpCode = 500;
71
+
72
+    /**
73
+     * The send output.
74
+     * 
75
+     * @var bool $sendOutput
76
+     */
77
+    protected $sendOutput = true;
78
+
79
+    /**
80
+     * The functions of system what control errors and exceptions.
81
+     * 
82
+     * @var string $system
83
+     */
84
+    protected $system;
85
+
86
+    /**
87
+     * In certain scenarios, like in shutdown handler, we can not throw exceptions.
88
+     * 
89
+     * @var bool $throwExceptions
90
+     */
91
+    protected $throwExceptions = true;
92
+
93
+    /**
94
+     * Constructor. The Debug class instance.
95
+     * 
96
+     * @param  \Syscodes\Debug\Util\System|null  $system
97
+     * 
98
+     * @return void
99
+     */
100
+    public function __construct(System $system = null)
101
+    {
102
+        $this->system    = $system ?: new System;
103
+        $this->benchmark = new Benchmark;
104
+    }
105
+
106
+    /**
107
+     * Catches any uncaught errors and exceptions, including most Fatal errors. Will log the 
108
+     * error, display it if display_errors is on, and fire an event that allows custom actions 
109
+     * to be taken at this point.
110
+     *
111
+     * @param  \Throwable  $exception
112
+     *
113
+     * @return string
114
+     */
115
+    public function handleException(Throwable $exception)
116
+    {	
117
+        // The start benchmark
118
+        $this->benchmark->start('total_execution', LENEVOR_START);
119
+
120
+        $supervisor = $this->getSupervisor($exception);
121
+
122
+        // Start buffer
123
+        $this->system->startOutputBuferring();
124
+
125
+        $handlerResponse    = null;
126
+        $handlerContentType = null;
127 127
 		
128
-		try {
129
-			foreach ($this->handlerStack as $handler) {			
130
-				$handler->setDebug($this);
131
-				$handler->setException($exception);
132
-				$handler->setSupervisor($supervisor);
128
+        try {
129
+            foreach ($this->handlerStack as $handler) {			
130
+                $handler->setDebug($this);
131
+                $handler->setException($exception);
132
+                $handler->setSupervisor($supervisor);
133 133
 				
134
-				$handlerResponse = $handler->handle();
134
+                $handlerResponse = $handler->handle();
135 135
 	
136
-				// Collect the content type for possible sending in the headers
137
-				$handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null;
136
+                // Collect the content type for possible sending in the headers
137
+                $handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null;
138 138
 	
139
-				if (in_array($handlerResponse, [MainHandler::LAST_HANDLER, MainHandler::QUIT])) {
140
-					break;
141
-				}
142
-			}
139
+                if (in_array($handlerResponse, [MainHandler::LAST_HANDLER, MainHandler::QUIT])) {
140
+                    break;
141
+                }
142
+            }
143 143
 	
144
-			$Quit = $handlerResponse == MainHandler::QUIT && $this->allowQuit();
145
-		}
146
-		finally {
147
-			// Returns the contents of the output buffer
148
-			$output = $this->system->CleanOutputBuffer();	
149
-		}
150
-
151
-		// Returns the contents of the output buffer for loading time of page
152
-		$totalTime = $this->benchmark->getElapsedTime('total_execution');
153
-		$output    = str_replace('{elapsed_time}', $totalTime, $output);
154
-
155
-		if ($this->writeToOutput()) {
156
-			if ($Quit) {
157
-				while ($this->system->getOutputBufferLevel() > 0) {
158
-					// Cleanes the output buffer
159
-					$this->system->endOutputBuffering();
160
-				}
161
-
162
-				if (Misc::sendHeaders() && $handlerContentType)	{
163
-					header("Content-Type: {$handlerContentType}");
164
-				}
165
-			}
166
-
167
-			$this->writeToOutputBuffer($output);
168
-		}
169
-
170
-		if ($Quit) {
171
-			$this->system->flushOutputBuffer();
172
-			$this->system->stopException(1);
173
-		}
174
-
175
-		return $output;
176
-	}
177
-
178
-	/**
179
-	 * Allow Handlers to force the script to quit.
180
-	 * 
181
-	 * @param  bool|int  $exit
182
-	 * 
183
-	 * @return bool
184
-	 */
185
-	public function allowQuit($exit = null)
186
-	{
187
-		if (func_num_args() == 0) {
188
-			return $this->allowQuit;
189
-		}
190
-
191
-		return $this->allowQuit = (bool) $exit;
192
-	}
193
-
194
-	/**
195
-	 * Lenevor Exception push output directly to the client it the data  
196
-	 * if they are true, but if it is false, the output will be returned 
197
-	 * by exception.
198
-	 * 
199
-	 * @param  bool|int  $send
200
-	 *
201
-	 * @return bool
202
-	 */
203
-	public function writeToOutput($send = null)
204
-	{
205
-		if (func_num_args() == 0) {
206
-			return $this->sendOutput;
207
-		}
144
+            $Quit = $handlerResponse == MainHandler::QUIT && $this->allowQuit();
145
+        }
146
+        finally {
147
+            // Returns the contents of the output buffer
148
+            $output = $this->system->CleanOutputBuffer();	
149
+        }
150
+
151
+        // Returns the contents of the output buffer for loading time of page
152
+        $totalTime = $this->benchmark->getElapsedTime('total_execution');
153
+        $output    = str_replace('{elapsed_time}', $totalTime, $output);
154
+
155
+        if ($this->writeToOutput()) {
156
+            if ($Quit) {
157
+                while ($this->system->getOutputBufferLevel() > 0) {
158
+                    // Cleanes the output buffer
159
+                    $this->system->endOutputBuffering();
160
+                }
161
+
162
+                if (Misc::sendHeaders() && $handlerContentType)	{
163
+                    header("Content-Type: {$handlerContentType}");
164
+                }
165
+            }
166
+
167
+            $this->writeToOutputBuffer($output);
168
+        }
169
+
170
+        if ($Quit) {
171
+            $this->system->flushOutputBuffer();
172
+            $this->system->stopException(1);
173
+        }
174
+
175
+        return $output;
176
+    }
177
+
178
+    /**
179
+     * Allow Handlers to force the script to quit.
180
+     * 
181
+     * @param  bool|int  $exit
182
+     * 
183
+     * @return bool
184
+     */
185
+    public function allowQuit($exit = null)
186
+    {
187
+        if (func_num_args() == 0) {
188
+            return $this->allowQuit;
189
+        }
190
+
191
+        return $this->allowQuit = (bool) $exit;
192
+    }
193
+
194
+    /**
195
+     * Lenevor Exception push output directly to the client it the data  
196
+     * if they are true, but if it is false, the output will be returned 
197
+     * by exception.
198
+     * 
199
+     * @param  bool|int  $send
200
+     *
201
+     * @return bool
202
+     */
203
+    public function writeToOutput($send = null)
204
+    {
205
+        if (func_num_args() == 0) {
206
+            return $this->sendOutput;
207
+        }
208 208
 		
209
-		return $this->sendOutput = (bool) $send;
210
-	}
209
+        return $this->sendOutput = (bool) $send;
210
+    }
211 211
 	
212
-	/**
213
-	 * Generate output to the browser.
214
-	 * 
215
-	 * @param  string  $output
216
-	 * 
217
-	 * @return $this
218
-	 */
219
-	protected function writeToOutputBuffer($output)
220
-	{
221
-		if ($this->sendHttpCode() && Misc::sendHeaders()) {
222
-			$this->system->setHttpResponseCode($this->sendHttpCode());
223
-		}
212
+    /**
213
+     * Generate output to the browser.
214
+     * 
215
+     * @param  string  $output
216
+     * 
217
+     * @return $this
218
+     */
219
+    protected function writeToOutputBuffer($output)
220
+    {
221
+        if ($this->sendHttpCode() && Misc::sendHeaders()) {
222
+            $this->system->setHttpResponseCode($this->sendHttpCode());
223
+        }
224 224
 		
225
-		echo $output;
225
+        echo $output;
226 226
 		
227
-		return $this;
228
-	}
229
-
230
-	/**
231
-	 * Error handler
232
-	 *
233
-	 * This will catch the php native error and treat it as a exception which will 
234
-	 * provide a full back trace on all errors.
235
-	 *
236
-	 * @param  int  $level
237
-	 * @param  string  $message
238
-	 * @param  string|null  $file
239
-	 * @param  int|null  $line
240
-	 *
241
-	 * @throws \ErrorException
242
-	 */
243
-	public function handleError(int $level, string $message, string $file = null, int $line = null)
244
-	{
245
-		if ($level & $this->system->getErrorReportingLevel()) {
246
-			$exception = new ErrorException($message, $level, $level, $file, $line);
247
-
248
-			if ($this->throwExceptions) {
249
-				throw $exception;
250
-			} else {
251
-				$this->handleException($exception);
252
-			}
253
-
254
-			return true;
255
-		}
256
-
257
-		return false;
258
-	}
259
-
260
-	/**
261
-	 * Pushes a handler to the end of the stack.
262
-	 * 
263
-	 * @param  \Callable|\Syscodes\Contracts\Debug\Handler  $handler
264
-	 * 
265
-	 * @return \Syscodes\Contracts\Debug\Handler
266
-	 */
267
-	public function pushHandler($handler)
268
-	{
269
-		return $this->prependHandler($handler);
270
-	}
271
-
272
-	/**
273
-	 * Appends a handler to the end of the stack.
274
-	 * 
275
-	 * @param  \Callable|\Syscodes\Contracts\Debug\Handler  $handler
276
-	 * 
277
-	 * @return $this
278
-	 */
279
-	public function appendHandler($handler)
280
-	{
281
-		array_unshift($this->handlerStack, $this->resolveHandler($handler));
282
-
283
-		return $this;
284
-	}
285
-
286
-	/**
287
-	 * Prepends a handler to the start of the stack.
288
-	 * 
289
-	 * @param  \Callable|\Syscodes\Contracts\Debug\Handler  $handler
290
-	 * 
291
-	 * @return $this
292
-	 */
293
-	public function prependHandler($handler)
294
-	{
295
-		array_unshift($this->handlerStack, $this->resolveHandler($handler));
296
-
297
-		return $this;
298
-	}
299
-
300
-	/**
301
-	 * Create a CallbackHandler from callable and throw if handler is invalid.
302
-	 * 
303
-	 * @param  \Callable|\Syscodes\Contracts\Debug\Handler  $handler
304
-	 * 
305
-	 * @return \Syscodes\Contracts\Debug\Handler
306
-	 * 
307
-	 * @throws \InvalidArgumentException If argument is not callable or instance of \Syscodes\Contracts\Debug\Handler
308
-	 */
309
-	protected function resolveHandler($handler)
310
-	{
311
-		if (is_callable($handler)) {
312
-			$handler = new CallbackHandler($handler);
313
-		}
314
-
315
-		if ( ! $handler instanceof MainHandler) {
316
-			throw new InvalidArgumentException(
317
-				"Argument to " . __METHOD__ . " must be a callable, or instance of ".
318
-				"Syscodes\\Contracts\\Debug\\Handler"
319
-			);
320
-		}
321
-
322
-		return $handler;
323
-	}
324
-
325
-	/**
326
-	 * Returns an array with all handlers, in the order they were added to the stack.
327
-	 * 
328
-	 * @return array
329
-	 */
330
-	public function getHandlers()
331
-	{
332
-		return $this->handlerStack;
333
-	}
334
-
335
-	/**
336
-	 * Clears all handlers in the handlerStack, including the default PleasingPage handler.
337
-	 * 
338
-	 * @return $this
339
-	 */
340
-	public function clearHandlers()
341
-	{
342
-		$this->handlerStack = [];
343
-
344
-		return $this;
345
-	}
346
-
347
-	/**
348
-	 * Removes the last handler in the stack and returns it.
349
-	 * 
350
-	 * @return array|null
351
-	 */
352
-	public function popHandler()
353
-	{
354
-		return array_pop($this->handlerStack);
355
-	}
356
-
357
-	/**
358
-	 * Gets supervisor already specified.
359
-	 * 
360
-	 * @param  \Throwable  $exception
361
-	 * 
362
-	 * @return \Syscodes\Debug\Engine\Supervisor
363
-	 */
364
-	protected function getSupervisor(Throwable $exception)
365
-	{
366
-		return new Supervisor($exception);
367
-	}
368
-
369
-	/**
370
-	 * Unregisters all handlers registered by this Debug instance.
371
-	 * 
372
-	 * @return void
373
-	 */
374
-	public function off()
375
-	{
376
-		$this->system->restoreExceptionHandler();
377
-		$this->system->restoreErrorHandler();
378
-	}
227
+        return $this;
228
+    }
229
+
230
+    /**
231
+     * Error handler
232
+     *
233
+     * This will catch the php native error and treat it as a exception which will 
234
+     * provide a full back trace on all errors.
235
+     *
236
+     * @param  int  $level
237
+     * @param  string  $message
238
+     * @param  string|null  $file
239
+     * @param  int|null  $line
240
+     *
241
+     * @throws \ErrorException
242
+     */
243
+    public function handleError(int $level, string $message, string $file = null, int $line = null)
244
+    {
245
+        if ($level & $this->system->getErrorReportingLevel()) {
246
+            $exception = new ErrorException($message, $level, $level, $file, $line);
247
+
248
+            if ($this->throwExceptions) {
249
+                throw $exception;
250
+            } else {
251
+                $this->handleException($exception);
252
+            }
253
+
254
+            return true;
255
+        }
256
+
257
+        return false;
258
+    }
259
+
260
+    /**
261
+     * Pushes a handler to the end of the stack.
262
+     * 
263
+     * @param  \Callable|\Syscodes\Contracts\Debug\Handler  $handler
264
+     * 
265
+     * @return \Syscodes\Contracts\Debug\Handler
266
+     */
267
+    public function pushHandler($handler)
268
+    {
269
+        return $this->prependHandler($handler);
270
+    }
271
+
272
+    /**
273
+     * Appends a handler to the end of the stack.
274
+     * 
275
+     * @param  \Callable|\Syscodes\Contracts\Debug\Handler  $handler
276
+     * 
277
+     * @return $this
278
+     */
279
+    public function appendHandler($handler)
280
+    {
281
+        array_unshift($this->handlerStack, $this->resolveHandler($handler));
282
+
283
+        return $this;
284
+    }
285
+
286
+    /**
287
+     * Prepends a handler to the start of the stack.
288
+     * 
289
+     * @param  \Callable|\Syscodes\Contracts\Debug\Handler  $handler
290
+     * 
291
+     * @return $this
292
+     */
293
+    public function prependHandler($handler)
294
+    {
295
+        array_unshift($this->handlerStack, $this->resolveHandler($handler));
296
+
297
+        return $this;
298
+    }
299
+
300
+    /**
301
+     * Create a CallbackHandler from callable and throw if handler is invalid.
302
+     * 
303
+     * @param  \Callable|\Syscodes\Contracts\Debug\Handler  $handler
304
+     * 
305
+     * @return \Syscodes\Contracts\Debug\Handler
306
+     * 
307
+     * @throws \InvalidArgumentException If argument is not callable or instance of \Syscodes\Contracts\Debug\Handler
308
+     */
309
+    protected function resolveHandler($handler)
310
+    {
311
+        if (is_callable($handler)) {
312
+            $handler = new CallbackHandler($handler);
313
+        }
314
+
315
+        if ( ! $handler instanceof MainHandler) {
316
+            throw new InvalidArgumentException(
317
+                "Argument to " . __METHOD__ . " must be a callable, or instance of ".
318
+                "Syscodes\\Contracts\\Debug\\Handler"
319
+            );
320
+        }
321
+
322
+        return $handler;
323
+    }
324
+
325
+    /**
326
+     * Returns an array with all handlers, in the order they were added to the stack.
327
+     * 
328
+     * @return array
329
+     */
330
+    public function getHandlers()
331
+    {
332
+        return $this->handlerStack;
333
+    }
334
+
335
+    /**
336
+     * Clears all handlers in the handlerStack, including the default PleasingPage handler.
337
+     * 
338
+     * @return $this
339
+     */
340
+    public function clearHandlers()
341
+    {
342
+        $this->handlerStack = [];
343
+
344
+        return $this;
345
+    }
346
+
347
+    /**
348
+     * Removes the last handler in the stack and returns it.
349
+     * 
350
+     * @return array|null
351
+     */
352
+    public function popHandler()
353
+    {
354
+        return array_pop($this->handlerStack);
355
+    }
356
+
357
+    /**
358
+     * Gets supervisor already specified.
359
+     * 
360
+     * @param  \Throwable  $exception
361
+     * 
362
+     * @return \Syscodes\Debug\Engine\Supervisor
363
+     */
364
+    protected function getSupervisor(Throwable $exception)
365
+    {
366
+        return new Supervisor($exception);
367
+    }
368
+
369
+    /**
370
+     * Unregisters all handlers registered by this Debug instance.
371
+     * 
372
+     * @return void
373
+     */
374
+    public function off()
375
+    {
376
+        $this->system->restoreExceptionHandler();
377
+        $this->system->restoreErrorHandler();
378
+    }
379 379
 	
380
-	/**
381
-	 * Registers this instance as an error handler.
382
-	 * 
383
-	 * @return void
384
-	 */
385
-	public function on() 
386
-	{
387
-		// Set the exception handler
388
-		$this->system->setExceptionHandler([$this, self::EXCEPTION_HANDLER]);
389
-		// Set the error handler
390
-		$this->system->setErrorHandler([$this, self::ERROR_HANDLER]);
391
-		// Set the handler for shutdown to catch Parse errors
392
-		$this->system->registerShutdownFunction([$this, self::SHUTDOWN_HANDLER]);
393
-	}
394
-
395
-	/**
396
-	 * Lenevor Exception will by default send HTTP code 500, but you may wish
397
-	 * to use 502, 503, or another 5xx family code.
398
-	 * 
399
-	 * @param  bool|int  $code
400
-	 * 
401
-	 * @return int|false
402
-	 * 
403
-	 * @throws \InvalidArgumentException
404
-	 */
405
-	public function sendHttpCode($code = null)
406
-	{
407
-		if (func_num_args() == 0) {
408
-			return $this->sendHttpCode;
409
-		}
380
+    /**
381
+     * Registers this instance as an error handler.
382
+     * 
383
+     * @return void
384
+     */
385
+    public function on() 
386
+    {
387
+        // Set the exception handler
388
+        $this->system->setExceptionHandler([$this, self::EXCEPTION_HANDLER]);
389
+        // Set the error handler
390
+        $this->system->setErrorHandler([$this, self::ERROR_HANDLER]);
391
+        // Set the handler for shutdown to catch Parse errors
392
+        $this->system->registerShutdownFunction([$this, self::SHUTDOWN_HANDLER]);
393
+    }
394
+
395
+    /**
396
+     * Lenevor Exception will by default send HTTP code 500, but you may wish
397
+     * to use 502, 503, or another 5xx family code.
398
+     * 
399
+     * @param  bool|int  $code
400
+     * 
401
+     * @return int|false
402
+     * 
403
+     * @throws \InvalidArgumentException
404
+     */
405
+    public function sendHttpCode($code = null)
406
+    {
407
+        if (func_num_args() == 0) {
408
+            return $this->sendHttpCode;
409
+        }
410 410
 		
411
-		if ( ! $code) {
412
-			return $this->sendHttpCode = false;
413
-		}
411
+        if ( ! $code) {
412
+            return $this->sendHttpCode = false;
413
+        }
414 414
 		
415
-		if ($code === true) {
416
-			$code = 500;
417
-		}
415
+        if ($code === true) {
416
+            $code = 500;
417
+        }
418 418
 		
419
-		if ($code < 400 || 600 <= $code) {
420
-			throw new InvalidArgumentException("Invalid status code {$code}, must be 4xx or 5xx");
421
-		}
419
+        if ($code < 400 || 600 <= $code) {
420
+            throw new InvalidArgumentException("Invalid status code {$code}, must be 4xx or 5xx");
421
+        }
422 422
 		
423
-		return $this->sendHttpCode = $code;
424
-	}
425
-
426
-	/**
427
-	 * This will catch errors that are generated at the shutdown level of execution.
428
-	 *
429
-	 * @return void
430
-	 *
431
-	 * @throws \ErrorException
432
-	 */
433
-	public function handleShutdown()
434
-	{
435
-		$this->throwExceptions = false;
436
-
437
-		$error = $this->system->getLastError();
438
-
439
-		// If we've got an error that hasn't been displayed, then convert
440
-		// it to an Exception and use the Exception handler to display it
441
-		// to the user
442
-		if ($error && Misc::isFatalError($error['type'])) {
443
-			$this->errorHandler($error['type'], $error['message'], $error['file'], $error['line']);
444
-		}
445
-	}
423
+        return $this->sendHttpCode = $code;
424
+    }
425
+
426
+    /**
427
+     * This will catch errors that are generated at the shutdown level of execution.
428
+     *
429
+     * @return void
430
+     *
431
+     * @throws \ErrorException
432
+     */
433
+    public function handleShutdown()
434
+    {
435
+        $this->throwExceptions = false;
436
+
437
+        $error = $this->system->getLastError();
438
+
439
+        // If we've got an error that hasn't been displayed, then convert
440
+        // it to an Exception and use the Exception handler to display it
441
+        // to the user
442
+        if ($error && Misc::isFatalError($error['type'])) {
443
+            $this->errorHandler($error['type'], $error['message'], $error['file'], $error['line']);
444
+        }
445
+    }
446 446
 }
447 447
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 					$this->system->endOutputBuffering();
160 160
 				}
161 161
 
162
-				if (Misc::sendHeaders() && $handlerContentType)	{
162
+				if (Misc::sendHeaders() && $handlerContentType) {
163 163
 					header("Content-Type: {$handlerContentType}");
164 164
 				}
165 165
 			}
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 
315 315
 		if ( ! $handler instanceof MainHandler) {
316 316
 			throw new InvalidArgumentException(
317
-				"Argument to " . __METHOD__ . " must be a callable, or instance of ".
317
+				"Argument to ".__METHOD__." must be a callable, or instance of ".
318 318
 				"Syscodes\\Contracts\\Debug\\Handler"
319 319
 			);
320 320
 		}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -142,8 +142,7 @@
 block discarded – undo
142 142
 			}
143 143
 	
144 144
 			$Quit = $handlerResponse == MainHandler::QUIT && $this->allowQuit();
145
-		}
146
-		finally {
145
+		} finally {
147 146
 			// Returns the contents of the output buffer
148 147
 			$output = $this->system->CleanOutputBuffer();	
149 148
 		}
Please login to merge, or discard this patch.
src/components/Debug/ExceptionHandler.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 
160 160
         $caughtLength = $this->caughtLength = 0;
161 161
 
162
-        ob_start(function ($buffer) {
162
+        ob_start(function($buffer) {
163 163
             $this->caughtBuffer = $buffer;
164 164
 
165 165
             return '';            
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
         $this->sendPhpResponse($exception);
169 169
 
170 170
         if (isset($this->caughtBuffer[0])) {
171
-            ob_start(function ($buffer) {
171
+            ob_start(function($buffer) {
172 172
                 if ($this->caughtLength) {
173 173
                     $cleanBuffer = substr_replace($buffer, '', 0, $this->caughtLength);
174 174
 
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
         }
459 459
 
460 460
         if (is_string($frmt)) {
461
-            $index  = strpos($f = $frmt, '&', max(strrpos($f, '%f'), strrpos($f, '%l')) ?: strlen($f));
461
+            $index = strpos($f = $frmt, '&', max(strrpos($f, '%f'), strrpos($f, '%l')) ?: strlen($f));
462 462
             $frmt = [substr($f, 0, $index)] + preg_split('/&([^>]++)>/', substr($f, $index), -1, PREG_SPLIT_DELIM_CAPTURE);
463 463
 
464 464
             for ($index = 1; isset($frmt[$index]); ++$index) {
Please login to merge, or discard this patch.
src/components/Debug/Exceptions/Handlers/PleasingPageHandler.php 3 patches
Indentation   +407 added lines, -407 removed lines patch added patch discarded remove patch
@@ -41,429 +41,429 @@
 block discarded – undo
41 41
  */
42 42
 class PleasingPageHandler extends MainHandler
43 43
 {
44
-	/**
45
-	 * The brand main of handler.
46
-	 * 
47
-	 * @var string $brand
48
-	 */
49
-	protected $brand = 'Lenevor Debug';
50
-
51
-	/**
52
-	 * A string identifier for a known IDE/text editor, or a closure
53
-	 * that resolves a string that can be used to open a given file
54
-	 * in an editor.
55
-	 * 
56
-	 * @var mixed $editor
57
-	 */
58
-	protected $editor;
59
-
60
-	/**
61
-	 * A list of known editor strings.
62
-	 * 
63
-	 * @var array $editors
64
-	 */
65
-	protected $editors = [
66
-		"vscode"   => "vscode://file/%file:%line",
67
-		"sublime"  => "subl://open?url=file://%file&line=%line",
68
-		"phpstorm" => "phpstorm://open?file://%file&line=%line",
69
-		"textmate" => "txmt://open?url=file://%file&line=%line",
70
-		"atom"     => "atom://core/open/file?filename=%file&line=%line",
71
-	];
44
+    /**
45
+     * The brand main of handler.
46
+     * 
47
+     * @var string $brand
48
+     */
49
+    protected $brand = 'Lenevor Debug';
50
+
51
+    /**
52
+     * A string identifier for a known IDE/text editor, or a closure
53
+     * that resolves a string that can be used to open a given file
54
+     * in an editor.
55
+     * 
56
+     * @var mixed $editor
57
+     */
58
+    protected $editor;
59
+
60
+    /**
61
+     * A list of known editor strings.
62
+     * 
63
+     * @var array $editors
64
+     */
65
+    protected $editors = [
66
+        "vscode"   => "vscode://file/%file:%line",
67
+        "sublime"  => "subl://open?url=file://%file&line=%line",
68
+        "phpstorm" => "phpstorm://open?file://%file&line=%line",
69
+        "textmate" => "txmt://open?url=file://%file&line=%line",
70
+        "atom"     => "atom://core/open/file?filename=%file&line=%line",
71
+    ];
72 72
 	
73
-	/**
74
-	 * The page title main of handler.
75
-	 * 
76
-	 * @var string $pageTitle
77
-	 */
78
-	protected $pageTitle = 'Lenevor Debug! There was an error.';
73
+    /**
74
+     * The page title main of handler.
75
+     * 
76
+     * @var string $pageTitle
77
+     */
78
+    protected $pageTitle = 'Lenevor Debug! There was an error.';
79 79
 	
80
-	/**
81
-	 * Fast lookup cache for known resource locations.
82
-	 * 
83
-	 * @var array $resourceCache
84
-	 */
85
-	protected $resourceCache = [];
80
+    /**
81
+     * Fast lookup cache for known resource locations.
82
+     * 
83
+     * @var array $resourceCache
84
+     */
85
+    protected $resourceCache = [];
86 86
 	
87
-	/**
88
-	 * The path to the directory containing the html error template directories.
89
-	 * 
90
-	 * @var array $searchPaths
91
-	 */
92
-	protected $searchPaths = [];
93
-
94
-	/**
95
-	 * Gets the table of data.
96
-	 * 
97
-	 * @var array $tables
98
-	 */
99
-	protected $tables = [];
87
+    /**
88
+     * The path to the directory containing the html error template directories.
89
+     * 
90
+     * @var array $searchPaths
91
+     */
92
+    protected $searchPaths = [];
93
+
94
+    /**
95
+     * Gets the table of data.
96
+     * 
97
+     * @var array $tables
98
+     */
99
+    protected $tables = [];
100 100
 	
101
-	/**
102
-	 * The template handler system.
103
-	 * 
104
-	 * @var string $template
105
-	 */
106
-	protected $template;	
101
+    /**
102
+     * The template handler system.
103
+     * 
104
+     * @var string $template
105
+     */
106
+    protected $template;	
107 107
 	
108
-	/**
109
-	 * Constructor. The PleasingPageHandler class.
110
-	 * 
111
-	 * @return void
112
-	 */
113
-	public function __construct()
114
-	{
115
-		$this->template      = new TemplateHandler;
116
-		$this->searchPaths[] = dirname(__DIR__).DIRECTORY_SEPARATOR.'Resources';
117
-	}
118
-
119
-	/**
120
-	 * Adds an editor resolver, identified by a string name, and that may be a 
121
-	 * string path, or a callable resolver.
122
-	 * 
123
-	 * @param  string            $identifier
124
-	 * @param  string|\Callable  $resolver
125
-	 * 
126
-	 * @return void
127
-	 */
128
-	public function addEditor($identifier, $resolver)
129
-	{
130
-		$this->editors[$identifier] = $resolver;
131
-	}
132
-
133
-	/**
134
-	 * Adds an entry to the list of tables displayed in the template.
135
-	 * The expected data is a simple associative array. Any nested arrays
136
-	 * will be flattened with print_r.
137
-	 * 
138
-	 * @param  \Syscodes\Contracts\Debug\Table  $table
139
-	 * 
140
-	 * @return array
141
-	 */
142
-	public function addTables(Table $table)
143
-	{
144
-		$this->tables[] = $table;
145
-	}
108
+    /**
109
+     * Constructor. The PleasingPageHandler class.
110
+     * 
111
+     * @return void
112
+     */
113
+    public function __construct()
114
+    {
115
+        $this->template      = new TemplateHandler;
116
+        $this->searchPaths[] = dirname(__DIR__).DIRECTORY_SEPARATOR.'Resources';
117
+    }
118
+
119
+    /**
120
+     * Adds an editor resolver, identified by a string name, and that may be a 
121
+     * string path, or a callable resolver.
122
+     * 
123
+     * @param  string            $identifier
124
+     * @param  string|\Callable  $resolver
125
+     * 
126
+     * @return void
127
+     */
128
+    public function addEditor($identifier, $resolver)
129
+    {
130
+        $this->editors[$identifier] = $resolver;
131
+    }
132
+
133
+    /**
134
+     * Adds an entry to the list of tables displayed in the template.
135
+     * The expected data is a simple associative array. Any nested arrays
136
+     * will be flattened with print_r.
137
+     * 
138
+     * @param  \Syscodes\Contracts\Debug\Table  $table
139
+     * 
140
+     * @return array
141
+     */
142
+    public function addTables(Table $table)
143
+    {
144
+        $this->tables[] = $table;
145
+    }
146 146
 	
147
-	/**
148
-	 * Gathers the variables that will be made available to the view.
149
-	 * 
150
-	 * @return  array
151
-	 */
152
-	protected function collectionVars()
153
-	{
154
-		$supervisor = $this->getSupervisor();
155
-		$style      = file_get_contents($this->getResource('css/debug.base.css'));
156
-		$jscript    = file_get_contents($this->getResource('js/debug.base.js'));
157
-		$tables     = array_merge($this->getDefaultTables(), $this->tables);
147
+    /**
148
+     * Gathers the variables that will be made available to the view.
149
+     * 
150
+     * @return  array
151
+     */
152
+    protected function collectionVars()
153
+    {
154
+        $supervisor = $this->getSupervisor();
155
+        $style      = file_get_contents($this->getResource('css/debug.base.css'));
156
+        $jscript    = file_get_contents($this->getResource('js/debug.base.js'));
157
+        $tables     = array_merge($this->getDefaultTables(), $this->tables);
158 158
 		
159
-		return [ 
160
-			'class'             => explode('\\', $supervisor->getExceptionName()),
161
-			'stylesheet'        => preg_replace('#[\r\n\t ]+#', ' ', $style),
162
-			'javascript'        => preg_replace('#[\r\n\t ]+#', ' ', $jscript),
163
-			'header'            => $this->getResource('views/header.php'),
164
-			'sidebar'           => $this->getResource('views/sidebar.php'),
165
-			'frame_description' => $this->getResource('views/frame_description.php'),
166
-			'frame_list'        => $this->getResource('views/frame_list.php'),
167
-			'details_panel'     => $this->getResource('views/details_panel.php'),
168
-			'code_source'       => $this->getResource('views/code_source.php'),
169
-			'details_content'   => $this->getResource('views/details_content.php'),
170
-			'footer'            => $this->getResource('views/footer.php'),
171
-			'plain_exception'   => Formatter::formatExceptionAsPlainText($this->getSupervisor()),
172
-			'handler'           => $this,
173
-			'handlers'          => $this->getDebug()->getHandlers(),
174
-			'debug'             => $this->getDebug(),
175
-			'code'              => $this->getExceptionCode(),
176
-			'message'           => $supervisor->getExceptionMessage(),
177
-			'frames'            => $this->getExceptionFrames(),
178
-			'tables'            => $this->getProcessTables($tables),
179
-		];
180
-	}
159
+        return [ 
160
+            'class'             => explode('\\', $supervisor->getExceptionName()),
161
+            'stylesheet'        => preg_replace('#[\r\n\t ]+#', ' ', $style),
162
+            'javascript'        => preg_replace('#[\r\n\t ]+#', ' ', $jscript),
163
+            'header'            => $this->getResource('views/header.php'),
164
+            'sidebar'           => $this->getResource('views/sidebar.php'),
165
+            'frame_description' => $this->getResource('views/frame_description.php'),
166
+            'frame_list'        => $this->getResource('views/frame_list.php'),
167
+            'details_panel'     => $this->getResource('views/details_panel.php'),
168
+            'code_source'       => $this->getResource('views/code_source.php'),
169
+            'details_content'   => $this->getResource('views/details_content.php'),
170
+            'footer'            => $this->getResource('views/footer.php'),
171
+            'plain_exception'   => Formatter::formatExceptionAsPlainText($this->getSupervisor()),
172
+            'handler'           => $this,
173
+            'handlers'          => $this->getDebug()->getHandlers(),
174
+            'debug'             => $this->getDebug(),
175
+            'code'              => $this->getExceptionCode(),
176
+            'message'           => $supervisor->getExceptionMessage(),
177
+            'frames'            => $this->getExceptionFrames(),
178
+            'tables'            => $this->getProcessTables($tables),
179
+        ];
180
+    }
181 181
 	
182
-	/**
183
-	 * The way in which the data sender (usually the server) can tell the recipient
184
-	 * (the browser, in general) what type of data is being sent in this case, html format tagged.
185
-	 * 
186
-	 * @return string
187
-	 */
188
-	public function contentType()
189
-	{
190
-		return 'text/html;charset=UTF-8';
191
-	}
192
-
193
-	/**
194
-	 * Gets the brand of project.
195
-	 * 
196
-	 * @return string
197
-	 */
198
-	public function getBrand()
199
-	{
200
-		return $this->brand;
201
-	}
202
-
203
-	/**
204
-	 * Returns the default tables.
205
-	 * 
206
-	 * @return \Syscodes\Contracts\Debug\Table[]
207
-	 */
208
-	protected function getDefaultTables()
209
-	{
210
-		return [
211
-			new ArrayTable('GET Data', $_GET),
212
-			new ArrayTable('POST Data', $_POST),
213
-			new ArrayTable('Files', $_FILES),
214
-			new ArrayTable('Cookie', $_COOKIE),
215
-			new ArrayTable('Session', isset($_SESSION) ? $_SESSION : []),
216
-			new ArrayTable('Server/Request Data', $_SERVER),
217
-			new ArrayTable(__('exception.environmentVars'), $_ENV),
218
-		];
219
-	}
220
-
221
-	/**
222
-	 * Get the code of the exception that is currently being handled.
223
-	 * 
224
-	 * @return string
225
-	 */
226
-	protected function getExceptionCode()
227
-	{
228
-		$exception = $this->getException();
229
-		$code      = $exception->getCode();
230
-
231
-		if ($exception instanceof ErrorException) {
232
-			$code = Misc::translateErrorCode($exception->getSeverity());
233
-		}
234
-
235
-		return (string) $code;
236
-	}
237
-
238
-	/**
239
-	 * Get the stack trace frames of the exception that is currently being handled.
240
-	 * 
241
-	 * @return \Syscodes\Debug\Engine\Supervisor;
242
-	 */
243
-	protected function getExceptionFrames()
244
-	{
245
-		$frames = $this->getSupervisor()->getFrames();
182
+    /**
183
+     * The way in which the data sender (usually the server) can tell the recipient
184
+     * (the browser, in general) what type of data is being sent in this case, html format tagged.
185
+     * 
186
+     * @return string
187
+     */
188
+    public function contentType()
189
+    {
190
+        return 'text/html;charset=UTF-8';
191
+    }
192
+
193
+    /**
194
+     * Gets the brand of project.
195
+     * 
196
+     * @return string
197
+     */
198
+    public function getBrand()
199
+    {
200
+        return $this->brand;
201
+    }
202
+
203
+    /**
204
+     * Returns the default tables.
205
+     * 
206
+     * @return \Syscodes\Contracts\Debug\Table[]
207
+     */
208
+    protected function getDefaultTables()
209
+    {
210
+        return [
211
+            new ArrayTable('GET Data', $_GET),
212
+            new ArrayTable('POST Data', $_POST),
213
+            new ArrayTable('Files', $_FILES),
214
+            new ArrayTable('Cookie', $_COOKIE),
215
+            new ArrayTable('Session', isset($_SESSION) ? $_SESSION : []),
216
+            new ArrayTable('Server/Request Data', $_SERVER),
217
+            new ArrayTable(__('exception.environmentVars'), $_ENV),
218
+        ];
219
+    }
220
+
221
+    /**
222
+     * Get the code of the exception that is currently being handled.
223
+     * 
224
+     * @return string
225
+     */
226
+    protected function getExceptionCode()
227
+    {
228
+        $exception = $this->getException();
229
+        $code      = $exception->getCode();
230
+
231
+        if ($exception instanceof ErrorException) {
232
+            $code = Misc::translateErrorCode($exception->getSeverity());
233
+        }
234
+
235
+        return (string) $code;
236
+    }
237
+
238
+    /**
239
+     * Get the stack trace frames of the exception that is currently being handled.
240
+     * 
241
+     * @return \Syscodes\Debug\Engine\Supervisor;
242
+     */
243
+    protected function getExceptionFrames()
244
+    {
245
+        $frames = $this->getSupervisor()->getFrames();
246 246
 		
247
-		return $frames;
248
-	}
247
+        return $frames;
248
+    }
249 249
 	
250
-	/**
251
-	 * Gets the page title web.
252
-	 * 
253
-	 * @return string
254
-	 */
255
-	public function getPageTitle()
256
-	{
257
-		return $this->pageTitle;
258
-	}
259
-
260
-	/**
261
-	 * Processes an array of tables making sure everything is allright.
262
-	 * 
263
-	 * @param  \Syscodes\Contracts\Debug\Table[]  $tables
264
-	 * 
265
-	 * @return array
266
-	 */
267
-	protected function getProcessTables(array $tables)
268
-	{
269
-		$processTables = [];
270
-
271
-		foreach ($tables as $table) {
272
-			if ( ! $table instanceof Table) {
273
-				continue;
274
-			}
275
-
276
-			$label = $table->getLabel();
277
-
278
-			try {
279
-				$data = $table->getData();
280
-
281
-				if ( ! (is_array($data) || $data instanceof Traversable)) {
282
-					$data = [];
283
-				}
284
-			} catch (Exception $e) {
285
-				$data = [];
286
-			}
287
-
288
-			$processTables[$label] = $data;
289
-		}
290
-
291
-		return $processTables;
292
-	}
293
-
294
-	/**
295
-	 * Finds a resource, by its relative path, in all available search paths.
296
-	 *
297
-	 * @param  string  $resource
298
-	 * 
299
-	 * @return string
300
-	 * 
301
-	 * @throws \RuntimeException
302
-	 */
303
-	protected function getResource($resource)
304
-	{
305
-		if (isset($this->resourceCache[$resource])) {
306
-			return $this->resourceCache[$resource];
307
-		}
308
-
309
-		foreach ($this->searchPaths as $path) {
310
-			$fullPath = $path.DIRECTORY_SEPARATOR.$resource;
311
-
312
-			if (is_file($fullPath)) {
313
-				// Cache:
314
-				$this->resourceCache[$resource] = $fullPath;
315
-
316
-				return $fullPath;
317
-			}
318
-		}
319
-
320
-		throw new RuntimeException( 
321
-				"Could not find resource '{$resource}' in any resource paths.". 
322
-				"(searched: ".join(", ", $this->searchPaths).")");
323
-	}
250
+    /**
251
+     * Gets the page title web.
252
+     * 
253
+     * @return string
254
+     */
255
+    public function getPageTitle()
256
+    {
257
+        return $this->pageTitle;
258
+    }
259
+
260
+    /**
261
+     * Processes an array of tables making sure everything is allright.
262
+     * 
263
+     * @param  \Syscodes\Contracts\Debug\Table[]  $tables
264
+     * 
265
+     * @return array
266
+     */
267
+    protected function getProcessTables(array $tables)
268
+    {
269
+        $processTables = [];
270
+
271
+        foreach ($tables as $table) {
272
+            if ( ! $table instanceof Table) {
273
+                continue;
274
+            }
275
+
276
+            $label = $table->getLabel();
277
+
278
+            try {
279
+                $data = $table->getData();
280
+
281
+                if ( ! (is_array($data) || $data instanceof Traversable)) {
282
+                    $data = [];
283
+                }
284
+            } catch (Exception $e) {
285
+                $data = [];
286
+            }
287
+
288
+            $processTables[$label] = $data;
289
+        }
290
+
291
+        return $processTables;
292
+    }
293
+
294
+    /**
295
+     * Finds a resource, by its relative path, in all available search paths.
296
+     *
297
+     * @param  string  $resource
298
+     * 
299
+     * @return string
300
+     * 
301
+     * @throws \RuntimeException
302
+     */
303
+    protected function getResource($resource)
304
+    {
305
+        if (isset($this->resourceCache[$resource])) {
306
+            return $this->resourceCache[$resource];
307
+        }
308
+
309
+        foreach ($this->searchPaths as $path) {
310
+            $fullPath = $path.DIRECTORY_SEPARATOR.$resource;
311
+
312
+            if (is_file($fullPath)) {
313
+                // Cache:
314
+                $this->resourceCache[$resource] = $fullPath;
315
+
316
+                return $fullPath;
317
+            }
318
+        }
319
+
320
+        throw new RuntimeException( 
321
+                "Could not find resource '{$resource}' in any resource paths.". 
322
+                "(searched: ".join(", ", $this->searchPaths).")");
323
+    }
324 324
 	
325
-	/**
326
-	 * Given an exception and status code will display the error to the client.
327
-	 * 
328
-	 * @return int|null
329
-	 */
330
-	public function handle()
331
-	{	
332
-		$templatePath = $this->getResource('debug.layout.php');
333
-
334
-		$vars = $this->collectionVars();
325
+    /**
326
+     * Given an exception and status code will display the error to the client.
327
+     * 
328
+     * @return int|null
329
+     */
330
+    public function handle()
331
+    {	
332
+        $templatePath = $this->getResource('debug.layout.php');
333
+
334
+        $vars = $this->collectionVars();
335 335
 		
336
-		if (empty($vars['message'])) $vars['message'] = __('exception.noMessage');
336
+        if (empty($vars['message'])) $vars['message'] = __('exception.noMessage');
337 337
 		
338
-		$this->template->setVariables($vars);
339
-		$this->template->render($templatePath);
338
+        $this->template->setVariables($vars);
339
+        $this->template->render($templatePath);
340 340
 		
341
-		return MainHandler::QUIT;
342
-	}
343
-
344
-	/**
345
-	 * Set the editor to use to open referenced files, by a string identifier or callable
346
-	 * that will be executed for every file reference. Should return a string.
347
-	 * 
348
-	 * @example  $debug->setEditor(function($file, $line) { return "file:///{$file}"; });
349
-	 * @example  $debug->setEditor('vscode');
350
-	 * 
351
-	 * @param  string  $editor
352
-	 * 
353
-	 * @return void
354
-	 * 
355
-	 * @throws \InvalidArgumentException
356
-	 */
357
-	public function setEditor($editor)
358
-	{
359
-		if ( ! is_callable($editor) && ! isset($this->editors[$editor])) {
360
-			throw new InvalidArgumentException("Unknown editor identifier: [{$editor}]. Known editors: " .
361
-				implode(', ', array_keys($this->editors))
362
-			);
363
-		}
364
-
365
-		$this->editor = $editor;
366
-	}
367
-
368
-	/**
369
-	 * Given a string file path, and an integer file line,
370
-	 * executes the editor resolver and returns.
371
-	 * 
372
-	 * @param  string  $file
373
-	 * @param  int	   $line
374
-	 * 
375
-	 * @return string|bool
376
-	 * 
377
-	 * @throws \UnexpectedValueException
378
-	 */
379
-	public function getEditorAtHref($file, $line)
380
-	{
381
-		$editor = $this->getEditor($file, $line);
382
-
383
-		if (empty($editor))	{
384
-			return false;
385
-		}
386
-
387
-		if ( ! isset($editor['url']) || ! is_string($editor['url'])) {
388
-			throw new UnexpectedValueException(__METHOD__.'should always resolve to a string or a valid editor array');
389
-		}
390
-
391
-		$editor['url'] = str_replace("%file", rawurldecode($file), $editor['url']);
392
-		$editor['url'] = str_replace("%line", rawurldecode($line), $editor['url']);
393
-
394
-		return $editor['url'];
395
-	}
396
-
397
-	/**
398
-	 * The editor must be a valid callable function/closure.
399
-	 * 
400
-	 * @param  string  $file
401
-	 * @param  int	   $line
402
-	 * 
403
-	 * @return array
404
-	 */
405
-	protected function getEditor($file, $line)
406
-	{
407
-		if ( ! $this->editor || ( ! is_string($this->editor) && ! is_callable($this->editor))) {
408
-			return [];
409
-		}
410
-
411
-		if (is_string($this->editor) && isset($this->editors[$this->editor]) && ! is_callable($this->editors[$this->editor])) {
412
-			return ['url' => $this->editors[$this->editor]];
413
-		}
414
-
415
-		if (is_callable($this->editor) || (isset($this->editors[$this->editor]) && is_callable($this->editors[$this->editor]))) {
416
-			if (is_callable($this->editor)) {
417
-				$callback = call_user_func($this->editor, $filePath, $line);
418
-			} else {
419
-				$callback = call_user_func($this->editors[$this->editor], $filePath, $line);
420
-			}
421
-
422
-			if (empty($callback)) {
423
-				return [];
424
-			}
425
-
426
-			if (is_string($callback)) {
427
-				return ['url' => $callback];
428
-			}
341
+        return MainHandler::QUIT;
342
+    }
343
+
344
+    /**
345
+     * Set the editor to use to open referenced files, by a string identifier or callable
346
+     * that will be executed for every file reference. Should return a string.
347
+     * 
348
+     * @example  $debug->setEditor(function($file, $line) { return "file:///{$file}"; });
349
+     * @example  $debug->setEditor('vscode');
350
+     * 
351
+     * @param  string  $editor
352
+     * 
353
+     * @return void
354
+     * 
355
+     * @throws \InvalidArgumentException
356
+     */
357
+    public function setEditor($editor)
358
+    {
359
+        if ( ! is_callable($editor) && ! isset($this->editors[$editor])) {
360
+            throw new InvalidArgumentException("Unknown editor identifier: [{$editor}]. Known editors: " .
361
+                implode(', ', array_keys($this->editors))
362
+            );
363
+        }
364
+
365
+        $this->editor = $editor;
366
+    }
367
+
368
+    /**
369
+     * Given a string file path, and an integer file line,
370
+     * executes the editor resolver and returns.
371
+     * 
372
+     * @param  string  $file
373
+     * @param  int	   $line
374
+     * 
375
+     * @return string|bool
376
+     * 
377
+     * @throws \UnexpectedValueException
378
+     */
379
+    public function getEditorAtHref($file, $line)
380
+    {
381
+        $editor = $this->getEditor($file, $line);
382
+
383
+        if (empty($editor))	{
384
+            return false;
385
+        }
386
+
387
+        if ( ! isset($editor['url']) || ! is_string($editor['url'])) {
388
+            throw new UnexpectedValueException(__METHOD__.'should always resolve to a string or a valid editor array');
389
+        }
390
+
391
+        $editor['url'] = str_replace("%file", rawurldecode($file), $editor['url']);
392
+        $editor['url'] = str_replace("%line", rawurldecode($line), $editor['url']);
393
+
394
+        return $editor['url'];
395
+    }
396
+
397
+    /**
398
+     * The editor must be a valid callable function/closure.
399
+     * 
400
+     * @param  string  $file
401
+     * @param  int	   $line
402
+     * 
403
+     * @return array
404
+     */
405
+    protected function getEditor($file, $line)
406
+    {
407
+        if ( ! $this->editor || ( ! is_string($this->editor) && ! is_callable($this->editor))) {
408
+            return [];
409
+        }
410
+
411
+        if (is_string($this->editor) && isset($this->editors[$this->editor]) && ! is_callable($this->editors[$this->editor])) {
412
+            return ['url' => $this->editors[$this->editor]];
413
+        }
414
+
415
+        if (is_callable($this->editor) || (isset($this->editors[$this->editor]) && is_callable($this->editors[$this->editor]))) {
416
+            if (is_callable($this->editor)) {
417
+                $callback = call_user_func($this->editor, $filePath, $line);
418
+            } else {
419
+                $callback = call_user_func($this->editors[$this->editor], $filePath, $line);
420
+            }
421
+
422
+            if (empty($callback)) {
423
+                return [];
424
+            }
425
+
426
+            if (is_string($callback)) {
427
+                return ['url' => $callback];
428
+            }
429 429
 			
430
-			return ['url' => isset($callback['url']) ? $callback['url'] : $callback];
431
-		}
430
+            return ['url' => isset($callback['url']) ? $callback['url'] : $callback];
431
+        }
432 432
 		
433
-		return [];
434
-	}
435
-
436
-	/**
437
-	 * Registered the editor.
438
-	 * 
439
-	 * @return string
440
-	 */
441
-	public function getEditorcode()
442
-	{
443
-		return $this->editor;
444
-	}
433
+        return [];
434
+    }
435
+
436
+    /**
437
+     * Registered the editor.
438
+     * 
439
+     * @return string
440
+     */
441
+    public function getEditorcode()
442
+    {
443
+        return $this->editor;
444
+    }
445 445
 	
446
-	/**
447
-	 * Sets the brand of project.
448
-	 * 
449
-	 * @param  string  $brand
450
-	 * 
451
-	 * @return void
452
-	 */
453
-	public function setBrand($brand)
454
-	{
455
-		$this->brand = (string) $brand;
456
-	}
446
+    /**
447
+     * Sets the brand of project.
448
+     * 
449
+     * @param  string  $brand
450
+     * 
451
+     * @return void
452
+     */
453
+    public function setBrand($brand)
454
+    {
455
+        $this->brand = (string) $brand;
456
+    }
457 457
 	
458
-	/**
459
-	 * Sets the page title web.
460
-	 * 
461
-	 * @param  string  $title
462
-	 * 
463
-	 * @return void
464
-	 */
465
-	public function setPageTitle($title)
466
-	{
467
-		$this->pageTitle = (string) $title;
468
-	}
458
+    /**
459
+     * Sets the page title web.
460
+     * 
461
+     * @param  string  $title
462
+     * 
463
+     * @return void
464
+     */
465
+    public function setPageTitle($title)
466
+    {
467
+        $this->pageTitle = (string) $title;
468
+    }
469 469
 }
470 470
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 	public function setEditor($editor)
358 358
 	{
359 359
 		if ( ! is_callable($editor) && ! isset($this->editors[$editor])) {
360
-			throw new InvalidArgumentException("Unknown editor identifier: [{$editor}]. Known editors: " .
360
+			throw new InvalidArgumentException("Unknown editor identifier: [{$editor}]. Known editors: ".
361 361
 				implode(', ', array_keys($this->editors))
362 362
 			);
363 363
 		}
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 	{
381 381
 		$editor = $this->getEditor($file, $line);
382 382
 
383
-		if (empty($editor))	{
383
+		if (empty($editor)) {
384 384
 			return false;
385 385
 		}
386 386
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -333,7 +333,9 @@
 block discarded – undo
333 333
 
334 334
 		$vars = $this->collectionVars();
335 335
 		
336
-		if (empty($vars['message'])) $vars['message'] = __('exception.noMessage');
336
+		if (empty($vars['message'])) {
337
+		    $vars['message'] = __('exception.noMessage');
338
+		}
337 339
 		
338 340
 		$this->template->setVariables($vars);
339 341
 		$this->template->render($templatePath);
Please login to merge, or discard this patch.
src/components/Debug/Exceptions/FrameHandler/Frame.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -150,7 +150,7 @@
 block discarded – undo
150 150
         $comments = $this->comments;
151 151
 
152 152
         if ($filter !== null) {
153
-            $comments = array_filter($comments, function ($comment) use ($filter) {
153
+            $comments = array_filter($comments, function($comment) use ($filter) {
154 154
                 return $comment['context'] == $filter;
155 155
             });
156 156
         }
Please login to merge, or discard this patch.
src/components/Debug/Exceptions/FrameHandler/Supervisor.php 1 patch
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -31,152 +31,152 @@
 block discarded – undo
31 31
  */
32 32
 class Supervisor
33 33
 {
34
-	/**
35
-	 * Get exception. 
36
-	 * 
37
-	 * @var \Throwable $exception
38
-	 */
39
-	protected $exception;
40
-
41
-	/**
42
-	 * The frame execute errors.
43
-	 * 
44
-	 * @var string $frames
45
-	 */
46
-	protected $frames;
47
-
48
-	/**
49
-	 * Constructor. The Supervisor class instance.
50
-	 * 
51
-	 * @param  \Throwable  $exception
52
-	 * 
53
-	 * @return string
54
-	 */
55
-	public function __construct($exception)
56
-	{
57
-		$this->exception = $exception;
58
-	}
34
+    /**
35
+     * Get exception. 
36
+     * 
37
+     * @var \Throwable $exception
38
+     */
39
+    protected $exception;
40
+
41
+    /**
42
+     * The frame execute errors.
43
+     * 
44
+     * @var string $frames
45
+     */
46
+    protected $frames;
47
+
48
+    /**
49
+     * Constructor. The Supervisor class instance.
50
+     * 
51
+     * @param  \Throwable  $exception
52
+     * 
53
+     * @return string
54
+     */
55
+    public function __construct($exception)
56
+    {
57
+        $this->exception = $exception;
58
+    }
59 59
 	
60
-	/**
61
-	 * Returns an iterator for the inspected exception's frames.
62
-	 * 
63
-	 * @param  \Throwable  $exception
64
-	 * 
65
-	 * @return array 
66
-	 */
67
-	public function getFrames()
68
-	{
69
-		if ($this->frames === null) {
70
-			$frames = $this->getTrace($this->exception);	
71
-
72
-			// Fill empty line/file info for call_user_func_array usages 
73
-			foreach ($frames as $k => $frame) {
74
-				if (empty($frame['file'])) {
75
-					// Default values when file and line are missing
76
-					$file = '[PHP internal Code]';
77
-					$line = 0;
78
-					$next_frame = ! empty($frames[$k + 1]) ? $frames[$k + 1] : [];
79
-					$frames[$k]['file'] = $file;
80
-					$frames[$k]['line'] = $line;
81
-				}
82
-			}
60
+    /**
61
+     * Returns an iterator for the inspected exception's frames.
62
+     * 
63
+     * @param  \Throwable  $exception
64
+     * 
65
+     * @return array 
66
+     */
67
+    public function getFrames()
68
+    {
69
+        if ($this->frames === null) {
70
+            $frames = $this->getTrace($this->exception);	
71
+
72
+            // Fill empty line/file info for call_user_func_array usages 
73
+            foreach ($frames as $k => $frame) {
74
+                if (empty($frame['file'])) {
75
+                    // Default values when file and line are missing
76
+                    $file = '[PHP internal Code]';
77
+                    $line = 0;
78
+                    $next_frame = ! empty($frames[$k + 1]) ? $frames[$k + 1] : [];
79
+                    $frames[$k]['file'] = $file;
80
+                    $frames[$k]['line'] = $line;
81
+                }
82
+            }
83 83
 			
84
-			// Find latest non-error handling frame index ($i) used to remove error handling frames
85
-			$i = 0;
86
-
87
-			foreach ($frames as $k => $frame) {
88
-				if ($frame['file'] == $this->exception->getFile() && $frame['line'] == $this->exception->getLine()) {
89
-					$i = $k;
90
-				}
91
-			}
92
-			// Remove error handling frames
93
-			if ($i > 0) {
94
-				array_splice($frames, 0, $i);
95
-			}
84
+            // Find latest non-error handling frame index ($i) used to remove error handling frames
85
+            $i = 0;
86
+
87
+            foreach ($frames as $k => $frame) {
88
+                if ($frame['file'] == $this->exception->getFile() && $frame['line'] == $this->exception->getLine()) {
89
+                    $i = $k;
90
+                }
91
+            }
92
+            // Remove error handling frames
93
+            if ($i > 0) {
94
+                array_splice($frames, 0, $i);
95
+            }
96 96
 	
97
-			$firstFrame = $this->getFrameFromException($this->exception);	
98
-			array_unshift($frames, $firstFrame);
99
-
100
-			$this->frames = new Collection($frames);
101
-		}
102
-
103
-		return $this->frames;
104
-	}
105
-
106
-	/**
107
-	 * Given an exception, generates an array in the format generated by Exception::getTrace().
108
-	 * 
109
-	 * @param  \Throwable  $exception
110
-	 * 
111
-	 * @return array
112
-	 */
113
-	protected function getFrameFromException(Throwable $exception)
114
-	{
115
-		return [
116
-			'file'  => $exception->getFile(),
117
-			'line'  => $exception->getLine(),
118
-			'class' => get_class($exception),
119
-			'code'  => $exception->getCode(),
120
-			'args'  => [
121
-				$exception->getMessage(),
122
-			],
123
-		];
124
-	}
125
-
126
-	/**
127
-	 * Gets exception already specified.
128
-	 * 
129
-	 * @return \Throwable
130
-	 */
131
-	public function getException()
132
-	{
133
-		return $this->exception;
134
-	}
135
-
136
-	/**
137
-	 * Gets the message of exception.
138
-	 * 
139
-	 * @return string
140
-	 */
141
-	public function getExceptionMessage()
142
-	{
143
-		return $this->exception->getMessage();
144
-	}
145
-
146
-	/**
147
-	 * Gets the class name of exception.
148
-	 * 
149
-	 * @return string
150
-	 */
151
-	public function getExceptionName()
152
-	{
153
-		return getClass($this->exception);
154
-	}
97
+            $firstFrame = $this->getFrameFromException($this->exception);	
98
+            array_unshift($frames, $firstFrame);
99
+
100
+            $this->frames = new Collection($frames);
101
+        }
102
+
103
+        return $this->frames;
104
+    }
105
+
106
+    /**
107
+     * Given an exception, generates an array in the format generated by Exception::getTrace().
108
+     * 
109
+     * @param  \Throwable  $exception
110
+     * 
111
+     * @return array
112
+     */
113
+    protected function getFrameFromException(Throwable $exception)
114
+    {
115
+        return [
116
+            'file'  => $exception->getFile(),
117
+            'line'  => $exception->getLine(),
118
+            'class' => get_class($exception),
119
+            'code'  => $exception->getCode(),
120
+            'args'  => [
121
+                $exception->getMessage(),
122
+            ],
123
+        ];
124
+    }
125
+
126
+    /**
127
+     * Gets exception already specified.
128
+     * 
129
+     * @return \Throwable
130
+     */
131
+    public function getException()
132
+    {
133
+        return $this->exception;
134
+    }
135
+
136
+    /**
137
+     * Gets the message of exception.
138
+     * 
139
+     * @return string
140
+     */
141
+    public function getExceptionMessage()
142
+    {
143
+        return $this->exception->getMessage();
144
+    }
145
+
146
+    /**
147
+     * Gets the class name of exception.
148
+     * 
149
+     * @return string
150
+     */
151
+    public function getExceptionName()
152
+    {
153
+        return getClass($this->exception);
154
+    }
155 155
 	
156
-	/**
157
-	 * Gets the backtrace from an exception.
158
-	 * 
159
-	 * @param  \Throwable  $exception
160
-	 * 
161
-	 * @return array
162
-	 */
163
-	protected function getTrace($exception)
164
-	{
165
-		$traces = $exception->getTrace();
166
-
167
-		if ( ! $exception instanceof ErrorException) {
168
-			return $traces;
169
-		}
170
-
171
-		if ( ! extension_loaded('xdebug') || ! xdebug_is_enabled()) {
172
-			return [];
173
-		}
156
+    /**
157
+     * Gets the backtrace from an exception.
158
+     * 
159
+     * @param  \Throwable  $exception
160
+     * 
161
+     * @return array
162
+     */
163
+    protected function getTrace($exception)
164
+    {
165
+        $traces = $exception->getTrace();
166
+
167
+        if ( ! $exception instanceof ErrorException) {
168
+            return $traces;
169
+        }
170
+
171
+        if ( ! extension_loaded('xdebug') || ! xdebug_is_enabled()) {
172
+            return [];
173
+        }
174 174
 		
175
-		// Use xdebug to get the full stack trace and remove the shutdown handler stack trace
176
-		$stack = array_reverse(xdebug_get_function_stack());
177
-		$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
178
-		$traces = array_diff_key($stack, $trace);
175
+        // Use xdebug to get the full stack trace and remove the shutdown handler stack trace
176
+        $stack = array_reverse(xdebug_get_function_stack());
177
+        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
178
+        $traces = array_diff_key($stack, $trace);
179 179
 		
180
-		return $traces;
181
-	}
180
+        return $traces;
181
+    }
182 182
 }
183 183
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Debug/Exceptions/Util/TemplateHandler.php 2 patches
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -32,283 +32,283 @@
 block discarded – undo
32 32
  */
33 33
 class TemplateHandler
34 34
 {
35
-	/**
36
-	 * Benchmark instance.
37
-	 * 
38
-	 * @var string $benchmark
39
-	 */
40
-	protected $benchmark;
35
+    /**
36
+     * Benchmark instance.
37
+     * 
38
+     * @var string $benchmark
39
+     */
40
+    protected $benchmark;
41 41
 
42
-	/**
43
-	 * Nesting level of the output buffering mechanism.
44
-	 *
45
-	 * @var string $obLevel
46
-	 */
47
-	public $obLevel;
42
+    /**
43
+     * Nesting level of the output buffering mechanism.
44
+     *
45
+     * @var string $obLevel
46
+     */
47
+    public $obLevel;
48 48
 	
49
-	/**
50
-	 * The functions of system what control errors and exceptions.
51
-	 * 
52
-	 * @var string $system
53
-	 */
54
-	protected $system;
49
+    /**
50
+     * The functions of system what control errors and exceptions.
51
+     * 
52
+     * @var string $system
53
+     */
54
+    protected $system;
55 55
 	
56
-	/**
57
-	 * An array of variables to be passed to all templates.
58
-	 * 
59
-	 * @var array $variables
60
-	 */
61
-	protected $variables = [];
56
+    /**
57
+     * An array of variables to be passed to all templates.
58
+     * 
59
+     * @var array $variables
60
+     */
61
+    protected $variables = [];
62 62
 
63
-	/**
64
-	 * Constructor. The TemplateHandler class instance.
65
-	 * 
66
-	 * @return void
67
-	 */
68
-	public function __construct()
69
-	{
70
-		$this->system    = new System;
71
-		$this->benchmark = new Benchmark;
72
-		$this->obLevel   = $this->system->getOutputBufferLevel();
73
-	}
63
+    /**
64
+     * Constructor. The TemplateHandler class instance.
65
+     * 
66
+     * @return void
67
+     */
68
+    public function __construct()
69
+    {
70
+        $this->system    = new System;
71
+        $this->benchmark = new Benchmark;
72
+        $this->obLevel   = $this->system->getOutputBufferLevel();
73
+    }
74 74
 
75
-	/**
76
-	 * Clean Path: This makes nicer looking paths for the error output.
77
-	 *
78
-	 * @param  string  $file
79
-	 *
80
-	 * @return string
81
-	 */
82
-	public function cleanPath($file)
83
-	{
84
-		if (strpos($file, APP_PATH) === 0) {
85
-			$file = 'APP_PATH'.DIRECTORY_SEPARATOR.substr($file, strlen(APP_PATH));
86
-		} elseif (strpos($file, SYS_PATH) === 0) {
87
-			$file = 'SYS_PATH'.DIRECTORY_SEPARATOR.substr($file, strlen(SYS_PATH));
88
-		} elseif (strpos($file, CON_PATH) === 0) {
89
-			$file = 'CON_PATH'.DIRECTORY_SEPARATOR.substr($file, strlen(CON_PATH));
90
-		} elseif (strpos($file, RES_PATH) === 0) {
91
-			$file = 'RES_PATH'.DIRECTORY_SEPARATOR.substr($file, strlen(RES_PATH));
92
-		}
75
+    /**
76
+     * Clean Path: This makes nicer looking paths for the error output.
77
+     *
78
+     * @param  string  $file
79
+     *
80
+     * @return string
81
+     */
82
+    public function cleanPath($file)
83
+    {
84
+        if (strpos($file, APP_PATH) === 0) {
85
+            $file = 'APP_PATH'.DIRECTORY_SEPARATOR.substr($file, strlen(APP_PATH));
86
+        } elseif (strpos($file, SYS_PATH) === 0) {
87
+            $file = 'SYS_PATH'.DIRECTORY_SEPARATOR.substr($file, strlen(SYS_PATH));
88
+        } elseif (strpos($file, CON_PATH) === 0) {
89
+            $file = 'CON_PATH'.DIRECTORY_SEPARATOR.substr($file, strlen(CON_PATH));
90
+        } elseif (strpos($file, RES_PATH) === 0) {
91
+            $file = 'RES_PATH'.DIRECTORY_SEPARATOR.substr($file, strlen(RES_PATH));
92
+        }
93 93
 
94
-		return $file;
95
-	}
94
+        return $file;
95
+    }
96 96
 
97
-	/**
98
-	 * Display memory usage in real-world units. Intended for use
99
-	 * with memory_get_usage, etc.
100
-	 *
101
-	 * @param  int  $bytes
102
-	 *
103
-	 * @return string
104
-	 */
105
-	public function displayMemory(int $bytes)
106
-	{
107
-		if ($bytes < 1024) {
108
-			return $bytes.'B';
109
-		} else if ($bytes < 1048576) {
110
-			return round($bytes/1024, 2).'KB';
111
-		}
97
+    /**
98
+     * Display memory usage in real-world units. Intended for use
99
+     * with memory_get_usage, etc.
100
+     *
101
+     * @param  int  $bytes
102
+     *
103
+     * @return string
104
+     */
105
+    public function displayMemory(int $bytes)
106
+    {
107
+        if ($bytes < 1024) {
108
+            return $bytes.'B';
109
+        } else if ($bytes < 1048576) {
110
+            return round($bytes/1024, 2).'KB';
111
+        }
112 112
 
113
-		return round($bytes/1048576, 2).'MB';
114
-	}
113
+        return round($bytes/1048576, 2).'MB';
114
+    }
115 115
 	
116
-	/**
117
-	 * Format the given value into a human readable string.
118
-	 * 
119
-	 * @param  mixed  $value
120
-	 * 
121
-	 * @return string
122
-	 */
123
-	public function dump($value)
124
-	{
125
-		return htmlspecialchars(print_r($value, true));
126
-	}
116
+    /**
117
+     * Format the given value into a human readable string.
118
+     * 
119
+     * @param  mixed  $value
120
+     * 
121
+     * @return string
122
+     */
123
+    public function dump($value)
124
+    {
125
+        return htmlspecialchars(print_r($value, true));
126
+    }
127 127
 	
128
-	/**
129
-	 * Format the args of the given Frame as a human readable html string.
130
-	 * 
131
-	 * @param  \Syscodes\Debug\FrameHandler\Frame  $frame
132
-	 * 
133
-	 * @return string  The rendered html
134
-	 */
135
-	public function dumpArgs(Frame $frame)
136
-	{
137
-		$html      = '';
138
-		$numFrames = count($frame->getArgs());
128
+    /**
129
+     * Format the args of the given Frame as a human readable html string.
130
+     * 
131
+     * @param  \Syscodes\Debug\FrameHandler\Frame  $frame
132
+     * 
133
+     * @return string  The rendered html
134
+     */
135
+    public function dumpArgs(Frame $frame)
136
+    {
137
+        $html      = '';
138
+        $numFrames = count($frame->getArgs());
139 139
 		
140
-		if ($numFrames > 0) {
141
-			$html = '<ol class="linenums">';
140
+        if ($numFrames > 0) {
141
+            $html = '<ol class="linenums">';
142 142
 			
143
-			foreach ($frame->getArgs() as $j => $frameArg) {
144
-				$html .= '<li>'.$this->dump($frameArg).'</li>';
145
-			}
143
+            foreach ($frame->getArgs() as $j => $frameArg) {
144
+                $html .= '<li>'.$this->dump($frameArg).'</li>';
145
+            }
146 146
 			
147
-			$html .= '</ol>';
148
-		}
147
+            $html .= '</ol>';
148
+        }
149 149
 		
150
-		return $html;
151
-	}
150
+        return $html;
151
+    }
152 152
 
153
-	/**
154
-	 * Escapes a string for output in an HTML document.
155
-	 * 
156
-	 * @param  string  $text
157
-	 * 
158
-	 * @return string
159
-	 */
160
-	public function escape($text)
161
-	{
162
-		$flags = ENT_QUOTES;
153
+    /**
154
+     * Escapes a string for output in an HTML document.
155
+     * 
156
+     * @param  string  $text
157
+     * 
158
+     * @return string
159
+     */
160
+    public function escape($text)
161
+    {
162
+        $flags = ENT_QUOTES;
163 163
 		
164
-		// HHVM has all constants defined, but only ENT_IGNORE
165
-		// works at the moment
166
-		if (defined("ENT_SUBSTITUTE") && ! defined("HHVM_VERSION")) {
167
-			$flags |= ENT_SUBSTITUTE;
168
-		} else {
169
-			$flags |= ENT_IGNORE;
170
-		}
164
+        // HHVM has all constants defined, but only ENT_IGNORE
165
+        // works at the moment
166
+        if (defined("ENT_SUBSTITUTE") && ! defined("HHVM_VERSION")) {
167
+            $flags |= ENT_SUBSTITUTE;
168
+        } else {
169
+            $flags |= ENT_IGNORE;
170
+        }
171 171
 		
172
-		$text = str_replace(chr(9), '    ', $text);
172
+        $text = str_replace(chr(9), '    ', $text);
173 173
 		
174
-		return htmlspecialchars($text, $flags, "UTF-8");
175
-	}
174
+        return htmlspecialchars($text, $flags, "UTF-8");
175
+    }
176 176
 
177
-	/**
178
-	 * Returns all variables for this helper.
179
-	 * 
180
-	 * @return array
181
-	 */
182
-	public function getVariables()
183
-	{
184
-		return $this->variables;
185
-	}
177
+    /**
178
+     * Returns all variables for this helper.
179
+     * 
180
+     * @return array
181
+     */
182
+    public function getVariables()
183
+    {
184
+        return $this->variables;
185
+    }
186 186
 
187
-	/**
188
-	 * Creates a syntax-highlighted version of a PHP file.
189
-	 *
190
-	 * @param  string  $file
191
-	 * @param  int     $lineNumber
192
-	 * @param  int     $lines
193
-	 *
194
-	 * @return bool|string
195
-	 * 
196
-	 * @throws \Exception
197
-	 */
198
-	public function highlightFile($file, $lineNumber, $lines = 15)
199
-	{
200
-		if (empty ($file) || ! is_readable($file)) {
201
-			return false;
202
-		}
187
+    /**
188
+     * Creates a syntax-highlighted version of a PHP file.
189
+     *
190
+     * @param  string  $file
191
+     * @param  int     $lineNumber
192
+     * @param  int     $lines
193
+     *
194
+     * @return bool|string
195
+     * 
196
+     * @throws \Exception
197
+     */
198
+    public function highlightFile($file, $lineNumber, $lines = 15)
199
+    {
200
+        if (empty ($file) || ! is_readable($file)) {
201
+            return false;
202
+        }
203 203
 
204
-		// Set our highlight colors:
205
-		if (function_exists('ini_set')) {
206
-			ini_set('highlight.comment', '#C5C5C5');
207
-			ini_set('highlight.default', '#5399BA');
208
-			ini_set('highlight.html', '#06B');
209
-			ini_set('highlight.keyword', '#7081A5;');
210
-			ini_set('highlight.string', '#d8A134');
211
-		}
204
+        // Set our highlight colors:
205
+        if (function_exists('ini_set')) {
206
+            ini_set('highlight.comment', '#C5C5C5');
207
+            ini_set('highlight.default', '#5399BA');
208
+            ini_set('highlight.html', '#06B');
209
+            ini_set('highlight.keyword', '#7081A5;');
210
+            ini_set('highlight.string', '#d8A134');
211
+        }
212 212
 
213
-		try {
214
-			$origin = file_get_contents($file);
215
-		} catch (Exception $e) {
216
-			return false;
217
-		}
213
+        try {
214
+            $origin = file_get_contents($file);
215
+        } catch (Exception $e) {
216
+            return false;
217
+        }
218 218
 
219
-		$origin  = str_replace(["\r\n", "\r"], "\n", $origin);
220
-		$origin  = explode("\n", highlight_string($origin , true));
221
-		$origin  = str_replace('<br />', "\n", $origin [1]);
219
+        $origin  = str_replace(["\r\n", "\r"], "\n", $origin);
220
+        $origin  = explode("\n", highlight_string($origin , true));
221
+        $origin  = str_replace('<br />', "\n", $origin [1]);
222 222
 
223
-		$origin  = explode("\n", str_replace("\r\n", "\n", $origin));
223
+        $origin  = explode("\n", str_replace("\r\n", "\n", $origin));
224 224
 
225
-		// Get just the part to show
226
-		$start = $lineNumber - (int)round($lines / 2);
227
-		$start = $start < 0 ? 0 : $start;
225
+        // Get just the part to show
226
+        $start = $lineNumber - (int)round($lines / 2);
227
+        $start = $start < 0 ? 0 : $start;
228 228
 
229
-		// Get just the lines we need to display, while keeping line numbers...
230
-		$origin  = array_splice($origin, $start, $lines, true);
229
+        // Get just the lines we need to display, while keeping line numbers...
230
+        $origin  = array_splice($origin, $start, $lines, true);
231 231
 
232
-		// Used to format the line number in the source
233
-		$format = '% '.strlen($start + $lines).'d';
232
+        // Used to format the line number in the source
233
+        $format = '% '.strlen($start + $lines).'d';
234 234
 
235
-		$out = '';
236
-		// Because the highlighting may have an uneven number
237
-		// of open and close span tags on one line, we need
238
-		// to ensure we can close them all to get the lines
239
-		// showing correctly.
240
-		$spans = 1;
235
+        $out = '';
236
+        // Because the highlighting may have an uneven number
237
+        // of open and close span tags on one line, we need
238
+        // to ensure we can close them all to get the lines
239
+        // showing correctly.
240
+        $spans = 1;
241 241
 
242
-		foreach ($origin as $n => $row) {
243
-			$spans += substr_count($row, '<span') - substr_count($row, '</span');
244
-			$row = str_replace(["\r", "\n"], ['', ''], $row);
242
+        foreach ($origin as $n => $row) {
243
+            $spans += substr_count($row, '<span') - substr_count($row, '</span');
244
+            $row = str_replace(["\r", "\n"], ['', ''], $row);
245 245
 
246
-			if (($n+$start+1) == $lineNumber) {
247
-				preg_match_all('#<[^>]+>#', $row, $tags);
248
-				$out .= sprintf("<span class='line highlight'><span class='number'>{$format}</span> %s\n</span>%s",
249
-						$n + $start + 1,
250
-						strip_tags($row),
251
-						implode('', $tags[0])
252
-				);
253
-			} else {
254
-				$out .= sprintf('<span class="number">'.$format.'</span> %s <span class="line">', $n + $start +1, $row) ."\n";
255
-			}
256
-		}
246
+            if (($n+$start+1) == $lineNumber) {
247
+                preg_match_all('#<[^>]+>#', $row, $tags);
248
+                $out .= sprintf("<span class='line highlight'><span class='number'>{$format}</span> %s\n</span>%s",
249
+                        $n + $start + 1,
250
+                        strip_tags($row),
251
+                        implode('', $tags[0])
252
+                );
253
+            } else {
254
+                $out .= sprintf('<span class="number">'.$format.'</span> %s <span class="line">', $n + $start +1, $row) ."\n";
255
+            }
256
+        }
257 257
 
258
-		$out .= str_repeat('</span>', $spans);
258
+        $out .= str_repeat('</span>', $spans);
259 259
 
260
-		return '<pre class="code-blocks"><code>'.$out.'</code></pre>';
261
-	}
260
+        return '<pre class="code-blocks"><code>'.$out.'</code></pre>';
261
+    }
262 262
 
263
-	/**
264
-	 * Sets the variables to be passed to all templates rendered 
265
-	 * by this template helper.
266
-	 * 
267
-	 * @param  array  $variables
268
-	 * 
269
-	 * @return void
270
-	 */
271
-	public function setVariables(array $variables)
272
-	{
273
-		$this->variables = $variables;
274
-	}
263
+    /**
264
+     * Sets the variables to be passed to all templates rendered 
265
+     * by this template helper.
266
+     * 
267
+     * @param  array  $variables
268
+     * 
269
+     * @return void
270
+     */
271
+    public function setVariables(array $variables)
272
+    {
273
+        $this->variables = $variables;
274
+    }
275 275
 
276
-	/**
277
-	 * Convert a string to a slug version of itself.
278
-	 * 
279
-	 * @param  string  $original
280
-	 * 
281
-	 * @return string
282
-	 */
283
-	public function slug($original)
284
-	{
285
-		$slug = str_replace(" ", "-", $original);
286
-		$slug = preg_replace('/[^\w\d\-\_]/i',' ', $slug);
276
+    /**
277
+     * Convert a string to a slug version of itself.
278
+     * 
279
+     * @param  string  $original
280
+     * 
281
+     * @return string
282
+     */
283
+    public function slug($original)
284
+    {
285
+        $slug = str_replace(" ", "-", $original);
286
+        $slug = preg_replace('/[^\w\d\-\_]/i',' ', $slug);
287 287
 
288
-		return strtolower($slug);
289
-	}
288
+        return strtolower($slug);
289
+    }
290 290
 
291
-	/**
292
-	 * Given an exception and status code will display the error to the client.
293
-	 *
294
-	 * @param  string  $template
295
-	 * 
296
-	 * @return void
297
-	 */
298
-	public function render($template)
299
-	{
300
-		$vars = $this->getVariables();
291
+    /**
292
+     * Given an exception and status code will display the error to the client.
293
+     *
294
+     * @param  string  $template
295
+     * 
296
+     * @return void
297
+     */
298
+    public function render($template)
299
+    {
300
+        $vars = $this->getVariables();
301 301
 
302
-		$vars['template'] = $this;
302
+        $vars['template'] = $this;
303 303
 		
304
-		if ($this->system->getOutputBufferLevel() > $this->obLevel + 1) {
305
-			@$this->system->endOutputBuffering();
306
-		}
304
+        if ($this->system->getOutputBufferLevel() > $this->obLevel + 1) {
305
+            @$this->system->endOutputBuffering();
306
+        }
307 307
 
308
-		// Instantiate the error view and prepare the vars
309
-		call_user_func(function () {
310
-			extract(func_get_arg(1));
311
-			include func_get_arg(0);
312
-		}, $template, $vars);
313
-	}
308
+        // Instantiate the error view and prepare the vars
309
+        call_user_func(function () {
310
+            extract(func_get_arg(1));
311
+            include func_get_arg(0);
312
+        }, $template, $vars);
313
+    }
314 314
 }
315 315
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 		if ($bytes < 1024) {
108 108
 			return $bytes.'B';
109 109
 		} else if ($bytes < 1048576) {
110
-			return round($bytes/1024, 2).'KB';
110
+			return round($bytes / 1024, 2).'KB';
111 111
 		}
112 112
 
113
-		return round($bytes/1048576, 2).'MB';
113
+		return round($bytes / 1048576, 2).'MB';
114 114
 	}
115 115
 	
116 116
 	/**
@@ -217,17 +217,17 @@  discard block
 block discarded – undo
217 217
 		}
218 218
 
219 219
 		$origin  = str_replace(["\r\n", "\r"], "\n", $origin);
220
-		$origin  = explode("\n", highlight_string($origin , true));
220
+		$origin  = explode("\n", highlight_string($origin, true));
221 221
 		$origin  = str_replace('<br />', "\n", $origin [1]);
222 222
 
223 223
 		$origin  = explode("\n", str_replace("\r\n", "\n", $origin));
224 224
 
225 225
 		// Get just the part to show
226
-		$start = $lineNumber - (int)round($lines / 2);
226
+		$start = $lineNumber - (int) round($lines / 2);
227 227
 		$start = $start < 0 ? 0 : $start;
228 228
 
229 229
 		// Get just the lines we need to display, while keeping line numbers...
230
-		$origin  = array_splice($origin, $start, $lines, true);
230
+		$origin = array_splice($origin, $start, $lines, true);
231 231
 
232 232
 		// Used to format the line number in the source
233 233
 		$format = '% '.strlen($start + $lines).'d';
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 			$spans += substr_count($row, '<span') - substr_count($row, '</span');
244 244
 			$row = str_replace(["\r", "\n"], ['', ''], $row);
245 245
 
246
-			if (($n+$start+1) == $lineNumber) {
246
+			if (($n + $start + 1) == $lineNumber) {
247 247
 				preg_match_all('#<[^>]+>#', $row, $tags);
248 248
 				$out .= sprintf("<span class='line highlight'><span class='number'>{$format}</span> %s\n</span>%s",
249 249
 						$n + $start + 1,
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 						implode('', $tags[0])
252 252
 				);
253 253
 			} else {
254
-				$out .= sprintf('<span class="number">'.$format.'</span> %s <span class="line">', $n + $start +1, $row) ."\n";
254
+				$out .= sprintf('<span class="number">'.$format.'</span> %s <span class="line">', $n + $start + 1, $row)."\n";
255 255
 			}
256 256
 		}
257 257
 
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 	public function slug($original)
284 284
 	{
285 285
 		$slug = str_replace(" ", "-", $original);
286
-		$slug = preg_replace('/[^\w\d\-\_]/i',' ', $slug);
286
+		$slug = preg_replace('/[^\w\d\-\_]/i', ' ', $slug);
287 287
 
288 288
 		return strtolower($slug);
289 289
 	}
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 		}
307 307
 
308 308
 		// Instantiate the error view and prepare the vars
309
-		call_user_func(function () {
309
+		call_user_func(function() {
310 310
 			extract(func_get_arg(1));
311 311
 			include func_get_arg(0);
312 312
 		}, $template, $vars);
Please login to merge, or discard this patch.
src/components/Debug/Benchmark.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@
 block discarded – undo
143 143
         $seconds  = (int) ($duration - $hours * 60 * 60 - $minutes * 60); 
144 144
         
145 145
         if ($seconds <= 0) {
146
-           return ' ms';
146
+            return ' ms';
147 147
         } elseif ($seconds > 0) {
148 148
             return ' s';
149 149
         }
Please login to merge, or discard this patch.
src/components/Filesystem/Filesystem.php 2 patches
Indentation   +805 added lines, -805 removed lines patch added patch discarded remove patch
@@ -35,820 +35,820 @@
 block discarded – undo
35 35
  */
36 36
 class Filesystem 
37 37
 {
38
-	/**
39
-	 * Enable locking for file reading and writing.
40
-	 *
41
-	 * @var null|bool $lock
42
-	 */
43
-	public $lock = null;
44
-
45
-	/**
46
-	 * Holds the file handler resource if the file is opened.
47
-	 *
48
-	 * @var resource $handler
49
-	 */
50
-	protected $handler;
51
-
52
-	/**
53
-	 * The files size in bytes.
54
-	 *
55
-	 * @var float $size
56
-	 */
57
-	protected $size;
58
-
59
-	/**
60
-	 * Append given data string to this file.
61
-	 *
62
-	 * @param  string  $path
63
-	 * @param  string  $data
64
-	 * @param  bool  $force
65
-	 *
66
-	 * @return bool
67
-	 */
68
-	public function append($path, $data, $force = false)
69
-	{
70
-		return $this->write($path, $data, 'a', $force);
71
-	}
72
-
73
-	/**
74
-	 * Copy a file to a new location.
75
-	 *
76
-	 * @param  string  $path
77
-	 * @param  string  $target
78
-	 * 
79
-	 * @return bool
80
-	 */
81
-	public function copy($path, $target)
82
-	{
83
-		return copy($path, $target);
84
-	}
85
-
86
-	/**
87
-	 * Get the contents of a file.
88
-	 *
89
-	 * @param  string  $path
90
-	 * @param  bool  $lock  (false by default)
91
-	 * @param  bool  $force  (false by default)
92
-	 *
93
-	 * @return string
94
-	 *
95
-	 * @throws FileNotFoundException
96
-	 */
97
-	public function get($path, $lock = false, $force = false)
98
-	{
99
-		if ($this->isFile($path)) {
100
-			return $lock ? $this->read($path, $force) : file_get_contents($path);
101
-		}
102
-
103
-		throw new FileNotFoundException($path);
104
-	}
105
-
106
-	/**
107
-	 * Get contents of a file with shared access.
108
-	 *
109
-	 * @param  string  $path
110
-	 * @param  bool  $force  
111
-	 *
112
-	 * @return string
113
-	 */
114
-	protected function read($path, $force = false)
115
-	{
116
-		$contents = '';
117
-
118
-		$this->open($path, 'rb', $force);
38
+    /**
39
+     * Enable locking for file reading and writing.
40
+     *
41
+     * @var null|bool $lock
42
+     */
43
+    public $lock = null;
44
+
45
+    /**
46
+     * Holds the file handler resource if the file is opened.
47
+     *
48
+     * @var resource $handler
49
+     */
50
+    protected $handler;
51
+
52
+    /**
53
+     * The files size in bytes.
54
+     *
55
+     * @var float $size
56
+     */
57
+    protected $size;
58
+
59
+    /**
60
+     * Append given data string to this file.
61
+     *
62
+     * @param  string  $path
63
+     * @param  string  $data
64
+     * @param  bool  $force
65
+     *
66
+     * @return bool
67
+     */
68
+    public function append($path, $data, $force = false)
69
+    {
70
+        return $this->write($path, $data, 'a', $force);
71
+    }
72
+
73
+    /**
74
+     * Copy a file to a new location.
75
+     *
76
+     * @param  string  $path
77
+     * @param  string  $target
78
+     * 
79
+     * @return bool
80
+     */
81
+    public function copy($path, $target)
82
+    {
83
+        return copy($path, $target);
84
+    }
85
+
86
+    /**
87
+     * Get the contents of a file.
88
+     *
89
+     * @param  string  $path
90
+     * @param  bool  $lock  (false by default)
91
+     * @param  bool  $force  (false by default)
92
+     *
93
+     * @return string
94
+     *
95
+     * @throws FileNotFoundException
96
+     */
97
+    public function get($path, $lock = false, $force = false)
98
+    {
99
+        if ($this->isFile($path)) {
100
+            return $lock ? $this->read($path, $force) : file_get_contents($path);
101
+        }
102
+
103
+        throw new FileNotFoundException($path);
104
+    }
105
+
106
+    /**
107
+     * Get contents of a file with shared access.
108
+     *
109
+     * @param  string  $path
110
+     * @param  bool  $force  
111
+     *
112
+     * @return string
113
+     */
114
+    protected function read($path, $force = false)
115
+    {
116
+        $contents = '';
117
+
118
+        $this->open($path, 'rb', $force);
119 119
 		
120
-		if ($this->handler) {
121
-			try {
122
-				if (flock($this->handler, LOCK_SH)) {
123
-					$this->clearStatCache($path);
120
+        if ($this->handler) {
121
+            try {
122
+                if (flock($this->handler, LOCK_SH)) {
123
+                    $this->clearStatCache($path);
124 124
 
125
-					$contents = fread($this->handler, $this->getSize($path) ?: 1);
125
+                    $contents = fread($this->handler, $this->getSize($path) ?: 1);
126 126
 					
127
-					while ( ! feof($this->handler)) {
128
-						$contents .= fgets($this->handler, 4096);
129
-					}
130
-
131
-					flock($this->handler, LOCK_UN);
132
-				}
133
-			} finally {
134
-				$this->close();
135
-			}
136
-		}
137
-
138
-		return trim($contents);
139
-	}
140
-
141
-	/**
142
-	 * Opens the current file with a given $mode.
143
-	 *
144
-	 * @param  string  $path
145
-	 * @param  string  $mode  A valid 'fopen' mode string (r|w|a ...)
146
-	 * @param  bool  $force  
147
-	 *
148
-	 * @return bool
149
-	 */
150
-	public function open($path, $mode, $force = false)
151
-	{
152
-		if ( ! $force && is_resource($this->handler)) {
153
-			return true;
154
-		}
155
-
156
-		if ($this->exists($path) === false) {
157
-			if ($this->create($path) === false) {
158
-				return false;
159
-			}
160
-		}
161
-
162
-		$this->handler = fopen($path, $mode);
163
-
164
-		return is_resource($this->handler);
165
-	}
166
-
167
-	/**
168
-	 * Creates the file.
169
-	 * 
170
-	 * @param  string  $path
171
-	 * 
172
-	 * @return bool
173
-	 */
174
-	public function create($path)
175
-	{
176
-		if (($this->isDirectory($path)) && ($this->isWritable($path)) || ! $this->exists($path)) {
177
-			if (touch($path)) {
178
-				return true;
179
-			}
180
-		}
181
-
182
-		return false;
183
-	}
184
-
185
-	/**
186
-	 * Determine if a file exists.
187
-	 *
188
-	 * @param  string  $path
189
-	 *
190
-	 * @return bool
191
-	 */
192
-	public function exists($path)
193
-	{
194
-		$this->clearStatCache($path);
195
-
196
-		return file_exists($path);
197
-	}
198
-
199
-	/**
200
-	 * Clear PHP's internal stat cache.
201
-	 *
202
-	 * @param  string  $path
203
-	 * @param  bool  $all  Clear all cache or not
204
-	 *
205
-	 * @return void
206
-	 */
207
-	public function clearStatCache($path, $all = false)
208
-	{
209
-		if ($all === false) {
210
-			clearstatcache(true, $path);
211
-		}
212
-
213
-		clearstatcache();
214
-	}
215
-
216
-	/**
217
-	 * Get the returned value of a file.
218
-	 * 
219
-	 * @param  string  $path
220
-	 * @param  array  $data
221
-	 * 
222
-	 * @return mixed
223
-	 * 
224
-	 * @throws \Syscodes\Filesystem\Exceptions\FileNotFoundException
225
-	 */
226
-	public function getRequire($path, array $data = [])
227
-	{
228
-		if ($this->isFile($path)) {
229
-			$__path = $path;
230
-			$__data = $data;
231
-
232
-			return (static function () use ($__path, $__data) {
233
-				extract($__data, EXTR_SKIP);
234
-
235
-				return require $__path;
236
-			})();
237
-		}
238
-
239
-		throw new FileNotFoundException($path);
240
-	}
241
-
242
-	/**
243
-	 * Require the given file once.
244
-	 * 
245
-	 * @param  string  $path
246
-	 * @param  array  $data
247
-	 * 
248
-	 * @return mixed
249
-	 * 
250
-	 * @throws \Syscodes\Filesystem\Exceptions\FileNotFoundException
251
-	 */
252
-	public function getRequireOnce($path, array $data = [])
253
-	{
254
-		if ($this->isFile($path)) {
255
-			$__path = $path;
256
-			$__data = $data;
257
-
258
-			return (static function () use ($__path, $__data) {
259
-				extract($__data, EXTR_SKIP);
260
-
261
-				return require_once $__path;
262
-			})();
263
-		}
264
-
265
-		throw new FileNotFoundException($path);
266
-	}
267
-
268
-	/**
269
-	 * Retrieve the file size.
270
-	 *
271
-	 * Implementations SHOULD return the value stored in the "size" key of
272
-	 * the file in the $_FILES array if available, as PHP calculates this
273
-	 * based on the actual size transmitted.
274
-	 *
275
-	 * @param  string  $path
276
-	 * @param  string  $unit  ('b' by default)
277
-	 * 
278
-	 * @return int|null  The file size in bytes or null if unknown
279
-	 */
280
-	public function getSize($path, $unit = 'b')
281
-	{
282
-		if ($this->exists($path)) {
283
-			if (is_null($this->size)) {
284
-				$this->size = filesize($path);
285
-			}
286
-
287
-			switch (strtolower($unit)) {
288
-				case 'kb':
289
-					return number_format($this->size / 1024, 3);
290
-					break;
291
-				case 'mb':
292
-					return number_format(($this->size / 1024) / 1024, 3);     
293
-					break;
294
-			}
295
-
296
-			return $this->size;
297
-		}
298
-	}
127
+                    while ( ! feof($this->handler)) {
128
+                        $contents .= fgets($this->handler, 4096);
129
+                    }
130
+
131
+                    flock($this->handler, LOCK_UN);
132
+                }
133
+            } finally {
134
+                $this->close();
135
+            }
136
+        }
137
+
138
+        return trim($contents);
139
+    }
140
+
141
+    /**
142
+     * Opens the current file with a given $mode.
143
+     *
144
+     * @param  string  $path
145
+     * @param  string  $mode  A valid 'fopen' mode string (r|w|a ...)
146
+     * @param  bool  $force  
147
+     *
148
+     * @return bool
149
+     */
150
+    public function open($path, $mode, $force = false)
151
+    {
152
+        if ( ! $force && is_resource($this->handler)) {
153
+            return true;
154
+        }
155
+
156
+        if ($this->exists($path) === false) {
157
+            if ($this->create($path) === false) {
158
+                return false;
159
+            }
160
+        }
161
+
162
+        $this->handler = fopen($path, $mode);
163
+
164
+        return is_resource($this->handler);
165
+    }
166
+
167
+    /**
168
+     * Creates the file.
169
+     * 
170
+     * @param  string  $path
171
+     * 
172
+     * @return bool
173
+     */
174
+    public function create($path)
175
+    {
176
+        if (($this->isDirectory($path)) && ($this->isWritable($path)) || ! $this->exists($path)) {
177
+            if (touch($path)) {
178
+                return true;
179
+            }
180
+        }
181
+
182
+        return false;
183
+    }
184
+
185
+    /**
186
+     * Determine if a file exists.
187
+     *
188
+     * @param  string  $path
189
+     *
190
+     * @return bool
191
+     */
192
+    public function exists($path)
193
+    {
194
+        $this->clearStatCache($path);
195
+
196
+        return file_exists($path);
197
+    }
198
+
199
+    /**
200
+     * Clear PHP's internal stat cache.
201
+     *
202
+     * @param  string  $path
203
+     * @param  bool  $all  Clear all cache or not
204
+     *
205
+     * @return void
206
+     */
207
+    public function clearStatCache($path, $all = false)
208
+    {
209
+        if ($all === false) {
210
+            clearstatcache(true, $path);
211
+        }
212
+
213
+        clearstatcache();
214
+    }
215
+
216
+    /**
217
+     * Get the returned value of a file.
218
+     * 
219
+     * @param  string  $path
220
+     * @param  array  $data
221
+     * 
222
+     * @return mixed
223
+     * 
224
+     * @throws \Syscodes\Filesystem\Exceptions\FileNotFoundException
225
+     */
226
+    public function getRequire($path, array $data = [])
227
+    {
228
+        if ($this->isFile($path)) {
229
+            $__path = $path;
230
+            $__data = $data;
231
+
232
+            return (static function () use ($__path, $__data) {
233
+                extract($__data, EXTR_SKIP);
234
+
235
+                return require $__path;
236
+            })();
237
+        }
238
+
239
+        throw new FileNotFoundException($path);
240
+    }
241
+
242
+    /**
243
+     * Require the given file once.
244
+     * 
245
+     * @param  string  $path
246
+     * @param  array  $data
247
+     * 
248
+     * @return mixed
249
+     * 
250
+     * @throws \Syscodes\Filesystem\Exceptions\FileNotFoundException
251
+     */
252
+    public function getRequireOnce($path, array $data = [])
253
+    {
254
+        if ($this->isFile($path)) {
255
+            $__path = $path;
256
+            $__data = $data;
257
+
258
+            return (static function () use ($__path, $__data) {
259
+                extract($__data, EXTR_SKIP);
260
+
261
+                return require_once $__path;
262
+            })();
263
+        }
264
+
265
+        throw new FileNotFoundException($path);
266
+    }
267
+
268
+    /**
269
+     * Retrieve the file size.
270
+     *
271
+     * Implementations SHOULD return the value stored in the "size" key of
272
+     * the file in the $_FILES array if available, as PHP calculates this
273
+     * based on the actual size transmitted.
274
+     *
275
+     * @param  string  $path
276
+     * @param  string  $unit  ('b' by default)
277
+     * 
278
+     * @return int|null  The file size in bytes or null if unknown
279
+     */
280
+    public function getSize($path, $unit = 'b')
281
+    {
282
+        if ($this->exists($path)) {
283
+            if (is_null($this->size)) {
284
+                $this->size = filesize($path);
285
+            }
286
+
287
+            switch (strtolower($unit)) {
288
+                case 'kb':
289
+                    return number_format($this->size / 1024, 3);
290
+                    break;
291
+                case 'mb':
292
+                    return number_format(($this->size / 1024) / 1024, 3);     
293
+                    break;
294
+            }
295
+
296
+            return $this->size;
297
+        }
298
+    }
299 299
 	
300
-	/**
301
-	 * Returns the file's group.
302
-	 *
303
-	 * @param  string  $path
304
-	 * 
305
-	 * @return int|bool  The file group, or false in case of an error
306
-	 */
307
-	public function group($path)
308
-	{
309
-		if ($this->exists($path)) {
310
-			return filegroup($path);
311
-		}
312
-
313
-		return false;
314
-	}
300
+    /**
301
+     * Returns the file's group.
302
+     *
303
+     * @param  string  $path
304
+     * 
305
+     * @return int|bool  The file group, or false in case of an error
306
+     */
307
+    public function group($path)
308
+    {
309
+        if ($this->exists($path)) {
310
+            return filegroup($path);
311
+        }
312
+
313
+        return false;
314
+    }
315 315
 	
316
-	/**
317
-	 * Returns true if the file is executable.
318
-	 *
319
-	 * @param  string  $path
320
-	 * 
321
-	 * @return bool  True if file is executable, false otherwise
322
-	 */
323
-	public function exec($path)
324
-	{
325
-		return is_executable($path);
326
-	}
327
-
328
-	/**
329
-	 * Determine if the given path is a directory.
330
-	 *
331
-	 * @param  string  $directory
332
-	 *
333
-	 * @return bool
334
-	 */
335
-	public function isDirectory($directory)
336
-	{
337
-		return is_dir($directory);
338
-	}
339
-
340
-	/**
341
-	 * Determine if the given path is a file.
342
-	 *
343
-	 * @param  string  $file
344
-	 *
345
-	 * @return bool
346
-	 */
347
-	public function isFile($file)
348
-	{
349
-		return is_file($file);
350
-	}
351
-
352
-	/**
353
-	 * Determine if the given path is writable.
354
-	 * 
355
-	 * @param  string  $path
356
-	 * 
357
-	 * @return bool
358
-	 */
359
-	public function isWritable($path)
360
-	{
361
-		return is_writable($path);
362
-	}
363
-
364
-	/**
365
-	 * Returns if true the file is readable.
366
-	 *
367
-	 * @param  string  $path
368
-	 * 
369
-	 * @return bool  True if file is readable, false otherwise
370
-	 */
371
-	public function isReadable($path)
372
-	{
373
-		return is_readable($path);
374
-	}
375
-
376
-	/**
377
-	 * Returns last access time.
378
-	 *
379
-	 * @param  string  $path
380
-	 * 
381
-	 * @return int|bool  Timestamp of last access time, or false in case of an error
382
-	 */
383
-	public function lastAccess($path)
384
-	{
385
-		if ($this->exists($path)) {
386
-			return fileatime($path);
387
-		}
388
-
389
-		return false;
390
-	}
391
-
392
-	/**
393
-	 * Returns last modified time.
394
-	 *
395
-	 * @param  string  $path
396
-	 * 
397
-	 * @return int|bool  Timestamp of last modified time, or false in case of an error
398
-	 */
399
-	public function lastModified($path)
400
-	{
401
-		if ($this->exists($path)) {
402
-			return filemtime($path);
403
-		}
404
-
405
-		return false;
406
-	}
407
-
408
-	/**
409
-	 * Get all of the directories within a given directory.
410
-	 * 
411
-	 * @param  string  $directory
412
-	 * 
413
-	 * @return array
414
-	 */
415
-	public function directories($directory)
416
-	{
417
-		$directories = [];
418
-
419
-		$iterators = new FilesystemIterator($directory);
420
-
421
-		foreach ($iterators as $iterator) {
422
-			$directories[] = trim($iterator->getPathname(), '/').'/';
423
-		}
424
-
425
-		return $directories;
426
-	}
427
-
428
-	/**
429
-	 * Delete the file at a given path.
430
-	 * 
431
-	 * @param  string  $paths
432
-	 * 
433
-	 * @return bool
434
-	 */
435
-	public function delete($paths)
436
-	{
437
-		if (is_resource($this->handler)) {
438
-			fclose($this->handler);
439
-			$this->handler = null;
440
-		}
441
-
442
-		$paths = is_array($paths) ? $paths : func_get_args();
443
-
444
-		$success = true;
445
-
446
-		foreach ($paths as $path) {
447
-			try {
448
-				if ( ! @unlink($path)) {
449
-					return $success = false;
450
-				}
451
-			} catch (ErrorException $e) {
452
-				return $success = false;
453
-			}
454
-		}
455
-
456
-		return $success;
457
-	}
458
-
459
-	/**
460
-	 * Create a directory.
461
-	 *
462
-	 * @param  string  $path
463
-	 * @param  int  $mode
464
-	 * @param  bool  $recursive
465
-	 * @param  bool  $force
466
-	 *
467
-	 * @return bool
468
-	 * 
469
-	 * @throws FileException
470
-	 */
471
-	public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false)
472
-	{
473
-		if ($force) {
474
-			return @mkdir($path, $mode, $recursive);
475
-		}
476
-
477
-		mkdir($path, $mode, $recursive);
478
-	}
479
-
480
-	/**
481
-	 * Copy a directory from one location to another.
482
-	 * 
483
-	 * @param  string  $directory
484
-	 * @param  string  $destination
485
-	 * @param  int  $options  (null by default)
486
-	 * 
487
-	 * @return bool
488
-	 */
489
-	public function copyDirectory($directory, $destination, $options = null)
490
-	{
491
-		if ( ! $this->isDirectory($directory)) return false;
492
-
493
-		$options = $options ?: FilesystemIterator::SKIP_DOTS;
316
+    /**
317
+     * Returns true if the file is executable.
318
+     *
319
+     * @param  string  $path
320
+     * 
321
+     * @return bool  True if file is executable, false otherwise
322
+     */
323
+    public function exec($path)
324
+    {
325
+        return is_executable($path);
326
+    }
327
+
328
+    /**
329
+     * Determine if the given path is a directory.
330
+     *
331
+     * @param  string  $directory
332
+     *
333
+     * @return bool
334
+     */
335
+    public function isDirectory($directory)
336
+    {
337
+        return is_dir($directory);
338
+    }
339
+
340
+    /**
341
+     * Determine if the given path is a file.
342
+     *
343
+     * @param  string  $file
344
+     *
345
+     * @return bool
346
+     */
347
+    public function isFile($file)
348
+    {
349
+        return is_file($file);
350
+    }
351
+
352
+    /**
353
+     * Determine if the given path is writable.
354
+     * 
355
+     * @param  string  $path
356
+     * 
357
+     * @return bool
358
+     */
359
+    public function isWritable($path)
360
+    {
361
+        return is_writable($path);
362
+    }
363
+
364
+    /**
365
+     * Returns if true the file is readable.
366
+     *
367
+     * @param  string  $path
368
+     * 
369
+     * @return bool  True if file is readable, false otherwise
370
+     */
371
+    public function isReadable($path)
372
+    {
373
+        return is_readable($path);
374
+    }
375
+
376
+    /**
377
+     * Returns last access time.
378
+     *
379
+     * @param  string  $path
380
+     * 
381
+     * @return int|bool  Timestamp of last access time, or false in case of an error
382
+     */
383
+    public function lastAccess($path)
384
+    {
385
+        if ($this->exists($path)) {
386
+            return fileatime($path);
387
+        }
388
+
389
+        return false;
390
+    }
391
+
392
+    /**
393
+     * Returns last modified time.
394
+     *
395
+     * @param  string  $path
396
+     * 
397
+     * @return int|bool  Timestamp of last modified time, or false in case of an error
398
+     */
399
+    public function lastModified($path)
400
+    {
401
+        if ($this->exists($path)) {
402
+            return filemtime($path);
403
+        }
404
+
405
+        return false;
406
+    }
407
+
408
+    /**
409
+     * Get all of the directories within a given directory.
410
+     * 
411
+     * @param  string  $directory
412
+     * 
413
+     * @return array
414
+     */
415
+    public function directories($directory)
416
+    {
417
+        $directories = [];
418
+
419
+        $iterators = new FilesystemIterator($directory);
420
+
421
+        foreach ($iterators as $iterator) {
422
+            $directories[] = trim($iterator->getPathname(), '/').'/';
423
+        }
424
+
425
+        return $directories;
426
+    }
427
+
428
+    /**
429
+     * Delete the file at a given path.
430
+     * 
431
+     * @param  string  $paths
432
+     * 
433
+     * @return bool
434
+     */
435
+    public function delete($paths)
436
+    {
437
+        if (is_resource($this->handler)) {
438
+            fclose($this->handler);
439
+            $this->handler = null;
440
+        }
441
+
442
+        $paths = is_array($paths) ? $paths : func_get_args();
443
+
444
+        $success = true;
445
+
446
+        foreach ($paths as $path) {
447
+            try {
448
+                if ( ! @unlink($path)) {
449
+                    return $success = false;
450
+                }
451
+            } catch (ErrorException $e) {
452
+                return $success = false;
453
+            }
454
+        }
455
+
456
+        return $success;
457
+    }
458
+
459
+    /**
460
+     * Create a directory.
461
+     *
462
+     * @param  string  $path
463
+     * @param  int  $mode
464
+     * @param  bool  $recursive
465
+     * @param  bool  $force
466
+     *
467
+     * @return bool
468
+     * 
469
+     * @throws FileException
470
+     */
471
+    public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false)
472
+    {
473
+        if ($force) {
474
+            return @mkdir($path, $mode, $recursive);
475
+        }
476
+
477
+        mkdir($path, $mode, $recursive);
478
+    }
479
+
480
+    /**
481
+     * Copy a directory from one location to another.
482
+     * 
483
+     * @param  string  $directory
484
+     * @param  string  $destination
485
+     * @param  int  $options  (null by default)
486
+     * 
487
+     * @return bool
488
+     */
489
+    public function copyDirectory($directory, $destination, $options = null)
490
+    {
491
+        if ( ! $this->isDirectory($directory)) return false;
492
+
493
+        $options = $options ?: FilesystemIterator::SKIP_DOTS;
494 494
 		
495
-		// If the destination directory does not actually exist, we will go ahead and
496
-		// create it recursively, which just gets the destination prepared to copy
497
-		// the files over. Once we make the directory we'll proceed the copying.
498
-		if ( ! $this->isdirectory($destination)) {
499
-			$this->makeDirectory($destination, 0777, true);
500
-		}
495
+        // If the destination directory does not actually exist, we will go ahead and
496
+        // create it recursively, which just gets the destination prepared to copy
497
+        // the files over. Once we make the directory we'll proceed the copying.
498
+        if ( ! $this->isdirectory($destination)) {
499
+            $this->makeDirectory($destination, 0777, true);
500
+        }
501 501
 
502
-		$iterators = new FilesystemIterator($directory, $options);
502
+        $iterators = new FilesystemIterator($directory, $options);
503 503
 
504
-		foreach ($iterators as $iterator) {
505
-			$target = $destination.DIRECTORY_SEPARATOR.$iterator->getBasename();
504
+        foreach ($iterators as $iterator) {
505
+            $target = $destination.DIRECTORY_SEPARATOR.$iterator->getBasename();
506 506
 			
507
-			// As we spin through items, we will check to see if the current file is actually
507
+            // As we spin through items, we will check to see if the current file is actually
508 508
             // a directory or a file. When it is actually a directory we will need to call
509 509
             // back into this function recursively to keep copying these nested folders.
510
-			if ($iterator->isDir()) {
511
-				if ( ! $this->copyDirectory($iterator->getPathname(), $target, $options)) return false;
512
-			}
513
-			// If the current items is just a regular file, we will just copy this to the new
514
-			// location and keep looping. If for some reason the copy fails we'll bail out
515
-			// and return false, so the developer is aware that the copy process failed.
516
-			else {
517
-				if ( ! $this->copy($iterator->getPathname(), $target)) return false;
518
-			}
519
-		}
520
-
521
-		return true;
522
-	}
523
-
524
-	/**
525
-	 * Recursively delete a directory and optionally you can keep 
526
-	 * the directory if you wish.
527
-	 * 
528
-	 * @param  string  $directory
529
-	 * @param  bool  $keep
530
-	 * 
531
-	 * @return bool
532
-	 */
533
-	public function deleteDirectory($directory, $keep = false)
534
-	{
535
-		if ( ! $this->isDirectory($directory)) return false;
536
-
537
-		$iterators = new filesystemIterator($directory);
538
-
539
-		foreach ($iterators as $iterator) {
540
-			// If the item is a directory, we can just recurse into the function and delete 
541
-			// that sub-directory otherwise we'll just delete the file and keep iterating 
542
-			// through each file until the directory is cleaned.
543
-			if ($iterator->isDir() && ! $iterator->isLink()) {
544
-				$this->deleteDirectory($iterator->getPathname());
545
-			}
546
-			// If the item is just a file, we can go ahead and delete it since we're
547
-			// just looping through and waxing all of the files in this directory
548
-			// and calling directories recursively, so we delete the real path.
549
-			else {
550
-				$this->delete($iterator->getPathname());
551
-			}
552
-		}
553
-
554
-		if ( ! $keep) @rmdir($directory);
555
-
556
-		return true;
557
-	}
558
-
559
-	/**
560
-	 * Empty the specified directory of all files and folders.
561
-	 * 
562
-	 * 
563
-	 * @param  string  $directory
564
-	 * 
565
-	 * @return bool
566
-	 */
567
-	public function cleanDirectory($directory)
568
-	{
569
-		return $this->deleteDirectory($directory, true);
570
-	}
571
-
572
-	/**
573
-	 * Moves a file to a new location.
574
-	 * 
575
-	 * @param  string  $from
576
-	 * @param  string  $to
577
-	 * @param  bool  $overwrite  (false by default)
578
-	 * 
579
-	 * @return bool
580
-	 */
581
-	public function moveDirectory($from, $to, $overwrite = false)
582
-	{
583
-		if ($overwrite && $this->isDirectory($to) && ! $this->deleteDirectory($to)) return false;
584
-
585
-		if (false === @rename($from, $to)) {
586
-			$error = error_get_last();
587
-
588
-			throw new FileUnableToMoveException($from, $to, strip_tags($error['message']));
589
-		}
590
-
591
-		$this->perms($to, 0777 & ~umask());
592
-	}
593
-
594
-	/**
595
-	 * Attempts to determine the file extension based on the trusted
596
-	 * getType() method. If the mime type is unknown, will return null.
597
-	 * 
598
-	 * @param  string  $path
599
-	 * 
600
-	 * @return string|null
601
-	 */
602
-	public function guessExtension($path)
603
-	{
604
-		return FileMimeType::guessExtensionFromType($this->getMimeType($path));
605
-	}
606
-
607
-	/**
608
-	 * Retrieve the media type of the file. 
609
-	 * 
610
-	 * @param  string  $path
611
-	 * 
612
-	 * @return string|null
613
-	 */
614
-	public function getMimeType($path)
615
-	{
616
-		$finfo    = finfo_open(FILEINFO_MIME_TYPE);
617
-		$mimeType = finfo_file($finfo, $path);
618
-
619
-		finfo_close($finfo);
620
-
621
-		return $mimeType;
622
-	}
623
-
624
-	/**
625
-	 * Move a file to a new location.
626
-	 *
627
-	 * @param  string  $path
628
-	 * @param  string  $target
629
-	 *
630
-	 * @return bool
631
-	 */
632
-	public function move($path, $target)
633
-	{
634
-		if ($this->exists($path)) {
635
-			return rename($path, $target);
636
-		}
637
-	}
638
-
639
-	/**
640
-	 * Extract the file name from a file path.
641
-	 * 
642
-	 * @param  string  $path
643
-	 * 
644
-	 * @return string
645
-	 */
646
-	public function name($path)
647
-	{
648
-		return pathinfo($path, PATHINFO_FILENAME);
649
-	}
650
-
651
-	/**
652
-	 * Extract the trailing name component from a file path.
653
-	 * 
654
-	 * @param  string  $path
655
-	 * 
656
-	 * @return string
657
-	 */
658
-	public function basename($path)
659
-	{
660
-		return pathinfo($path, PATHINFO_BASENAME);
661
-	}
662
-
663
-	/**
664
-	 * Extract the parent directory from a file path.
665
-	 * 
666
-	 * @param  string  $path
667
-	 * 
668
-	 * @return string
669
-	 */
670
-	public function dirname($path)
671
-	{
672
-		return pathinfo($path, PATHINFO_DIRNAME);
673
-	}
674
-
675
-	/**
676
-	 * Extract the file extension from a file path.
677
-	 * 
678
-	 * @param  string  $path
679
-	 * 
680
-	 * @return string
681
-	 */
682
-	public function extension($path)
683
-	{
684
-		return pathinfo($path, PATHINFO_EXTENSION);
685
-	}
686
-
687
-	/**
688
-	 *  Find path names matching a given pattern.
689
-	 * 
690
-	 * @param  string  $pattern
691
-	 * @param  int  $flags  (0 by default)
692
-	 * 
693
-	 * @return array
694
-	 */
695
-	public function glob($pattern, $flags = 0)
696
-	{
697
-		return glob($pattern, $flags);
698
-	}
699
-
700
-	/**
701
-	 * Returns the file's owner.
702
-	 *
703
-	 * @param  string  $path
704
-	 * 
705
-	 * @return int|bool  The file owner, or false in case of an error
706
-	 */
707
-	public function owner($path)
708
-	{
709
-		if ($this->exists($path)) {
710
-			return fileowner($path);
711
-		}
712
-
713
-		return false;
714
-	}
715
-
716
-	/**
717
-	 * Returns the "chmod" (permissions) of the file.
718
-	 *
719
-	 * @param  string  $path
720
-	 * @param  int|null  $mode  (null by default)
721
-	 * 
722
-	 * @return mixed  Permissions for the file, or false in case of an error
723
-	 */
724
-	public function perms($path, $mode = null)
725
-	{
726
-		if ($mode) {
727
-			chmod($path, $mode);
728
-		}
729
-
730
-		return substr(sprintf('%o', fileperms($path)), -4);
731
-	}
732
-
733
-	/**
734
-	 * Prepend to a file.
735
-	 * 
736
-	 * @param  string  $path
737
-	 * @param  string  $data
738
-	 * 
739
-	 * @return int
740
-	 */
741
-	public function prepend($path, $data)
742
-	{
743
-		if ($this->exists($path)) {
744
-			$this->put($path, $data.$this->get($path));
745
-		}
746
-
747
-		return $this->put($path, $data);
748
-	}
749
-
750
-	/**
751
-	 * Write the content of a file.
752
-	 *
753
-	 * @param  string  $path
754
-	 * @param  string  $contents
755
-	 * @param  bool  $lock  (false by default)
756
-	 *
757
-	 * @return int
758
-	 */
759
-	public function put($path, $contents, $lock = false)
760
-	{
761
-		return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
762
-	}
763
-
764
-	/**
765
-	 * Get the file type of a given file.
766
-	 * 
767
-	 * @param  string  $path
768
-	 * 
769
-	 * @return string
770
-	 */
771
-	public function type($path)
772
-	{
773
-		return filetype($path);
774
-	}
775
-
776
-	/**
777
-	 * Searches for a given text and replaces the text if found.
778
-	 *
779
-	 * @param  string  $path
780
-	 * @param  string  $search
781
-	 * @param  string  $replace
782
-	 *
783
-	 * @return bool
784
-	 */
785
-	public function replaceText($path, $search, $replace)
786
-	{
787
-		if ( ! $this->open($path, 'r+')) {
788
-			return false;
789
-		}
790
-
791
-		if ($this->lock !== null) {
792
-			if (flock($this->handler, LOCK_EX) === false)
793
-			{
794
-				return false;
795
-			}
796
-		}
797
-
798
-		$replaced = $this->write($path, str_replace($search, $replace, $this->get($path)), true);
799
-
800
-		if ($this->lock !== null) {
801
-			flock($this->handler, LOCK_UN);
802
-		}
803
-
804
-		$this->close();
805
-
806
-		return $replaced;
807
-	}	
808
-
809
-	/**
810
-	 * Closes the current file if it is opened.
811
-	 *
812
-	 * @return bool
813
-	 */
814
-	public function close()
815
-	{
816
-		if ( ! is_resource($this->handler)) {
817
-			return true;
818
-		}
819
-
820
-		return fclose($this->handler);
821
-	}
822
-
823
-	/**
824
-	 * Write given data to this file.
825
-	 *
826
-	 * @param  string  $path
827
-	 * @param  string  $data  Data to write to this File
828
-	 * @param  bool  $force  The file to open
829
-	 *
830
-	 * @return bool
831
-	 */
832
-	public function write($path, $data, $force = false)
833
-	{
834
-		$success = false;
835
-
836
-		if ($this->open($path, 'w', $force) === true) {
837
-			if ($this->lock !== null) {
838
-				if (flock($this->handler, LOCK_EX) === false) {
839
-					return false;
840
-				}
841
-			}
842
-
843
-			if (fwrite($this->handler, $data) !== false) {
844
-				$success = true;
845
-			}
846
-
847
-			if ($this->lock !== null) {
848
-				flock($this->handler, LOCK_UN);
849
-			}
850
-		}
851
-
852
-		return $success;
853
-	}
510
+            if ($iterator->isDir()) {
511
+                if ( ! $this->copyDirectory($iterator->getPathname(), $target, $options)) return false;
512
+            }
513
+            // If the current items is just a regular file, we will just copy this to the new
514
+            // location and keep looping. If for some reason the copy fails we'll bail out
515
+            // and return false, so the developer is aware that the copy process failed.
516
+            else {
517
+                if ( ! $this->copy($iterator->getPathname(), $target)) return false;
518
+            }
519
+        }
520
+
521
+        return true;
522
+    }
523
+
524
+    /**
525
+     * Recursively delete a directory and optionally you can keep 
526
+     * the directory if you wish.
527
+     * 
528
+     * @param  string  $directory
529
+     * @param  bool  $keep
530
+     * 
531
+     * @return bool
532
+     */
533
+    public function deleteDirectory($directory, $keep = false)
534
+    {
535
+        if ( ! $this->isDirectory($directory)) return false;
536
+
537
+        $iterators = new filesystemIterator($directory);
538
+
539
+        foreach ($iterators as $iterator) {
540
+            // If the item is a directory, we can just recurse into the function and delete 
541
+            // that sub-directory otherwise we'll just delete the file and keep iterating 
542
+            // through each file until the directory is cleaned.
543
+            if ($iterator->isDir() && ! $iterator->isLink()) {
544
+                $this->deleteDirectory($iterator->getPathname());
545
+            }
546
+            // If the item is just a file, we can go ahead and delete it since we're
547
+            // just looping through and waxing all of the files in this directory
548
+            // and calling directories recursively, so we delete the real path.
549
+            else {
550
+                $this->delete($iterator->getPathname());
551
+            }
552
+        }
553
+
554
+        if ( ! $keep) @rmdir($directory);
555
+
556
+        return true;
557
+    }
558
+
559
+    /**
560
+     * Empty the specified directory of all files and folders.
561
+     * 
562
+     * 
563
+     * @param  string  $directory
564
+     * 
565
+     * @return bool
566
+     */
567
+    public function cleanDirectory($directory)
568
+    {
569
+        return $this->deleteDirectory($directory, true);
570
+    }
571
+
572
+    /**
573
+     * Moves a file to a new location.
574
+     * 
575
+     * @param  string  $from
576
+     * @param  string  $to
577
+     * @param  bool  $overwrite  (false by default)
578
+     * 
579
+     * @return bool
580
+     */
581
+    public function moveDirectory($from, $to, $overwrite = false)
582
+    {
583
+        if ($overwrite && $this->isDirectory($to) && ! $this->deleteDirectory($to)) return false;
584
+
585
+        if (false === @rename($from, $to)) {
586
+            $error = error_get_last();
587
+
588
+            throw new FileUnableToMoveException($from, $to, strip_tags($error['message']));
589
+        }
590
+
591
+        $this->perms($to, 0777 & ~umask());
592
+    }
593
+
594
+    /**
595
+     * Attempts to determine the file extension based on the trusted
596
+     * getType() method. If the mime type is unknown, will return null.
597
+     * 
598
+     * @param  string  $path
599
+     * 
600
+     * @return string|null
601
+     */
602
+    public function guessExtension($path)
603
+    {
604
+        return FileMimeType::guessExtensionFromType($this->getMimeType($path));
605
+    }
606
+
607
+    /**
608
+     * Retrieve the media type of the file. 
609
+     * 
610
+     * @param  string  $path
611
+     * 
612
+     * @return string|null
613
+     */
614
+    public function getMimeType($path)
615
+    {
616
+        $finfo    = finfo_open(FILEINFO_MIME_TYPE);
617
+        $mimeType = finfo_file($finfo, $path);
618
+
619
+        finfo_close($finfo);
620
+
621
+        return $mimeType;
622
+    }
623
+
624
+    /**
625
+     * Move a file to a new location.
626
+     *
627
+     * @param  string  $path
628
+     * @param  string  $target
629
+     *
630
+     * @return bool
631
+     */
632
+    public function move($path, $target)
633
+    {
634
+        if ($this->exists($path)) {
635
+            return rename($path, $target);
636
+        }
637
+    }
638
+
639
+    /**
640
+     * Extract the file name from a file path.
641
+     * 
642
+     * @param  string  $path
643
+     * 
644
+     * @return string
645
+     */
646
+    public function name($path)
647
+    {
648
+        return pathinfo($path, PATHINFO_FILENAME);
649
+    }
650
+
651
+    /**
652
+     * Extract the trailing name component from a file path.
653
+     * 
654
+     * @param  string  $path
655
+     * 
656
+     * @return string
657
+     */
658
+    public function basename($path)
659
+    {
660
+        return pathinfo($path, PATHINFO_BASENAME);
661
+    }
662
+
663
+    /**
664
+     * Extract the parent directory from a file path.
665
+     * 
666
+     * @param  string  $path
667
+     * 
668
+     * @return string
669
+     */
670
+    public function dirname($path)
671
+    {
672
+        return pathinfo($path, PATHINFO_DIRNAME);
673
+    }
674
+
675
+    /**
676
+     * Extract the file extension from a file path.
677
+     * 
678
+     * @param  string  $path
679
+     * 
680
+     * @return string
681
+     */
682
+    public function extension($path)
683
+    {
684
+        return pathinfo($path, PATHINFO_EXTENSION);
685
+    }
686
+
687
+    /**
688
+     *  Find path names matching a given pattern.
689
+     * 
690
+     * @param  string  $pattern
691
+     * @param  int  $flags  (0 by default)
692
+     * 
693
+     * @return array
694
+     */
695
+    public function glob($pattern, $flags = 0)
696
+    {
697
+        return glob($pattern, $flags);
698
+    }
699
+
700
+    /**
701
+     * Returns the file's owner.
702
+     *
703
+     * @param  string  $path
704
+     * 
705
+     * @return int|bool  The file owner, or false in case of an error
706
+     */
707
+    public function owner($path)
708
+    {
709
+        if ($this->exists($path)) {
710
+            return fileowner($path);
711
+        }
712
+
713
+        return false;
714
+    }
715
+
716
+    /**
717
+     * Returns the "chmod" (permissions) of the file.
718
+     *
719
+     * @param  string  $path
720
+     * @param  int|null  $mode  (null by default)
721
+     * 
722
+     * @return mixed  Permissions for the file, or false in case of an error
723
+     */
724
+    public function perms($path, $mode = null)
725
+    {
726
+        if ($mode) {
727
+            chmod($path, $mode);
728
+        }
729
+
730
+        return substr(sprintf('%o', fileperms($path)), -4);
731
+    }
732
+
733
+    /**
734
+     * Prepend to a file.
735
+     * 
736
+     * @param  string  $path
737
+     * @param  string  $data
738
+     * 
739
+     * @return int
740
+     */
741
+    public function prepend($path, $data)
742
+    {
743
+        if ($this->exists($path)) {
744
+            $this->put($path, $data.$this->get($path));
745
+        }
746
+
747
+        return $this->put($path, $data);
748
+    }
749
+
750
+    /**
751
+     * Write the content of a file.
752
+     *
753
+     * @param  string  $path
754
+     * @param  string  $contents
755
+     * @param  bool  $lock  (false by default)
756
+     *
757
+     * @return int
758
+     */
759
+    public function put($path, $contents, $lock = false)
760
+    {
761
+        return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
762
+    }
763
+
764
+    /**
765
+     * Get the file type of a given file.
766
+     * 
767
+     * @param  string  $path
768
+     * 
769
+     * @return string
770
+     */
771
+    public function type($path)
772
+    {
773
+        return filetype($path);
774
+    }
775
+
776
+    /**
777
+     * Searches for a given text and replaces the text if found.
778
+     *
779
+     * @param  string  $path
780
+     * @param  string  $search
781
+     * @param  string  $replace
782
+     *
783
+     * @return bool
784
+     */
785
+    public function replaceText($path, $search, $replace)
786
+    {
787
+        if ( ! $this->open($path, 'r+')) {
788
+            return false;
789
+        }
790
+
791
+        if ($this->lock !== null) {
792
+            if (flock($this->handler, LOCK_EX) === false)
793
+            {
794
+                return false;
795
+            }
796
+        }
797
+
798
+        $replaced = $this->write($path, str_replace($search, $replace, $this->get($path)), true);
799
+
800
+        if ($this->lock !== null) {
801
+            flock($this->handler, LOCK_UN);
802
+        }
803
+
804
+        $this->close();
805
+
806
+        return $replaced;
807
+    }	
808
+
809
+    /**
810
+     * Closes the current file if it is opened.
811
+     *
812
+     * @return bool
813
+     */
814
+    public function close()
815
+    {
816
+        if ( ! is_resource($this->handler)) {
817
+            return true;
818
+        }
819
+
820
+        return fclose($this->handler);
821
+    }
822
+
823
+    /**
824
+     * Write given data to this file.
825
+     *
826
+     * @param  string  $path
827
+     * @param  string  $data  Data to write to this File
828
+     * @param  bool  $force  The file to open
829
+     *
830
+     * @return bool
831
+     */
832
+    public function write($path, $data, $force = false)
833
+    {
834
+        $success = false;
835
+
836
+        if ($this->open($path, 'w', $force) === true) {
837
+            if ($this->lock !== null) {
838
+                if (flock($this->handler, LOCK_EX) === false) {
839
+                    return false;
840
+                }
841
+            }
842
+
843
+            if (fwrite($this->handler, $data) !== false) {
844
+                $success = true;
845
+            }
846
+
847
+            if ($this->lock !== null) {
848
+                flock($this->handler, LOCK_UN);
849
+            }
850
+        }
851
+
852
+        return $success;
853
+    }
854 854
 }
855 855
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -488,7 +488,9 @@  discard block
 block discarded – undo
488 488
 	 */
489 489
 	public function copyDirectory($directory, $destination, $options = null)
490 490
 	{
491
-		if ( ! $this->isDirectory($directory)) return false;
491
+		if ( ! $this->isDirectory($directory)) {
492
+		    return false;
493
+		}
492 494
 
493 495
 		$options = $options ?: FilesystemIterator::SKIP_DOTS;
494 496
 		
@@ -508,13 +510,17 @@  discard block
 block discarded – undo
508 510
             // a directory or a file. When it is actually a directory we will need to call
509 511
             // back into this function recursively to keep copying these nested folders.
510 512
 			if ($iterator->isDir()) {
511
-				if ( ! $this->copyDirectory($iterator->getPathname(), $target, $options)) return false;
513
+				if ( ! $this->copyDirectory($iterator->getPathname(), $target, $options)) {
514
+				    return false;
515
+				}
512 516
 			}
513 517
 			// If the current items is just a regular file, we will just copy this to the new
514 518
 			// location and keep looping. If for some reason the copy fails we'll bail out
515 519
 			// and return false, so the developer is aware that the copy process failed.
516 520
 			else {
517
-				if ( ! $this->copy($iterator->getPathname(), $target)) return false;
521
+				if ( ! $this->copy($iterator->getPathname(), $target)) {
522
+				    return false;
523
+				}
518 524
 			}
519 525
 		}
520 526
 
@@ -532,7 +538,9 @@  discard block
 block discarded – undo
532 538
 	 */
533 539
 	public function deleteDirectory($directory, $keep = false)
534 540
 	{
535
-		if ( ! $this->isDirectory($directory)) return false;
541
+		if ( ! $this->isDirectory($directory)) {
542
+		    return false;
543
+		}
536 544
 
537 545
 		$iterators = new filesystemIterator($directory);
538 546
 
@@ -551,7 +559,9 @@  discard block
 block discarded – undo
551 559
 			}
552 560
 		}
553 561
 
554
-		if ( ! $keep) @rmdir($directory);
562
+		if ( ! $keep) {
563
+		    @rmdir($directory);
564
+		}
555 565
 
556 566
 		return true;
557 567
 	}
@@ -580,7 +590,9 @@  discard block
 block discarded – undo
580 590
 	 */
581 591
 	public function moveDirectory($from, $to, $overwrite = false)
582 592
 	{
583
-		if ($overwrite && $this->isDirectory($to) && ! $this->deleteDirectory($to)) return false;
593
+		if ($overwrite && $this->isDirectory($to) && ! $this->deleteDirectory($to)) {
594
+		    return false;
595
+		}
584 596
 
585 597
 		if (false === @rename($from, $to)) {
586 598
 			$error = error_get_last();
Please login to merge, or discard this patch.
src/components/Filesystem/FileMimeType.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -30,61 +30,61 @@
 block discarded – undo
30 30
  */
31 31
 class FileMimeType
32 32
 {
33
-	/**
34
-	 * Map of extensions to mime types.
35
-	 *
36
-	 * @var array $mimes
37
-	 */
38
-	public static $mimes = [];
33
+    /**
34
+     * Map of extensions to mime types.
35
+     *
36
+     * @var array $mimes
37
+     */
38
+    public static $mimes = [];
39 39
 
40
-	/**
41
-	 * Constructor with an optional verification that the path is 
42
-	 * really a mimes.
43
-	 *
44
-	 * @return mixed
45
-	 */
46
-	public function __construct()
47
-	{
48
-		static::$mimes = (array) require CON_PATH.'mimes.php';
49
-	}
40
+    /**
41
+     * Constructor with an optional verification that the path is 
42
+     * really a mimes.
43
+     *
44
+     * @return mixed
45
+     */
46
+    public function __construct()
47
+    {
48
+        static::$mimes = (array) require CON_PATH.'mimes.php';
49
+    }
50 50
 
51
-	/**
52
-	 * Attempts to determine the best mime type for the given file extension.
53
-	 *
54
-	 * @param  string  $extension
55
-	 *
56
-	 * @return string|null  The mime type found, or none if unable to determine
57
-	 */
58
-	public static function guessTypeFromExtension($extension)
59
-	{
60
-		$extension = trim(strtolower($extension), '. ');
51
+    /**
52
+     * Attempts to determine the best mime type for the given file extension.
53
+     *
54
+     * @param  string  $extension
55
+     *
56
+     * @return string|null  The mime type found, or none if unable to determine
57
+     */
58
+    public static function guessTypeFromExtension($extension)
59
+    {
60
+        $extension = trim(strtolower($extension), '. ');
61 61
 
62
-		if ( ! array_key_exists($extension, static::$mimes)) {
63
-			return null;
64
-		}
62
+        if ( ! array_key_exists($extension, static::$mimes)) {
63
+            return null;
64
+        }
65 65
 		
66
-		return is_array(static::$mimes[$extension]) ? static::$mimes[$extension][0] : static::$mimes[$extension];
67
-	}
66
+        return is_array(static::$mimes[$extension]) ? static::$mimes[$extension][0] : static::$mimes[$extension];
67
+    }
68 68
 
69
-	/**
70
-	 * Attempts to determine the best file extension for a given mime type.
71
-	 *
72
-	 * @param  string  $type
73
-	 *
74
-	 * @return string|null The extension determined, or null if unable to match
75
-	 */
76
-	public static function guessExtensionFromType($type)
77
-	{
78
-		$type = trim(strtolower($type), '. ');
69
+    /**
70
+     * Attempts to determine the best file extension for a given mime type.
71
+     *
72
+     * @param  string  $type
73
+     *
74
+     * @return string|null The extension determined, or null if unable to match
75
+     */
76
+    public static function guessExtensionFromType($type)
77
+    {
78
+        $type = trim(strtolower($type), '. ');
79 79
 
80
-		foreach (static::$mimes as $ext => $types) {
81
-			if (is_string($types) && $types == $type) {
82
-				return $ext;
83
-			} elseif (is_array($types) && in_array($type, $types)) {
84
-				return $ext;
85
-			}
86
-		}
80
+        foreach (static::$mimes as $ext => $types) {
81
+            if (is_string($types) && $types == $type) {
82
+                return $ext;
83
+            } elseif (is_array($types) && in_array($type, $types)) {
84
+                return $ext;
85
+            }
86
+        }
87 87
 
88
-		return null;
89
-	}
88
+        return null;
89
+    }
90 90
 }
91 91
\ No newline at end of file
Please login to merge, or discard this patch.