Passed
Branch 0.7.0 (a860c5)
by Alexander
02:46
created
src/components/Debug/GDebug.php 1 patch
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|null  $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|null  $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|null  $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|null  $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.
src/components/Filesystem/Filesystem.php 1 patch
Indentation   +804 added lines, -804 removed lines patch added patch discarded remove patch
@@ -35,819 +35,819 @@
 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
-	 *
65
-	 * @return bool
66
-	 */
67
-	public function append($path, $data)
68
-	{
69
-		return file_put_contents($path, $data, FILE_APPEND);
70
-	}
71
-
72
-	/**
73
-	 * Copy a file to a new location.
74
-	 *
75
-	 * @param  string  $path
76
-	 * @param  string  $target
77
-	 * 
78
-	 * @return bool
79
-	 */
80
-	public function copy($path, $target)
81
-	{
82
-		return copy($path, $target);
83
-	}
84
-
85
-	/**
86
-	 * Get the contents of a file.
87
-	 *
88
-	 * @param  string  $path
89
-	 * @param  bool  $lock  
90
-	 * @param  bool  $force  
91
-	 *
92
-	 * @return string
93
-	 *
94
-	 * @throws FileNotFoundException
95
-	 */
96
-	public function get($path, $lock = false, $force = false)
97
-	{
98
-		if ($this->isFile($path)) {
99
-			return $lock ? $this->read($path, $force) : file_get_contents($path);
100
-		}
101
-
102
-		throw new FileNotFoundException($path);
103
-	}
104
-
105
-	/**
106
-	 * Get contents of a file with shared access.
107
-	 *
108
-	 * @param  string  $path
109
-	 * @param  bool  $force  
110
-	 *
111
-	 * @return string
112
-	 */
113
-	protected function read($path, $force = false)
114
-	{
115
-		$contents = '';
116
-
117
-		$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
+     *
65
+     * @return bool
66
+     */
67
+    public function append($path, $data)
68
+    {
69
+        return file_put_contents($path, $data, FILE_APPEND);
70
+    }
71
+
72
+    /**
73
+     * Copy a file to a new location.
74
+     *
75
+     * @param  string  $path
76
+     * @param  string  $target
77
+     * 
78
+     * @return bool
79
+     */
80
+    public function copy($path, $target)
81
+    {
82
+        return copy($path, $target);
83
+    }
84
+
85
+    /**
86
+     * Get the contents of a file.
87
+     *
88
+     * @param  string  $path
89
+     * @param  bool  $lock  
90
+     * @param  bool  $force  
91
+     *
92
+     * @return string
93
+     *
94
+     * @throws FileNotFoundException
95
+     */
96
+    public function get($path, $lock = false, $force = false)
97
+    {
98
+        if ($this->isFile($path)) {
99
+            return $lock ? $this->read($path, $force) : file_get_contents($path);
100
+        }
101
+
102
+        throw new FileNotFoundException($path);
103
+    }
104
+
105
+    /**
106
+     * Get contents of a file with shared access.
107
+     *
108
+     * @param  string  $path
109
+     * @param  bool  $force  
110
+     *
111
+     * @return string
112
+     */
113
+    protected function read($path, $force = false)
114
+    {
115
+        $contents = '';
116
+
117
+        $this->open($path, 'rb', $force);
118 118
 		
119
-		if ($this->handler) {
120
-			try {
121
-				if (flock($this->handler, LOCK_SH)) {
122
-					$this->clearStatCache($path);
119
+        if ($this->handler) {
120
+            try {
121
+                if (flock($this->handler, LOCK_SH)) {
122
+                    $this->clearStatCache($path);
123 123
 
124
-					$contents = fread($this->handler, $this->getSize($path) ?: 1);
124
+                    $contents = fread($this->handler, $this->getSize($path) ?: 1);
125 125
 					
126
-					while ( ! feof($this->handler)) {
127
-						$contents .= fgets($this->handler, 4096);
128
-					}
129
-
130
-					flock($this->handler, LOCK_UN);
131
-				}
132
-			} finally {
133
-				$this->close();
134
-			}
135
-		}
136
-
137
-		return trim($contents);
138
-	}
139
-
140
-	/**
141
-	 * Opens the current file with a given $mode.
142
-	 *
143
-	 * @param  string  $path
144
-	 * @param  string  $mode  A valid 'fopen' mode string (r|w|a ...)
145
-	 * @param  bool  $force  
146
-	 *
147
-	 * @return bool
148
-	 */
149
-	public function open($path, $mode, $force = false)
150
-	{
151
-		if ( ! $force && is_resource($this->handler)) {
152
-			return true;
153
-		}
154
-
155
-		if ($this->exists($path) === false) {
156
-			if ($this->create($path) === false) {
157
-				return false;
158
-			}
159
-		}
160
-
161
-		$this->handler = fopen($path, $mode);
162
-
163
-		return is_resource($this->handler);
164
-	}
165
-
166
-	/**
167
-	 * Creates the file.
168
-	 * 
169
-	 * @param  string  $path
170
-	 * 
171
-	 * @return bool
172
-	 */
173
-	public function create($path)
174
-	{
175
-		if (($this->isDirectory($path)) && ($this->isWritable($path)) || ( ! $this->exists($path))) {
176
-			if (touch($path)) {
177
-				return true;
178
-			}
179
-		}
180
-
181
-		return false;
182
-	}
183
-
184
-	/**
185
-	 * Determine if a file exists.
186
-	 *
187
-	 * @param  string  $path
188
-	 *
189
-	 * @return bool
190
-	 */
191
-	public function exists($path)
192
-	{
193
-		$this->clearStatCache($path);
194
-
195
-		return file_exists($path);
196
-	}
197
-
198
-	/**
199
-	 * Clear PHP's internal stat cache.
200
-	 *
201
-	 * @param  string  $path
202
-	 * @param  bool  $all  Clear all cache or not
203
-	 *
204
-	 * @return void
205
-	 */
206
-	public function clearStatCache($path, $all = false)
207
-	{
208
-		if ($all === false) {
209
-			clearstatcache(true, $path);
210
-		}
211
-
212
-		clearstatcache();
213
-	}
214
-
215
-	/**
216
-	 * Get the returned value of a file.
217
-	 * 
218
-	 * @param  string  $path
219
-	 * @param  array  $data
220
-	 * 
221
-	 * @return mixed
222
-	 * 
223
-	 * @throws \Syscodes\Filesystem\Exceptions\FileNotFoundException
224
-	 */
225
-	public function getRequire($path, array $data = [])
226
-	{
227
-		if ($this->isFile($path)) {
228
-			$__path = $path;
229
-			$__data = $data;
230
-
231
-			return (static function () use ($__path, $__data) {
232
-				extract($__data, EXTR_SKIP);
233
-
234
-				return require $__path;
235
-			})();
236
-		}
237
-
238
-		throw new FileNotFoundException($path);
239
-	}
240
-
241
-	/**
242
-	 * Require the given file once.
243
-	 * 
244
-	 * @param  string  $path
245
-	 * @param  array  $data
246
-	 * 
247
-	 * @return mixed
248
-	 * 
249
-	 * @throws \Syscodes\Filesystem\Exceptions\FileNotFoundException
250
-	 */
251
-	public function getRequireOnce($path, array $data = [])
252
-	{
253
-		if ($this->isFile($path)) {
254
-			$__path = $path;
255
-			$__data = $data;
256
-
257
-			return (static function () use ($__path, $__data) {
258
-				extract($__data, EXTR_SKIP);
259
-
260
-				return require_once $__path;
261
-			})();
262
-		}
263
-
264
-		throw new FileNotFoundException($path);
265
-	}
266
-
267
-	/**
268
-	 * Retrieve the file size.
269
-	 *
270
-	 * Implementations SHOULD return the value stored in the "size" key of
271
-	 * the file in the $_FILES array if available, as PHP calculates this
272
-	 * based on the actual size transmitted.
273
-	 *
274
-	 * @param  string  $path
275
-	 * @param  string  $unit  ('b' by default)
276
-	 * 
277
-	 * @return int|null  The file size in bytes or null if unknown
278
-	 */
279
-	public function getSize($path, $unit = 'b')
280
-	{
281
-		if ($this->exists($path)) {
282
-			if (is_null($this->size)) {
283
-				$this->size = filesize($path);
284
-			}
285
-
286
-			switch (strtolower($unit)) {
287
-				case 'kb':
288
-					return number_format($this->size / 1024, 3);
289
-					break;
290
-				case 'mb':
291
-					return number_format(($this->size / 1024) / 1024, 3);     
292
-					break;
293
-			}
294
-
295
-			return $this->size;
296
-		}
297
-	}
126
+                    while ( ! feof($this->handler)) {
127
+                        $contents .= fgets($this->handler, 4096);
128
+                    }
129
+
130
+                    flock($this->handler, LOCK_UN);
131
+                }
132
+            } finally {
133
+                $this->close();
134
+            }
135
+        }
136
+
137
+        return trim($contents);
138
+    }
139
+
140
+    /**
141
+     * Opens the current file with a given $mode.
142
+     *
143
+     * @param  string  $path
144
+     * @param  string  $mode  A valid 'fopen' mode string (r|w|a ...)
145
+     * @param  bool  $force  
146
+     *
147
+     * @return bool
148
+     */
149
+    public function open($path, $mode, $force = false)
150
+    {
151
+        if ( ! $force && is_resource($this->handler)) {
152
+            return true;
153
+        }
154
+
155
+        if ($this->exists($path) === false) {
156
+            if ($this->create($path) === false) {
157
+                return false;
158
+            }
159
+        }
160
+
161
+        $this->handler = fopen($path, $mode);
162
+
163
+        return is_resource($this->handler);
164
+    }
165
+
166
+    /**
167
+     * Creates the file.
168
+     * 
169
+     * @param  string  $path
170
+     * 
171
+     * @return bool
172
+     */
173
+    public function create($path)
174
+    {
175
+        if (($this->isDirectory($path)) && ($this->isWritable($path)) || ( ! $this->exists($path))) {
176
+            if (touch($path)) {
177
+                return true;
178
+            }
179
+        }
180
+
181
+        return false;
182
+    }
183
+
184
+    /**
185
+     * Determine if a file exists.
186
+     *
187
+     * @param  string  $path
188
+     *
189
+     * @return bool
190
+     */
191
+    public function exists($path)
192
+    {
193
+        $this->clearStatCache($path);
194
+
195
+        return file_exists($path);
196
+    }
197
+
198
+    /**
199
+     * Clear PHP's internal stat cache.
200
+     *
201
+     * @param  string  $path
202
+     * @param  bool  $all  Clear all cache or not
203
+     *
204
+     * @return void
205
+     */
206
+    public function clearStatCache($path, $all = false)
207
+    {
208
+        if ($all === false) {
209
+            clearstatcache(true, $path);
210
+        }
211
+
212
+        clearstatcache();
213
+    }
214
+
215
+    /**
216
+     * Get the returned value of a file.
217
+     * 
218
+     * @param  string  $path
219
+     * @param  array  $data
220
+     * 
221
+     * @return mixed
222
+     * 
223
+     * @throws \Syscodes\Filesystem\Exceptions\FileNotFoundException
224
+     */
225
+    public function getRequire($path, array $data = [])
226
+    {
227
+        if ($this->isFile($path)) {
228
+            $__path = $path;
229
+            $__data = $data;
230
+
231
+            return (static function () use ($__path, $__data) {
232
+                extract($__data, EXTR_SKIP);
233
+
234
+                return require $__path;
235
+            })();
236
+        }
237
+
238
+        throw new FileNotFoundException($path);
239
+    }
240
+
241
+    /**
242
+     * Require the given file once.
243
+     * 
244
+     * @param  string  $path
245
+     * @param  array  $data
246
+     * 
247
+     * @return mixed
248
+     * 
249
+     * @throws \Syscodes\Filesystem\Exceptions\FileNotFoundException
250
+     */
251
+    public function getRequireOnce($path, array $data = [])
252
+    {
253
+        if ($this->isFile($path)) {
254
+            $__path = $path;
255
+            $__data = $data;
256
+
257
+            return (static function () use ($__path, $__data) {
258
+                extract($__data, EXTR_SKIP);
259
+
260
+                return require_once $__path;
261
+            })();
262
+        }
263
+
264
+        throw new FileNotFoundException($path);
265
+    }
266
+
267
+    /**
268
+     * Retrieve the file size.
269
+     *
270
+     * Implementations SHOULD return the value stored in the "size" key of
271
+     * the file in the $_FILES array if available, as PHP calculates this
272
+     * based on the actual size transmitted.
273
+     *
274
+     * @param  string  $path
275
+     * @param  string  $unit  ('b' by default)
276
+     * 
277
+     * @return int|null  The file size in bytes or null if unknown
278
+     */
279
+    public function getSize($path, $unit = 'b')
280
+    {
281
+        if ($this->exists($path)) {
282
+            if (is_null($this->size)) {
283
+                $this->size = filesize($path);
284
+            }
285
+
286
+            switch (strtolower($unit)) {
287
+                case 'kb':
288
+                    return number_format($this->size / 1024, 3);
289
+                    break;
290
+                case 'mb':
291
+                    return number_format(($this->size / 1024) / 1024, 3);     
292
+                    break;
293
+            }
294
+
295
+            return $this->size;
296
+        }
297
+    }
298 298
 	
299
-	/**
300
-	 * Returns the file's group.
301
-	 *
302
-	 * @param  string  $path
303
-	 * 
304
-	 * @return int|bool  The file group, or false in case of an error
305
-	 */
306
-	public function group($path)
307
-	{
308
-		if ($this->exists($path)) {
309
-			return filegroup($path);
310
-		}
311
-
312
-		return false;
313
-	}
299
+    /**
300
+     * Returns the file's group.
301
+     *
302
+     * @param  string  $path
303
+     * 
304
+     * @return int|bool  The file group, or false in case of an error
305
+     */
306
+    public function group($path)
307
+    {
308
+        if ($this->exists($path)) {
309
+            return filegroup($path);
310
+        }
311
+
312
+        return false;
313
+    }
314 314
 	
315
-	/**
316
-	 * Returns true if the file is executable.
317
-	 *
318
-	 * @param  string  $path
319
-	 * 
320
-	 * @return bool  True if file is executable, false otherwise
321
-	 */
322
-	public function exec($path)
323
-	{
324
-		return is_executable($path);
325
-	}
326
-
327
-	/**
328
-	 * Determine if the given path is a directory.
329
-	 *
330
-	 * @param  string  $directory
331
-	 *
332
-	 * @return bool
333
-	 */
334
-	public function isDirectory($directory)
335
-	{
336
-		return is_dir($directory);
337
-	}
338
-
339
-	/**
340
-	 * Determine if the given path is a file.
341
-	 *
342
-	 * @param  string  $file
343
-	 *
344
-	 * @return bool
345
-	 */
346
-	public function isFile($file)
347
-	{
348
-		return is_file($file);
349
-	}
350
-
351
-	/**
352
-	 * Determine if the given path is writable.
353
-	 * 
354
-	 * @param  string  $path
355
-	 * 
356
-	 * @return bool
357
-	 */
358
-	public function isWritable($path)
359
-	{
360
-		return is_writable($path);
361
-	}
362
-
363
-	/**
364
-	 * Returns if true the file is readable.
365
-	 *
366
-	 * @param  string  $path
367
-	 * 
368
-	 * @return bool  True if file is readable, false otherwise
369
-	 */
370
-	public function isReadable($path)
371
-	{
372
-		return is_readable($path);
373
-	}
374
-
375
-	/**
376
-	 * Returns last access time.
377
-	 *
378
-	 * @param  string  $path
379
-	 * 
380
-	 * @return int|bool  Timestamp of last access time, or false in case of an error
381
-	 */
382
-	public function lastAccess($path)
383
-	{
384
-		if ($this->exists($path)) {
385
-			return fileatime($path);
386
-		}
387
-
388
-		return false;
389
-	}
390
-
391
-	/**
392
-	 * Returns last modified time.
393
-	 *
394
-	 * @param  string  $path
395
-	 * 
396
-	 * @return int|bool  Timestamp of last modified time, or false in case of an error
397
-	 */
398
-	public function lastModified($path)
399
-	{
400
-		if ($this->exists($path)) {
401
-			return filemtime($path);
402
-		}
403
-
404
-		return false;
405
-	}
406
-
407
-	/**
408
-	 * Get all of the directories within a given directory.
409
-	 * 
410
-	 * @param  string  $directory
411
-	 * 
412
-	 * @return array
413
-	 */
414
-	public function directories($directory)
415
-	{
416
-		$directories = [];
417
-
418
-		$iterators = new FilesystemIterator($directory);
419
-
420
-		foreach ($iterators as $iterator) {
421
-			$directories[] = trim($iterator->getPathname(), '/').'/';
422
-		}
423
-
424
-		return $directories;
425
-	}
426
-
427
-	/**
428
-	 * Delete the file at a given path.
429
-	 * 
430
-	 * @param  string  $paths
431
-	 * 
432
-	 * @return bool
433
-	 */
434
-	public function delete($paths)
435
-	{
436
-		if (is_resource($this->handler)) {
437
-			fclose($this->handler);
438
-			$this->handler = null;
439
-		}
440
-
441
-		$paths = is_array($paths) ? $paths : func_get_args();
442
-
443
-		$success = true;
444
-
445
-		foreach ($paths as $path) {
446
-			try {
447
-				if ( ! @unlink($path)) {
448
-					return $success = false;
449
-				}
450
-			} catch (ErrorException $e) {
451
-				return $success = false;
452
-			}
453
-		}
454
-
455
-		return $success;
456
-	}
457
-
458
-	/**
459
-	 * Create a directory.
460
-	 *
461
-	 * @param  string  $path
462
-	 * @param  int  $mode
463
-	 * @param  bool  $recursive
464
-	 * @param  bool  $force
465
-	 *
466
-	 * @return bool
467
-	 * 
468
-	 * @throws FileException
469
-	 */
470
-	public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false)
471
-	{
472
-		if ($force) {
473
-			return @mkdir($path, $mode, $recursive);
474
-		}
475
-
476
-		mkdir($path, $mode, $recursive);
477
-	}
478
-
479
-	/**
480
-	 * Copy a directory from one location to another.
481
-	 * 
482
-	 * @param  string  $directory
483
-	 * @param  string  $destination
484
-	 * @param  int  $options  
485
-	 * 
486
-	 * @return bool
487
-	 */
488
-	public function copyDirectory($directory, $destination, $options = null)
489
-	{
490
-		if ( ! $this->isDirectory($directory)) return false;
491
-
492
-		$options = $options ?: FilesystemIterator::SKIP_DOTS;
315
+    /**
316
+     * Returns true if the file is executable.
317
+     *
318
+     * @param  string  $path
319
+     * 
320
+     * @return bool  True if file is executable, false otherwise
321
+     */
322
+    public function exec($path)
323
+    {
324
+        return is_executable($path);
325
+    }
326
+
327
+    /**
328
+     * Determine if the given path is a directory.
329
+     *
330
+     * @param  string  $directory
331
+     *
332
+     * @return bool
333
+     */
334
+    public function isDirectory($directory)
335
+    {
336
+        return is_dir($directory);
337
+    }
338
+
339
+    /**
340
+     * Determine if the given path is a file.
341
+     *
342
+     * @param  string  $file
343
+     *
344
+     * @return bool
345
+     */
346
+    public function isFile($file)
347
+    {
348
+        return is_file($file);
349
+    }
350
+
351
+    /**
352
+     * Determine if the given path is writable.
353
+     * 
354
+     * @param  string  $path
355
+     * 
356
+     * @return bool
357
+     */
358
+    public function isWritable($path)
359
+    {
360
+        return is_writable($path);
361
+    }
362
+
363
+    /**
364
+     * Returns if true the file is readable.
365
+     *
366
+     * @param  string  $path
367
+     * 
368
+     * @return bool  True if file is readable, false otherwise
369
+     */
370
+    public function isReadable($path)
371
+    {
372
+        return is_readable($path);
373
+    }
374
+
375
+    /**
376
+     * Returns last access time.
377
+     *
378
+     * @param  string  $path
379
+     * 
380
+     * @return int|bool  Timestamp of last access time, or false in case of an error
381
+     */
382
+    public function lastAccess($path)
383
+    {
384
+        if ($this->exists($path)) {
385
+            return fileatime($path);
386
+        }
387
+
388
+        return false;
389
+    }
390
+
391
+    /**
392
+     * Returns last modified time.
393
+     *
394
+     * @param  string  $path
395
+     * 
396
+     * @return int|bool  Timestamp of last modified time, or false in case of an error
397
+     */
398
+    public function lastModified($path)
399
+    {
400
+        if ($this->exists($path)) {
401
+            return filemtime($path);
402
+        }
403
+
404
+        return false;
405
+    }
406
+
407
+    /**
408
+     * Get all of the directories within a given directory.
409
+     * 
410
+     * @param  string  $directory
411
+     * 
412
+     * @return array
413
+     */
414
+    public function directories($directory)
415
+    {
416
+        $directories = [];
417
+
418
+        $iterators = new FilesystemIterator($directory);
419
+
420
+        foreach ($iterators as $iterator) {
421
+            $directories[] = trim($iterator->getPathname(), '/').'/';
422
+        }
423
+
424
+        return $directories;
425
+    }
426
+
427
+    /**
428
+     * Delete the file at a given path.
429
+     * 
430
+     * @param  string  $paths
431
+     * 
432
+     * @return bool
433
+     */
434
+    public function delete($paths)
435
+    {
436
+        if (is_resource($this->handler)) {
437
+            fclose($this->handler);
438
+            $this->handler = null;
439
+        }
440
+
441
+        $paths = is_array($paths) ? $paths : func_get_args();
442
+
443
+        $success = true;
444
+
445
+        foreach ($paths as $path) {
446
+            try {
447
+                if ( ! @unlink($path)) {
448
+                    return $success = false;
449
+                }
450
+            } catch (ErrorException $e) {
451
+                return $success = false;
452
+            }
453
+        }
454
+
455
+        return $success;
456
+    }
457
+
458
+    /**
459
+     * Create a directory.
460
+     *
461
+     * @param  string  $path
462
+     * @param  int  $mode
463
+     * @param  bool  $recursive
464
+     * @param  bool  $force
465
+     *
466
+     * @return bool
467
+     * 
468
+     * @throws FileException
469
+     */
470
+    public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false)
471
+    {
472
+        if ($force) {
473
+            return @mkdir($path, $mode, $recursive);
474
+        }
475
+
476
+        mkdir($path, $mode, $recursive);
477
+    }
478
+
479
+    /**
480
+     * Copy a directory from one location to another.
481
+     * 
482
+     * @param  string  $directory
483
+     * @param  string  $destination
484
+     * @param  int  $options  
485
+     * 
486
+     * @return bool
487
+     */
488
+    public function copyDirectory($directory, $destination, $options = null)
489
+    {
490
+        if ( ! $this->isDirectory($directory)) return false;
491
+
492
+        $options = $options ?: FilesystemIterator::SKIP_DOTS;
493 493
 		
494
-		// If the destination directory does not actually exist, we will go ahead and
495
-		// create it recursively, which just gets the destination prepared to copy
496
-		// the files over. Once we make the directory we'll proceed the copying.
497
-		if ( ! $this->isdirectory($destination)) {
498
-			$this->makeDirectory($destination, 0777, true);
499
-		}
494
+        // If the destination directory does not actually exist, we will go ahead and
495
+        // create it recursively, which just gets the destination prepared to copy
496
+        // the files over. Once we make the directory we'll proceed the copying.
497
+        if ( ! $this->isdirectory($destination)) {
498
+            $this->makeDirectory($destination, 0777, true);
499
+        }
500 500
 
501
-		$iterators = new FilesystemIterator($directory, $options);
501
+        $iterators = new FilesystemIterator($directory, $options);
502 502
 
503
-		foreach ($iterators as $iterator) {
504
-			$target = $destination.DIRECTORY_SEPARATOR.$iterator->getBasename();
503
+        foreach ($iterators as $iterator) {
504
+            $target = $destination.DIRECTORY_SEPARATOR.$iterator->getBasename();
505 505
 			
506
-			// As we spin through items, we will check to see if the current file is actually
506
+            // As we spin through items, we will check to see if the current file is actually
507 507
             // a directory or a file. When it is actually a directory we will need to call
508 508
             // back into this function recursively to keep copying these nested folders.
509
-			if ($iterator->isDir()) {
510
-				if ( ! $this->copyDirectory($iterator->getPathname(), $target, $options)) return false;
511
-			}
512
-			// If the current items is just a regular file, we will just copy this to the new
513
-			// location and keep looping. If for some reason the copy fails we'll bail out
514
-			// and return false, so the developer is aware that the copy process failed.
515
-			else {
516
-				if ( ! $this->copy($iterator->getPathname(), $target)) return false;
517
-			}
518
-		}
519
-
520
-		return true;
521
-	}
522
-
523
-	/**
524
-	 * Recursively delete a directory and optionally you can keep 
525
-	 * the directory if you wish.
526
-	 * 
527
-	 * @param  string  $directory
528
-	 * @param  bool  $keep
529
-	 * 
530
-	 * @return bool
531
-	 */
532
-	public function deleteDirectory($directory, $keep = false)
533
-	{
534
-		if ( ! $this->isDirectory($directory)) return false;
535
-
536
-		$iterators = new filesystemIterator($directory);
537
-
538
-		foreach ($iterators as $iterator) {
539
-			// If the item is a directory, we can just recurse into the function and delete 
540
-			// that sub-directory otherwise we'll just delete the file and keep iterating 
541
-			// through each file until the directory is cleaned.
542
-			if ($iterator->isDir() && ! $iterator->isLink()) {
543
-				$this->deleteDirectory($iterator->getPathname());
544
-			}
545
-			// If the item is just a file, we can go ahead and delete it since we're
546
-			// just looping through and waxing all of the files in this directory
547
-			// and calling directories recursively, so we delete the real path.
548
-			else {
549
-				$this->delete($iterator->getPathname());
550
-			}
551
-		}
552
-
553
-		if ( ! $keep) @rmdir($directory);
554
-
555
-		return true;
556
-	}
557
-
558
-	/**
559
-	 * Empty the specified directory of all files and folders.
560
-	 * 
561
-	 * 
562
-	 * @param  string  $directory
563
-	 * 
564
-	 * @return bool
565
-	 */
566
-	public function cleanDirectory($directory)
567
-	{
568
-		return $this->deleteDirectory($directory, true);
569
-	}
570
-
571
-	/**
572
-	 * Moves a file to a new location.
573
-	 * 
574
-	 * @param  string  $from
575
-	 * @param  string  $to
576
-	 * @param  bool  $overwrite  
577
-	 * 
578
-	 * @return bool
579
-	 */
580
-	public function moveDirectory($from, $to, $overwrite = false)
581
-	{
582
-		if ($overwrite && $this->isDirectory($to) && ! $this->deleteDirectory($to)) return false;
583
-
584
-		if (false === @rename($from, $to)) {
585
-			$error = error_get_last();
586
-
587
-			throw new FileUnableToMoveException($from, $to, strip_tags($error['message']));
588
-		}
589
-
590
-		$this->perms($to, 0777 & ~umask());
591
-	}
592
-
593
-	/**
594
-	 * Attempts to determine the file extension based on the trusted
595
-	 * getType() method. If the mime type is unknown, will return null.
596
-	 * 
597
-	 * @param  string  $path
598
-	 * 
599
-	 * @return string|null
600
-	 */
601
-	public function guessExtension($path)
602
-	{
603
-		return FileMimeType::guessExtensionFromType($this->getMimeType($path));
604
-	}
605
-
606
-	/**
607
-	 * Retrieve the media type of the file. 
608
-	 * 
609
-	 * @param  string  $path
610
-	 * 
611
-	 * @return string|null
612
-	 */
613
-	public function getMimeType($path)
614
-	{
615
-		$finfo    = finfo_open(FILEINFO_MIME_TYPE);
616
-		$mimeType = finfo_file($finfo, $path);
617
-
618
-		finfo_close($finfo);
619
-
620
-		return $mimeType;
621
-	}
622
-
623
-	/**
624
-	 * Move a file to a new location.
625
-	 *
626
-	 * @param  string  $path
627
-	 * @param  string  $target
628
-	 *
629
-	 * @return bool
630
-	 */
631
-	public function move($path, $target)
632
-	{
633
-		if ($this->exists($path)) {
634
-			return rename($path, $target);
635
-		}
636
-	}
637
-
638
-	/**
639
-	 * Extract the file name from a file path.
640
-	 * 
641
-	 * @param  string  $path
642
-	 * 
643
-	 * @return string
644
-	 */
645
-	public function name($path)
646
-	{
647
-		return pathinfo($path, PATHINFO_FILENAME);
648
-	}
649
-
650
-	/**
651
-	 * Extract the trailing name component from a file path.
652
-	 * 
653
-	 * @param  string  $path
654
-	 * 
655
-	 * @return string
656
-	 */
657
-	public function basename($path)
658
-	{
659
-		return pathinfo($path, PATHINFO_BASENAME);
660
-	}
661
-
662
-	/**
663
-	 * Extract the parent directory from a file path.
664
-	 * 
665
-	 * @param  string  $path
666
-	 * 
667
-	 * @return string
668
-	 */
669
-	public function dirname($path)
670
-	{
671
-		return pathinfo($path, PATHINFO_DIRNAME);
672
-	}
673
-
674
-	/**
675
-	 * Extract the file extension from a file path.
676
-	 * 
677
-	 * @param  string  $path
678
-	 * 
679
-	 * @return string
680
-	 */
681
-	public function extension($path)
682
-	{
683
-		return pathinfo($path, PATHINFO_EXTENSION);
684
-	}
685
-
686
-	/**
687
-	 *  Find path names matching a given pattern.
688
-	 * 
689
-	 * @param  string  $pattern
690
-	 * @param  int  $flags  (0 by default)
691
-	 * 
692
-	 * @return array
693
-	 */
694
-	public function glob($pattern, $flags = 0)
695
-	{
696
-		return glob($pattern, $flags);
697
-	}
698
-
699
-	/**
700
-	 * Returns the file's owner.
701
-	 *
702
-	 * @param  string  $path
703
-	 * 
704
-	 * @return int|bool  The file owner, or false in case of an error
705
-	 */
706
-	public function owner($path)
707
-	{
708
-		if ($this->exists($path)) {
709
-			return fileowner($path);
710
-		}
711
-
712
-		return false;
713
-	}
714
-
715
-	/**
716
-	 * Returns the "chmod" (permissions) of the file.
717
-	 *
718
-	 * @param  string  $path
719
-	 * @param  int|null  $mode  
720
-	 * 
721
-	 * @return mixed  Permissions for the file, or false in case of an error
722
-	 */
723
-	public function perms($path, $mode = null)
724
-	{
725
-		if ($mode) {
726
-			chmod($path, $mode);
727
-		}
728
-
729
-		return substr(sprintf('%o', fileperms($path)), -4);
730
-	}
731
-
732
-	/**
733
-	 * Prepend to a file.
734
-	 * 
735
-	 * @param  string  $path
736
-	 * @param  string  $data
737
-	 * 
738
-	 * @return int
739
-	 */
740
-	public function prepend($path, $data)
741
-	{
742
-		if ($this->exists($path)) {
743
-			$this->put($path, $data.$this->get($path));
744
-		}
745
-
746
-		return $this->put($path, $data);
747
-	}
748
-
749
-	/**
750
-	 * Write the content of a file.
751
-	 *
752
-	 * @param  string  $path
753
-	 * @param  string  $contents
754
-	 * @param  bool  $lock  
755
-	 *
756
-	 * @return int
757
-	 */
758
-	public function put($path, $contents, $lock = false)
759
-	{
760
-		return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
761
-	}
762
-
763
-	/**
764
-	 * Get the file type of a given file.
765
-	 * 
766
-	 * @param  string  $path
767
-	 * 
768
-	 * @return string
769
-	 */
770
-	public function type($path)
771
-	{
772
-		return filetype($path);
773
-	}
774
-
775
-	/**
776
-	 * Searches for a given text and replaces the text if found.
777
-	 *
778
-	 * @param  string  $path
779
-	 * @param  string  $search
780
-	 * @param  string  $replace
781
-	 *
782
-	 * @return bool
783
-	 */
784
-	public function replaceText($path, $search, $replace)
785
-	{
786
-		if ( ! $this->open($path, 'r+')) {
787
-			return false;
788
-		}
789
-
790
-		if ($this->lock !== null) {
791
-			if (flock($this->handler, LOCK_EX) === false)
792
-			{
793
-				return false;
794
-			}
795
-		}
796
-
797
-		$replaced = $this->write($path, str_replace($search, $replace, $this->get($path)), true);
798
-
799
-		if ($this->lock !== null) {
800
-			flock($this->handler, LOCK_UN);
801
-		}
802
-
803
-		$this->close();
804
-
805
-		return $replaced;
806
-	}	
807
-
808
-	/**
809
-	 * Closes the current file if it is opened.
810
-	 *
811
-	 * @return bool
812
-	 */
813
-	public function close()
814
-	{
815
-		if ( ! is_resource($this->handler)) {
816
-			return true;
817
-		}
818
-
819
-		return fclose($this->handler);
820
-	}
821
-
822
-	/**
823
-	 * Write given data to this file.
824
-	 *
825
-	 * @param  string  $path
826
-	 * @param  string  $data  Data to write to this File
827
-	 * @param  bool  $force  The file to open
828
-	 *
829
-	 * @return bool
830
-	 */
831
-	public function write($path, $data, $force = false)
832
-	{
833
-		$success = false;
834
-
835
-		if ($this->open($path, 'w', $force) === true) {
836
-			if ($this->lock !== null) {
837
-				if (flock($this->handler, LOCK_EX) === false) {
838
-					return false;
839
-				}
840
-			}
841
-
842
-			if (fwrite($this->handler, $data) !== false) {
843
-				$success = true;
844
-			}
845
-
846
-			if ($this->lock !== null) {
847
-				flock($this->handler, LOCK_UN);
848
-			}
849
-		}
850
-
851
-		return $success;
852
-	}
509
+            if ($iterator->isDir()) {
510
+                if ( ! $this->copyDirectory($iterator->getPathname(), $target, $options)) return false;
511
+            }
512
+            // If the current items is just a regular file, we will just copy this to the new
513
+            // location and keep looping. If for some reason the copy fails we'll bail out
514
+            // and return false, so the developer is aware that the copy process failed.
515
+            else {
516
+                if ( ! $this->copy($iterator->getPathname(), $target)) return false;
517
+            }
518
+        }
519
+
520
+        return true;
521
+    }
522
+
523
+    /**
524
+     * Recursively delete a directory and optionally you can keep 
525
+     * the directory if you wish.
526
+     * 
527
+     * @param  string  $directory
528
+     * @param  bool  $keep
529
+     * 
530
+     * @return bool
531
+     */
532
+    public function deleteDirectory($directory, $keep = false)
533
+    {
534
+        if ( ! $this->isDirectory($directory)) return false;
535
+
536
+        $iterators = new filesystemIterator($directory);
537
+
538
+        foreach ($iterators as $iterator) {
539
+            // If the item is a directory, we can just recurse into the function and delete 
540
+            // that sub-directory otherwise we'll just delete the file and keep iterating 
541
+            // through each file until the directory is cleaned.
542
+            if ($iterator->isDir() && ! $iterator->isLink()) {
543
+                $this->deleteDirectory($iterator->getPathname());
544
+            }
545
+            // If the item is just a file, we can go ahead and delete it since we're
546
+            // just looping through and waxing all of the files in this directory
547
+            // and calling directories recursively, so we delete the real path.
548
+            else {
549
+                $this->delete($iterator->getPathname());
550
+            }
551
+        }
552
+
553
+        if ( ! $keep) @rmdir($directory);
554
+
555
+        return true;
556
+    }
557
+
558
+    /**
559
+     * Empty the specified directory of all files and folders.
560
+     * 
561
+     * 
562
+     * @param  string  $directory
563
+     * 
564
+     * @return bool
565
+     */
566
+    public function cleanDirectory($directory)
567
+    {
568
+        return $this->deleteDirectory($directory, true);
569
+    }
570
+
571
+    /**
572
+     * Moves a file to a new location.
573
+     * 
574
+     * @param  string  $from
575
+     * @param  string  $to
576
+     * @param  bool  $overwrite  
577
+     * 
578
+     * @return bool
579
+     */
580
+    public function moveDirectory($from, $to, $overwrite = false)
581
+    {
582
+        if ($overwrite && $this->isDirectory($to) && ! $this->deleteDirectory($to)) return false;
583
+
584
+        if (false === @rename($from, $to)) {
585
+            $error = error_get_last();
586
+
587
+            throw new FileUnableToMoveException($from, $to, strip_tags($error['message']));
588
+        }
589
+
590
+        $this->perms($to, 0777 & ~umask());
591
+    }
592
+
593
+    /**
594
+     * Attempts to determine the file extension based on the trusted
595
+     * getType() method. If the mime type is unknown, will return null.
596
+     * 
597
+     * @param  string  $path
598
+     * 
599
+     * @return string|null
600
+     */
601
+    public function guessExtension($path)
602
+    {
603
+        return FileMimeType::guessExtensionFromType($this->getMimeType($path));
604
+    }
605
+
606
+    /**
607
+     * Retrieve the media type of the file. 
608
+     * 
609
+     * @param  string  $path
610
+     * 
611
+     * @return string|null
612
+     */
613
+    public function getMimeType($path)
614
+    {
615
+        $finfo    = finfo_open(FILEINFO_MIME_TYPE);
616
+        $mimeType = finfo_file($finfo, $path);
617
+
618
+        finfo_close($finfo);
619
+
620
+        return $mimeType;
621
+    }
622
+
623
+    /**
624
+     * Move a file to a new location.
625
+     *
626
+     * @param  string  $path
627
+     * @param  string  $target
628
+     *
629
+     * @return bool
630
+     */
631
+    public function move($path, $target)
632
+    {
633
+        if ($this->exists($path)) {
634
+            return rename($path, $target);
635
+        }
636
+    }
637
+
638
+    /**
639
+     * Extract the file name from a file path.
640
+     * 
641
+     * @param  string  $path
642
+     * 
643
+     * @return string
644
+     */
645
+    public function name($path)
646
+    {
647
+        return pathinfo($path, PATHINFO_FILENAME);
648
+    }
649
+
650
+    /**
651
+     * Extract the trailing name component from a file path.
652
+     * 
653
+     * @param  string  $path
654
+     * 
655
+     * @return string
656
+     */
657
+    public function basename($path)
658
+    {
659
+        return pathinfo($path, PATHINFO_BASENAME);
660
+    }
661
+
662
+    /**
663
+     * Extract the parent directory from a file path.
664
+     * 
665
+     * @param  string  $path
666
+     * 
667
+     * @return string
668
+     */
669
+    public function dirname($path)
670
+    {
671
+        return pathinfo($path, PATHINFO_DIRNAME);
672
+    }
673
+
674
+    /**
675
+     * Extract the file extension from a file path.
676
+     * 
677
+     * @param  string  $path
678
+     * 
679
+     * @return string
680
+     */
681
+    public function extension($path)
682
+    {
683
+        return pathinfo($path, PATHINFO_EXTENSION);
684
+    }
685
+
686
+    /**
687
+     *  Find path names matching a given pattern.
688
+     * 
689
+     * @param  string  $pattern
690
+     * @param  int  $flags  (0 by default)
691
+     * 
692
+     * @return array
693
+     */
694
+    public function glob($pattern, $flags = 0)
695
+    {
696
+        return glob($pattern, $flags);
697
+    }
698
+
699
+    /**
700
+     * Returns the file's owner.
701
+     *
702
+     * @param  string  $path
703
+     * 
704
+     * @return int|bool  The file owner, or false in case of an error
705
+     */
706
+    public function owner($path)
707
+    {
708
+        if ($this->exists($path)) {
709
+            return fileowner($path);
710
+        }
711
+
712
+        return false;
713
+    }
714
+
715
+    /**
716
+     * Returns the "chmod" (permissions) of the file.
717
+     *
718
+     * @param  string  $path
719
+     * @param  int|null  $mode  
720
+     * 
721
+     * @return mixed  Permissions for the file, or false in case of an error
722
+     */
723
+    public function perms($path, $mode = null)
724
+    {
725
+        if ($mode) {
726
+            chmod($path, $mode);
727
+        }
728
+
729
+        return substr(sprintf('%o', fileperms($path)), -4);
730
+    }
731
+
732
+    /**
733
+     * Prepend to a file.
734
+     * 
735
+     * @param  string  $path
736
+     * @param  string  $data
737
+     * 
738
+     * @return int
739
+     */
740
+    public function prepend($path, $data)
741
+    {
742
+        if ($this->exists($path)) {
743
+            $this->put($path, $data.$this->get($path));
744
+        }
745
+
746
+        return $this->put($path, $data);
747
+    }
748
+
749
+    /**
750
+     * Write the content of a file.
751
+     *
752
+     * @param  string  $path
753
+     * @param  string  $contents
754
+     * @param  bool  $lock  
755
+     *
756
+     * @return int
757
+     */
758
+    public function put($path, $contents, $lock = false)
759
+    {
760
+        return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
761
+    }
762
+
763
+    /**
764
+     * Get the file type of a given file.
765
+     * 
766
+     * @param  string  $path
767
+     * 
768
+     * @return string
769
+     */
770
+    public function type($path)
771
+    {
772
+        return filetype($path);
773
+    }
774
+
775
+    /**
776
+     * Searches for a given text and replaces the text if found.
777
+     *
778
+     * @param  string  $path
779
+     * @param  string  $search
780
+     * @param  string  $replace
781
+     *
782
+     * @return bool
783
+     */
784
+    public function replaceText($path, $search, $replace)
785
+    {
786
+        if ( ! $this->open($path, 'r+')) {
787
+            return false;
788
+        }
789
+
790
+        if ($this->lock !== null) {
791
+            if (flock($this->handler, LOCK_EX) === false)
792
+            {
793
+                return false;
794
+            }
795
+        }
796
+
797
+        $replaced = $this->write($path, str_replace($search, $replace, $this->get($path)), true);
798
+
799
+        if ($this->lock !== null) {
800
+            flock($this->handler, LOCK_UN);
801
+        }
802
+
803
+        $this->close();
804
+
805
+        return $replaced;
806
+    }	
807
+
808
+    /**
809
+     * Closes the current file if it is opened.
810
+     *
811
+     * @return bool
812
+     */
813
+    public function close()
814
+    {
815
+        if ( ! is_resource($this->handler)) {
816
+            return true;
817
+        }
818
+
819
+        return fclose($this->handler);
820
+    }
821
+
822
+    /**
823
+     * Write given data to this file.
824
+     *
825
+     * @param  string  $path
826
+     * @param  string  $data  Data to write to this File
827
+     * @param  bool  $force  The file to open
828
+     *
829
+     * @return bool
830
+     */
831
+    public function write($path, $data, $force = false)
832
+    {
833
+        $success = false;
834
+
835
+        if ($this->open($path, 'w', $force) === true) {
836
+            if ($this->lock !== null) {
837
+                if (flock($this->handler, LOCK_EX) === false) {
838
+                    return false;
839
+                }
840
+            }
841
+
842
+            if (fwrite($this->handler, $data) !== false) {
843
+                $success = true;
844
+            }
845
+
846
+            if ($this->lock !== null) {
847
+                flock($this->handler, LOCK_UN);
848
+            }
849
+        }
850
+
851
+        return $success;
852
+    }
853 853
 }
854 854
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Support/Chronos/Traits/Factory.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -58,12 +58,12 @@  discard block
 block discarded – undo
58 58
         $this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone);
59 59
         
60 60
         if ( ! empty($time)) {
61
-			if (is_string($time) && static::hasRelativeKeywords($time)) {
62
-				$dateTime = new DateTime('now', $this->timezone);
63
-				$dateTime->modify($time);
61
+            if (is_string($time) && static::hasRelativeKeywords($time)) {
62
+                $dateTime = new DateTime('now', $this->timezone);
63
+                $dateTime->modify($time);
64 64
 
65
-				$time = $dateTime->format('Y-m-d H:i:s');
66
-			}
65
+                $time = $dateTime->format('Y-m-d H:i:s');
66
+            }
67 67
         }
68 68
         
69 69
         return parent::__construct($time, $this->timezone);
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
      * @return \Syscodes\Support\Chronos\Time
119 119
      */
120 120
     public static function yesterday($timezone = null, string $locale = null)
121
-	{
122
-		return static::parse(date('Y-m-d 00:00:00', strtotime('-1 day')), $timezone, $locale);
121
+    {
122
+        return static::parse(date('Y-m-d 00:00:00', strtotime('-1 day')), $timezone, $locale);
123 123
     }
124 124
 
125 125
     /**
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
      * @return \Syscodes\Support\Chronos\Time
132 132
      */
133 133
     public static function tomorrow($timezone = null, string $locale = null)
134
-	{
135
-		return static::parse(date('Y-m-d 00:00:00', strtotime('+1 day')), $timezone, $locale);
134
+    {
135
+        return static::parse(date('Y-m-d 00:00:00', strtotime('+1 day')), $timezone, $locale);
136 136
     }
137 137
 
138 138
     /**
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 
265 265
     /**
266 266
      * Creates an instance of Time that will be returned during testing
267
-	 * when calling 'Time::now' instead of the current time.
267
+     * when calling 'Time::now' instead of the current time.
268 268
      * 
269 269
      * @param  \Syscodes\Support\Chronos\Time|string  $datetime  
270 270
      * @param  string|null  $timezone 
Please login to merge, or discard this patch.
src/components/Routing/Route.php 1 patch
Indentation   +643 added lines, -643 removed lines patch added patch discarded remove patch
@@ -40,661 +40,661 @@
 block discarded – undo
40 40
  */
41 41
 class Route 
42 42
 {
43
-	use Concerns\RouteCondition,
44
-	    Concerns\RouteDependencyResolver;
43
+    use Concerns\RouteCondition,
44
+        Concerns\RouteDependencyResolver;
45 45
 	
46
-	/**
47
-	 * Action that the route will use when called.
48
-	 *
49
-	 * @var \Closure|string|array $action
50
-	 */
51
-	public $action;
52
-
53
-	/**
54
-	 * The container instance used by the route.
55
-	 * 
56
-	 * @var \Syscodes\Container\Container $container
57
-	 */
58
-	protected $container;
59
-
60
-	/**
61
-	 * The controller instance.
62
-	 * 
63
-	 * @var string $controller
64
-	 */
65
-	public $controller;
66
-
67
-	/**
68
-	 * The default values for the route.
69
-	 * 
70
-	 * @var array $defaults
71
-	 */
72
-	public $defaults = [];
73
-
74
-	/**
75
-	 * Variable of HTTP method.
76
-	 *  
77
-	 * @var array|string $method
78
-	 */
79
-	public $method;
80
-
81
-	/**
82
-	 * The array of matched parameters.
83
-	 * 
84
-	 * @var array $parameters
85
-	 */
86
-	public $parameters = [];
87
-
88
-	/**
89
-	 * The parameter names for the route.
90
-	 * 
91
-	 * @var string|null $parameterNames
92
-	 */
93
-	public $parameterNames;
94
-
95
-	/**
96
-	* Patterns that should be replaced.
97
-	*
98
-	* @var array $patterns 
99
-	*/
100
-	public $patterns = [
101
-		'~/~'                    =>  '\/',               // Slash
102
-		'~{an:[^\/{}]+}~'        => '([0-9a-zA-Z]++)',   // Placeholder accepts alphabetic and numeric chars
103
-		'~{n:[^\/{}]+}~'         => '([0-9]++)',         // Placeholder accepts only numeric
104
-		'~{a:[^\/{}]+}~'         => '([a-zA-Z]++)',      // Placeholder accepts only alphabetic chars
105
-		'~{w:[^\/{}]+}~'         => '([0-9a-zA-Z-_]++)', // Placeholder accepts alphanumeric and underscore
106
-		'~{\*:[^\/{}]+}~'        => '(.++)',             // Placeholder match rest of url
107
-		'~(\\\/)?{\?:[^\/{}]+}~' => '\/?([^\/]*)',		 // Optional placeholder
108
-		'~{[^\/{}]+}~'           => '([^\/]++)'			 // Normal placeholder
109
-	];
110
-
111
-	/**
112
-	 * The URI pattern the route responds to.
113
-	 *
114
-	 * @var array $uri
115
-	 */
116
-	public $uri = [];
117
-
118
-	/**
119
-	 * Contains the arguments of the current route.
120
-	 *
121
-	 * @var array $where
122
-	 */
123
-	public $wheres = [];
124
-
125
-	/**
126
-	 * Constructor. Initialize route.
127
-	 *
128
-	 * @param  array|string|null  $method  
129
-	 * @param  string|null  $uri  
130
-	 * @param  \Closure|string|null  $action  
131
-	 *
132
-	 * @return void
133
-	 */
134
-	public function __construct($method = null, $uri = null, $action = null)
135
-	{
136
-		$this->uri = $uri;
137
-
138
-		// Set the method
139
-		$this->parseMethod($method);
140
-
141
-		// Set the action
142
-		$this->action = Arr::except($this->parseAction($action), ['prefix']);
143
-
144
-		if (is_null($prefix = Arr::get($this->action, 'prefix'))) {
145
-			$this->prefix($prefix);
146
-		}
147
-	}
148
-
149
-	// Getters
150
-
151
-	/**
152
-	 * Get the action of the current route.
153
-	 *
154
-	 * @return \Closure|string|array
155
-	 */
156
-	public function getAction()
157
-	{
158
-		return $this->action;
159
-	}
160
-
161
-	/**
162
-	 * Get the arguments of the current route.
163
-	 *
164
-	 * @return array
165
-	 */
166
-	public function getArguments()
167
-	{
168
-		return $this->wheres;
169
-	}
170
-
171
-	/**
172
-	 * Get the controller instance for the route.
173
-	 * 
174
-	 * @return mixed
175
-	 */
176
-	public function getController()
177
-	{
178
-		if ( ! $this->controller) {
179
-			$class = $this->parseControllerCallback()[0];
46
+    /**
47
+     * Action that the route will use when called.
48
+     *
49
+     * @var \Closure|string|array $action
50
+     */
51
+    public $action;
52
+
53
+    /**
54
+     * The container instance used by the route.
55
+     * 
56
+     * @var \Syscodes\Container\Container $container
57
+     */
58
+    protected $container;
59
+
60
+    /**
61
+     * The controller instance.
62
+     * 
63
+     * @var string $controller
64
+     */
65
+    public $controller;
66
+
67
+    /**
68
+     * The default values for the route.
69
+     * 
70
+     * @var array $defaults
71
+     */
72
+    public $defaults = [];
73
+
74
+    /**
75
+     * Variable of HTTP method.
76
+     *  
77
+     * @var array|string $method
78
+     */
79
+    public $method;
80
+
81
+    /**
82
+     * The array of matched parameters.
83
+     * 
84
+     * @var array $parameters
85
+     */
86
+    public $parameters = [];
87
+
88
+    /**
89
+     * The parameter names for the route.
90
+     * 
91
+     * @var string|null $parameterNames
92
+     */
93
+    public $parameterNames;
94
+
95
+    /**
96
+     * Patterns that should be replaced.
97
+     *
98
+     * @var array $patterns 
99
+     */
100
+    public $patterns = [
101
+        '~/~'                    =>  '\/',               // Slash
102
+        '~{an:[^\/{}]+}~'        => '([0-9a-zA-Z]++)',   // Placeholder accepts alphabetic and numeric chars
103
+        '~{n:[^\/{}]+}~'         => '([0-9]++)',         // Placeholder accepts only numeric
104
+        '~{a:[^\/{}]+}~'         => '([a-zA-Z]++)',      // Placeholder accepts only alphabetic chars
105
+        '~{w:[^\/{}]+}~'         => '([0-9a-zA-Z-_]++)', // Placeholder accepts alphanumeric and underscore
106
+        '~{\*:[^\/{}]+}~'        => '(.++)',             // Placeholder match rest of url
107
+        '~(\\\/)?{\?:[^\/{}]+}~' => '\/?([^\/]*)',		 // Optional placeholder
108
+        '~{[^\/{}]+}~'           => '([^\/]++)'			 // Normal placeholder
109
+    ];
110
+
111
+    /**
112
+     * The URI pattern the route responds to.
113
+     *
114
+     * @var array $uri
115
+     */
116
+    public $uri = [];
117
+
118
+    /**
119
+     * Contains the arguments of the current route.
120
+     *
121
+     * @var array $where
122
+     */
123
+    public $wheres = [];
124
+
125
+    /**
126
+     * Constructor. Initialize route.
127
+     *
128
+     * @param  array|string|null  $method  
129
+     * @param  string|null  $uri  
130
+     * @param  \Closure|string|null  $action  
131
+     *
132
+     * @return void
133
+     */
134
+    public function __construct($method = null, $uri = null, $action = null)
135
+    {
136
+        $this->uri = $uri;
137
+
138
+        // Set the method
139
+        $this->parseMethod($method);
140
+
141
+        // Set the action
142
+        $this->action = Arr::except($this->parseAction($action), ['prefix']);
143
+
144
+        if (is_null($prefix = Arr::get($this->action, 'prefix'))) {
145
+            $this->prefix($prefix);
146
+        }
147
+    }
148
+
149
+    // Getters
150
+
151
+    /**
152
+     * Get the action of the current route.
153
+     *
154
+     * @return \Closure|string|array
155
+     */
156
+    public function getAction()
157
+    {
158
+        return $this->action;
159
+    }
160
+
161
+    /**
162
+     * Get the arguments of the current route.
163
+     *
164
+     * @return array
165
+     */
166
+    public function getArguments()
167
+    {
168
+        return $this->wheres;
169
+    }
170
+
171
+    /**
172
+     * Get the controller instance for the route.
173
+     * 
174
+     * @return mixed
175
+     */
176
+    public function getController()
177
+    {
178
+        if ( ! $this->controller) {
179
+            $class = $this->parseControllerCallback()[0];
180 180
  
181
-			$this->controller = $this->container->make(ltrim($class, '\\'));
182
-		}
183
-
184
-		return $this->controller;
185
-	}
186
-
187
-	/**
188
-	 * Get the controller method used for the route.
189
-	 * 
190
-	 * @return string
191
-	 */
192
-	public function getControllerMethod()
193
-	{
194
-		return $this->parseControllerCallback()[1];
195
-	}
196
-
197
-	/**
198
-	 * Get the request method of the current route.
199
-	 *
200
-	 * @return array|string
201
-	 */
202
-	public function getMethod()
203
-	{
204
-		return $this->method;
205
-	}
206
-
207
-	/**
208
-	 * Get the url of the current route.
209
-	 *
210
-	 * @return string
211
-	 */
212
-	public function getName()
213
-	{
214
-		return $this->action['as'] ?? null;
215
-	}
216
-
217
-	/**
218
-	 * Get the url of the current route.
219
-	 *
220
-	 * @return array
221
-	 */
222
-	public function getRoute()
223
-	{
224
-		return $this->uri;
225
-	}
226
-
227
-	/**
228
-	 * Get or set the domain for the route.
229
-	 * 
230
-	 * @param  string|null  $domain  
231
-	 * 
232
-	 * @return $this
233
-	 */
234
-	public function domain($domain = null)
235
-	{
236
-		if (is_null($domain)) {
237
-			return $this->getDomain();
238
-		}
239
-
240
-		$this->action['domain'] = $this->parseRoute($domain);
241
-
242
-		return $this;
243
-	}
244
-
245
-	/**
246
-	 * Get the domain defined for the route.
247
-	 * 
248
-	 * @return string|null
249
-	 */
250
-	public function getDomain()
251
-	{
252
-		return isset($this->action['domain'])
253
-				? str_replace(['http://', 'https://'], '', $this->action['domain'])
254
-				: null;
255
-	}
256
-
257
-	/**
258
-	 * Parse the controller.
259
-	 * 
260
-	 * @return array
261
-	 */
262
-	public function parseControllerCallback()
263
-	{
264
-		return Str::parseCallback($this->action['uses']);
265
-	}
181
+            $this->controller = $this->container->make(ltrim($class, '\\'));
182
+        }
183
+
184
+        return $this->controller;
185
+    }
186
+
187
+    /**
188
+     * Get the controller method used for the route.
189
+     * 
190
+     * @return string
191
+     */
192
+    public function getControllerMethod()
193
+    {
194
+        return $this->parseControllerCallback()[1];
195
+    }
196
+
197
+    /**
198
+     * Get the request method of the current route.
199
+     *
200
+     * @return array|string
201
+     */
202
+    public function getMethod()
203
+    {
204
+        return $this->method;
205
+    }
206
+
207
+    /**
208
+     * Get the url of the current route.
209
+     *
210
+     * @return string
211
+     */
212
+    public function getName()
213
+    {
214
+        return $this->action['as'] ?? null;
215
+    }
216
+
217
+    /**
218
+     * Get the url of the current route.
219
+     *
220
+     * @return array
221
+     */
222
+    public function getRoute()
223
+    {
224
+        return $this->uri;
225
+    }
226
+
227
+    /**
228
+     * Get or set the domain for the route.
229
+     * 
230
+     * @param  string|null  $domain  
231
+     * 
232
+     * @return $this
233
+     */
234
+    public function domain($domain = null)
235
+    {
236
+        if (is_null($domain)) {
237
+            return $this->getDomain();
238
+        }
239
+
240
+        $this->action['domain'] = $this->parseRoute($domain);
241
+
242
+        return $this;
243
+    }
244
+
245
+    /**
246
+     * Get the domain defined for the route.
247
+     * 
248
+     * @return string|null
249
+     */
250
+    public function getDomain()
251
+    {
252
+        return isset($this->action['domain'])
253
+                ? str_replace(['http://', 'https://'], '', $this->action['domain'])
254
+                : null;
255
+    }
256
+
257
+    /**
258
+     * Parse the controller.
259
+     * 
260
+     * @return array
261
+     */
262
+    public function parseControllerCallback()
263
+    {
264
+        return Str::parseCallback($this->action['uses']);
265
+    }
266 266
 	
267
-	/**
268
-	 * Checks whether the route's action is a controller.
269
-	 * 
270
-	 * @return bool
271
-	 */
272
-	public function isControllerAction()
273
-	{
274
-		return is_string($this->action['uses']);
275
-	}
276
-
277
-	/**
278
-	 * Get the dispatcher for the route's controller.
279
-	 * 
280
-	 * @return \Syscodes\Controller\ControllerDispatcher
281
-	 */
282
-	private function controllerDispatcher()
283
-	{
284
-		return new ControllerDispatcher($this->container);
285
-	}
286
-
287
-	// Setters
267
+    /**
268
+     * Checks whether the route's action is a controller.
269
+     * 
270
+     * @return bool
271
+     */
272
+    public function isControllerAction()
273
+    {
274
+        return is_string($this->action['uses']);
275
+    }
276
+
277
+    /**
278
+     * Get the dispatcher for the route's controller.
279
+     * 
280
+     * @return \Syscodes\Controller\ControllerDispatcher
281
+     */
282
+    private function controllerDispatcher()
283
+    {
284
+        return new ControllerDispatcher($this->container);
285
+    }
286
+
287
+    // Setters
288 288
 	
289
-	/**
290
-	 * Run the route action and return the response.
291
-	 * 
292
-	 * @return mixed
293
-	 */
294
-	public function runResolver()
295
-	{
296
-		$this->container = $this->container ?: new Container;
297
-
298
-		try {
299
-			if ($this->isControllerAction()) {
300
-				return $this->runResolverController();
301
-			}
302
-
303
-			return $this->runResolverCallable();
304
-		} catch (HttpResponseException $e) {
305
-			return $e->getResponse();
306
-		}
307
-	}
308
-
309
-	/**
310
-	 * Run the route action and return the response.
311
-	 *  
312
-	 * @return mixed
313
-	 */
314
-	protected function runResolverCallable()
315
-	{
316
-		$callable = $this->action['uses'];
317
-
318
-		return $callable(...array_values($this->resolveMethodDependencies(
319
-			$this->parametersWithouNulls(), new ReflectionFunction($this->action['uses'])
320
-		)));
321
-	}
322
-
323
-	/**
324
-	 * Run the route action and return the response.
325
-	 * 
326
-	 * @return mixed
327
-	 */
328
-	protected function runResolverController()
329
-	{
330
-		return $this->controllerDispatcher()->dispatch($this, $this->getController(), $this->getControllerMethod());
331
-	}
332
-
333
-	/**
334
-	 * Set the action.
335
-	 *
336
-	 * @param  \Closure|string  $action
337
-	 *
338
-	 * @return $this
339
-	 *
340
-	 * @throws \InvalidArgumentException
341
-	 */
342
-	public function parseAction($action)
343
-	{
344
-		if ( ! (is_object($action) && ($action instanceof Closure)) && ($action === null || $action === '')) {
345
-			throw new InvalidArgumentException(__('route.actionClosureOrFunction'));
346
-		}
347
-
348
-		return RouteAction::parse($this->uri, $action);
349
-	}
350
-
351
-	/**
352
-	 * Set the method of the current route.
353
-	 *
354
-	 * @param  array  $method
355
-	 *
356
-	 * @return string $this
357
-	 * 
358
-	 * @throws \InvalidArgumentException
359
-	 */
360
-	public function parseMethod($method)
361
-	{
362
-		if ($method === null || empty($method)) {
363
-			throw new InvalidArgumentException(__('route.methodNotProvided'));
289
+    /**
290
+     * Run the route action and return the response.
291
+     * 
292
+     * @return mixed
293
+     */
294
+    public function runResolver()
295
+    {
296
+        $this->container = $this->container ?: new Container;
297
+
298
+        try {
299
+            if ($this->isControllerAction()) {
300
+                return $this->runResolverController();
301
+            }
302
+
303
+            return $this->runResolverCallable();
304
+        } catch (HttpResponseException $e) {
305
+            return $e->getResponse();
306
+        }
307
+    }
308
+
309
+    /**
310
+     * Run the route action and return the response.
311
+     *  
312
+     * @return mixed
313
+     */
314
+    protected function runResolverCallable()
315
+    {
316
+        $callable = $this->action['uses'];
317
+
318
+        return $callable(...array_values($this->resolveMethodDependencies(
319
+            $this->parametersWithouNulls(), new ReflectionFunction($this->action['uses'])
320
+        )));
321
+    }
322
+
323
+    /**
324
+     * Run the route action and return the response.
325
+     * 
326
+     * @return mixed
327
+     */
328
+    protected function runResolverController()
329
+    {
330
+        return $this->controllerDispatcher()->dispatch($this, $this->getController(), $this->getControllerMethod());
331
+    }
332
+
333
+    /**
334
+     * Set the action.
335
+     *
336
+     * @param  \Closure|string  $action
337
+     *
338
+     * @return $this
339
+     *
340
+     * @throws \InvalidArgumentException
341
+     */
342
+    public function parseAction($action)
343
+    {
344
+        if ( ! (is_object($action) && ($action instanceof Closure)) && ($action === null || $action === '')) {
345
+            throw new InvalidArgumentException(__('route.actionClosureOrFunction'));
346
+        }
347
+
348
+        return RouteAction::parse($this->uri, $action);
349
+    }
350
+
351
+    /**
352
+     * Set the method of the current route.
353
+     *
354
+     * @param  array  $method
355
+     *
356
+     * @return string $this
357
+     * 
358
+     * @throws \InvalidArgumentException
359
+     */
360
+    public function parseMethod($method)
361
+    {
362
+        if ($method === null || empty($method)) {
363
+            throw new InvalidArgumentException(__('route.methodNotProvided'));
364 364
 			
365
-		}
366
-
367
-		foreach ($method as $httpMethod) {
368
-			if ( ! in_array($httpMethod, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD', 'ANY'])) {
369
-				throw new InvalidArgumentException(__('route.methodNotAllowed'));				
370
-			}
371
-		}
372
-
373
-	    $this->method = $method;
374
-
375
-	    return $this;
376
-	}
377
-
378
-	/**
379
-	 * Set the route.
380
-	 *
381
-	 * @param  string|array|null  $uri
382
-	 *
383
-	 * @return string
384
-	 *
385
-	 * @throws  \InvalidArgumentException
386
-	 */
387
-	public function parseRoute($uri)
388
-	{
389
-		if ($uri === null) {
390
-			throw new InvalidArgumentException(__('route.uriNotProvided'));
391
-		}	
392
-
393
-		$this->uri = $this->parseRoutePath($uri);
394
-
395
-		return $this;
396
-	}
397
-
398
-	/**
399
-	 * Replace word patterns with regex in route uri.
400
-	 * 
401
-	 * @param  string  $uri
402
-	 * 
403
-	 * @return string
404
-	 */
405
-	protected function parseRoutePath($uri)
406
-	{
407
-		$uri = trim($uri, '\/?');
408
-		$uri = trim($uri, '\/');
365
+        }
366
+
367
+        foreach ($method as $httpMethod) {
368
+            if ( ! in_array($httpMethod, ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD', 'ANY'])) {
369
+                throw new InvalidArgumentException(__('route.methodNotAllowed'));				
370
+            }
371
+        }
372
+
373
+        $this->method = $method;
374
+
375
+        return $this;
376
+    }
377
+
378
+    /**
379
+     * Set the route.
380
+     *
381
+     * @param  string|array|null  $uri
382
+     *
383
+     * @return string
384
+     *
385
+     * @throws  \InvalidArgumentException
386
+     */
387
+    public function parseRoute($uri)
388
+    {
389
+        if ($uri === null) {
390
+            throw new InvalidArgumentException(__('route.uriNotProvided'));
391
+        }	
392
+
393
+        $this->uri = $this->parseRoutePath($uri);
394
+
395
+        return $this;
396
+    }
397
+
398
+    /**
399
+     * Replace word patterns with regex in route uri.
400
+     * 
401
+     * @param  string  $uri
402
+     * 
403
+     * @return string
404
+     */
405
+    protected function parseRoutePath($uri)
406
+    {
407
+        $uri = trim($uri, '\/?');
408
+        $uri = trim($uri, '\/');
409 409
 		
410
-		preg_match_all('/\{([\w\:]+?)\??\}/', $uri, $matches);
410
+        preg_match_all('/\{([\w\:]+?)\??\}/', $uri, $matches);
411 411
 		
412
-		foreach ($matches[1] as $match) {
413
-			if (strpos($match, ':') === false) {
414
-				continue;
415
-			}
412
+        foreach ($matches[1] as $match) {
413
+            if (strpos($match, ':') === false) {
414
+                continue;
415
+            }
416 416
 			
417
-			$pattern  = array_keys($this->patterns);
418
-			$replace  = array_values($this->patterns);
419
-			$segments = explode(':', trim($match, '{}?'));
417
+            $pattern  = array_keys($this->patterns);
418
+            $replace  = array_values($this->patterns);
419
+            $segments = explode(':', trim($match, '{}?'));
420 420
 			
421
-			$uri = strpos($match, ':') !== false
422
-					? preg_replace($pattern, $replace, $uri)
423
-					: str_replace($match, '{'.$segments[0].'}', $uri);
424
-		}
421
+            $uri = strpos($match, ':') !== false
422
+                    ? preg_replace($pattern, $replace, $uri)
423
+                    : str_replace($match, '{'.$segments[0].'}', $uri);
424
+        }
425 425
 		
426
-		return $uri;
427
-	}
428
-
429
-	/**
430
-	 * Add a prefix to the route URI.
431
-	 * 
432
-	 * @param  string  $prefix
433
-	 * 
434
-	 * @return $this
435
-	 */
436
-	public function prefix($prefix)
437
-	{
438
-		if ( ! empty($newPrefix = trim(rtrim($prefix, '/').'/'.ltrim($this->action['prefix'] ?? '', '/'), '/'))) {
439
-			$this->action['prefix'] = $newPrefix;
440
-		}
426
+        return $uri;
427
+    }
428
+
429
+    /**
430
+     * Add a prefix to the route URI.
431
+     * 
432
+     * @param  string  $prefix
433
+     * 
434
+     * @return $this
435
+     */
436
+    public function prefix($prefix)
437
+    {
438
+        if ( ! empty($newPrefix = trim(rtrim($prefix, '/').'/'.ltrim($this->action['prefix'] ?? '', '/'), '/'))) {
439
+            $this->action['prefix'] = $newPrefix;
440
+        }
441 441
 		
442
-		$uri = rtrim($prefix, '/').'/'.ltrim($this->uri, '/');
442
+        $uri = rtrim($prefix, '/').'/'.ltrim($this->uri, '/');
443 443
 		
444
-		return $this->parseRoute($uri !== '/' ? trim($uri, '/') : $uri);
445
-	}
446
-
447
-	/**
448
-	 * Set the action array for the route.
449
-	 * 
450
-	 * @param  array  $action
451
-	 * 
452
-	 * @return $this
453
-	 */
454
-	public function setAction(array $action)
455
-	{
456
-		$this->action = $action;
457
-
458
-		if (isset($this->action['domain'])) {
459
-			$this->domain($this->action['domain']);
460
-		}
444
+        return $this->parseRoute($uri !== '/' ? trim($uri, '/') : $uri);
445
+    }
446
+
447
+    /**
448
+     * Set the action array for the route.
449
+     * 
450
+     * @param  array  $action
451
+     * 
452
+     * @return $this
453
+     */
454
+    public function setAction(array $action)
455
+    {
456
+        $this->action = $action;
457
+
458
+        if (isset($this->action['domain'])) {
459
+            $this->domain($this->action['domain']);
460
+        }
461 461
 		
462
-		return $this;
463
-	}
464
-
465
-	/**
466
-	 * Set the name.
467
-	 *
468
-	 * @param  string  $name
469
-	 *
470
-	 * @return $this
471
-	 */
472
-	public function name($name)
473
-	{
474
-		$this->action['as'] = isset($this->action['as']) ? $this->action['as'].$name : $name;
475
-
476
-		return $this;
477
-	}
478
-
479
-	/**
480
-	 * Determine whether the route's name matches the given patterns.
481
-	 * 
482
-	 * @param  mixed  ...$patterns
483
-	 * 
484
-	 * @return bool
485
-	 */
486
-	public function named(...$patterns)
487
-	{
488
-		if (is_null($routeName = $this->getName())) {
489
-			return false;
490
-		}
491
-
492
-		foreach ($patterns as $pattern) {
493
-			if (Str::is($pattern, $routeName)) {
494
-				return true;
495
-			}
496
-		}
497
-
498
-		return false;
499
-	}
500
-
501
-	/**
502
-	 * Set a default value for the route.
503
-	 * 
504
-	 * @param  string  $key
505
-	 * @param  mixed   $value
506
-	 * 
507
-	 * @return $this
508
-	 */
509
-	public function defaults($key, $value)
510
-	{
511
-		$this->defaults[$key] = $value;
512
-
513
-		return $this;
514
-	}
515
-
516
-	/**
517
-	 * Set a default values for the route.
518
-	 * 
519
-	 * @param  string  $defaults
520
-	 * 
521
-	 * @return $this
522
-	 */
523
-	public function setDefaults(array $defaults)
524
-	{
525
-		$this->defaults = $defaults;
526
-
527
-		return $this;
528
-	}
529
-
530
-	/**
531
-	 * Set the where.
532
-	 *
533
-	 * @param  array|string  $name
534
-	 * @param  string|null  $expression  
535
-	 *
536
-	 * @return $this
537
-	 */
538
-	public function where($name, string $expression = null)
539
-	{
540
-		$wheres = is_array($name) ? $name : [$name => $expression];
462
+        return $this;
463
+    }
464
+
465
+    /**
466
+     * Set the name.
467
+     *
468
+     * @param  string  $name
469
+     *
470
+     * @return $this
471
+     */
472
+    public function name($name)
473
+    {
474
+        $this->action['as'] = isset($this->action['as']) ? $this->action['as'].$name : $name;
475
+
476
+        return $this;
477
+    }
478
+
479
+    /**
480
+     * Determine whether the route's name matches the given patterns.
481
+     * 
482
+     * @param  mixed  ...$patterns
483
+     * 
484
+     * @return bool
485
+     */
486
+    public function named(...$patterns)
487
+    {
488
+        if (is_null($routeName = $this->getName())) {
489
+            return false;
490
+        }
491
+
492
+        foreach ($patterns as $pattern) {
493
+            if (Str::is($pattern, $routeName)) {
494
+                return true;
495
+            }
496
+        }
497
+
498
+        return false;
499
+    }
500
+
501
+    /**
502
+     * Set a default value for the route.
503
+     * 
504
+     * @param  string  $key
505
+     * @param  mixed   $value
506
+     * 
507
+     * @return $this
508
+     */
509
+    public function defaults($key, $value)
510
+    {
511
+        $this->defaults[$key] = $value;
512
+
513
+        return $this;
514
+    }
515
+
516
+    /**
517
+     * Set a default values for the route.
518
+     * 
519
+     * @param  string  $defaults
520
+     * 
521
+     * @return $this
522
+     */
523
+    public function setDefaults(array $defaults)
524
+    {
525
+        $this->defaults = $defaults;
526
+
527
+        return $this;
528
+    }
529
+
530
+    /**
531
+     * Set the where.
532
+     *
533
+     * @param  array|string  $name
534
+     * @param  string|null  $expression  
535
+     *
536
+     * @return $this
537
+     */
538
+    public function where($name, string $expression = null)
539
+    {
540
+        $wheres = is_array($name) ? $name : [$name => $expression];
541 541
 		
542
-		foreach ($wheres as $name => $expression) {
543
-			$this->wheres[$name] = $expression;
544
-		}
545
-
546
-		return $this;
547
-	}
548
-
549
-	/**
550
-	 * Bind the route to a given request for execution.
551
-	 * 
552
-	 * @param  \Syscodes\Http\Request  $request
553
-	 * 
554
-	 * @return $this
555
-	 */
556
-	public function bind(Request $request)
557
-	{
558
-		$this->parameters = (new RouteParamBinding($this))->parameters($request);
559
-
560
-		return $this;
561
-	}
562
-
563
-	/**
564
-	 * Get all of the parameter names for the route.
565
-	 * 
566
-	 * @return array
567
-	 */
568
-	public function parameterNames()
569
-	{
570
-		if (isset($this->parameterNames)) {
571
-			return $this->parameterNames;
572
-		}
573
-
574
-		return $this->parameterNames = $this->compileParamNames();
575
-	}
576
-
577
-	/**
578
-	 * Get the parameter names for the route.
579
-	 * 
580
-	 * @return array
581
-	 */
582
-	protected function compileParamNames()
583
-	{
584
-		preg_match_all('~[^\/\{(.*?)\}]~', $this->domain().$this->uri, $matches);
585
-
586
-		return array_map(function ($match) {
587
-			return trim($match, '?');
588
-		}, $matches[0]);
589
-	}
590
-
591
-	/**
592
-	 * Get a given parameter from the route.
593
-	 * 
594
-	 * @param  string  $name
595
-	 * @param  mixed  $default  
596
-	 * 
597
-	 * @return array
598
-	 */
599
-	public function parameter($name, $default = null)
600
-	{
601
-		return Arr::get($this->parameters(), $name, $default);
602
-	}
603
-
604
-	/**
605
-	 * Set a parameter to the given value.
606
-	 * 
607
-	 * @param  string  $name
608
-	 * @param  mixed  $value
609
-	 * 
610
-	 * @return array
611
-	 */
612
-	public function setParameter($name, $value)
613
-	{
614
-		$this->parameters();
615
-
616
-		$this->parameters[$name] = $value;
617
-	}
618
-
619
-	/**
620
-	 * Get the key / value list of parameters without null values.
621
-	 * 
622
-	 * @return array
623
-	 */
624
-	public function parametersWithouNulls()
625
-	{
626
-		return array_filter($this->parameters(), function ($parameter) {
627
-			return ! is_null($parameter);
628
-		});
629
-	}
630
-
631
-	/**
632
-	 * Get the key / value list of parameters for the route.
633
-	 * 
634
-	 * @return array
635
-	 */
636
-	public function parameters()
637
-	{
638
-		if (isset($this->parameters)) {
639
-			return $this->parameters;
640
-		}
641
-
642
-		throw new LogicException('The route is not bound.');
643
-	}
644
-
645
-	/**
646
-	 * Determine if the route only responds to HTTP requests.
647
-	 * 
648
-	 * @return bool
649
-	 */
650
-	public function httpOnly()
651
-	{
652
-		return in_array('http', $this->action, true);
653
-	}
654
-
655
-	/**
656
-	 * Determine if the route only responds to HTTPS requests.
657
-	 * 
658
-	 * @return bool
659
-	 */
660
-	public function httpsOnly()
661
-	{
662
-		return $this->secure();
663
-	}
664
-
665
-	/**
666
-	 * Determine if the route only responds to HTTPS requests.
667
-	 * 
668
-	 * @return bool
669
-	 */
670
-	public function secure()
671
-	{
672
-		return in_array('https', $this->action, true);
673
-	}
674
-
675
-	/**
676
-	 * Set the container instance on the route.
677
-	 * 
678
-	 * @param  \Syscodes\Container\Container  $container
679
-	 * 
680
-	 * @return $this
681
-	 */
682
-	public function setContainer(Container $container)
683
-	{
684
-		$this->container = $container;
685
-
686
-		return $this;
687
-	}
688
-
689
-	/**
690
-	 * Dynamically access route parameters.
691
-	 * 
692
-	 * @param  string  $key
693
-	 * 
694
-	 * @return mixed
695
-	 */
696
-	public function __get($key)
697
-	{
698
-		return $this->parameter($key);
699
-	}
542
+        foreach ($wheres as $name => $expression) {
543
+            $this->wheres[$name] = $expression;
544
+        }
545
+
546
+        return $this;
547
+    }
548
+
549
+    /**
550
+     * Bind the route to a given request for execution.
551
+     * 
552
+     * @param  \Syscodes\Http\Request  $request
553
+     * 
554
+     * @return $this
555
+     */
556
+    public function bind(Request $request)
557
+    {
558
+        $this->parameters = (new RouteParamBinding($this))->parameters($request);
559
+
560
+        return $this;
561
+    }
562
+
563
+    /**
564
+     * Get all of the parameter names for the route.
565
+     * 
566
+     * @return array
567
+     */
568
+    public function parameterNames()
569
+    {
570
+        if (isset($this->parameterNames)) {
571
+            return $this->parameterNames;
572
+        }
573
+
574
+        return $this->parameterNames = $this->compileParamNames();
575
+    }
576
+
577
+    /**
578
+     * Get the parameter names for the route.
579
+     * 
580
+     * @return array
581
+     */
582
+    protected function compileParamNames()
583
+    {
584
+        preg_match_all('~[^\/\{(.*?)\}]~', $this->domain().$this->uri, $matches);
585
+
586
+        return array_map(function ($match) {
587
+            return trim($match, '?');
588
+        }, $matches[0]);
589
+    }
590
+
591
+    /**
592
+     * Get a given parameter from the route.
593
+     * 
594
+     * @param  string  $name
595
+     * @param  mixed  $default  
596
+     * 
597
+     * @return array
598
+     */
599
+    public function parameter($name, $default = null)
600
+    {
601
+        return Arr::get($this->parameters(), $name, $default);
602
+    }
603
+
604
+    /**
605
+     * Set a parameter to the given value.
606
+     * 
607
+     * @param  string  $name
608
+     * @param  mixed  $value
609
+     * 
610
+     * @return array
611
+     */
612
+    public function setParameter($name, $value)
613
+    {
614
+        $this->parameters();
615
+
616
+        $this->parameters[$name] = $value;
617
+    }
618
+
619
+    /**
620
+     * Get the key / value list of parameters without null values.
621
+     * 
622
+     * @return array
623
+     */
624
+    public function parametersWithouNulls()
625
+    {
626
+        return array_filter($this->parameters(), function ($parameter) {
627
+            return ! is_null($parameter);
628
+        });
629
+    }
630
+
631
+    /**
632
+     * Get the key / value list of parameters for the route.
633
+     * 
634
+     * @return array
635
+     */
636
+    public function parameters()
637
+    {
638
+        if (isset($this->parameters)) {
639
+            return $this->parameters;
640
+        }
641
+
642
+        throw new LogicException('The route is not bound.');
643
+    }
644
+
645
+    /**
646
+     * Determine if the route only responds to HTTP requests.
647
+     * 
648
+     * @return bool
649
+     */
650
+    public function httpOnly()
651
+    {
652
+        return in_array('http', $this->action, true);
653
+    }
654
+
655
+    /**
656
+     * Determine if the route only responds to HTTPS requests.
657
+     * 
658
+     * @return bool
659
+     */
660
+    public function httpsOnly()
661
+    {
662
+        return $this->secure();
663
+    }
664
+
665
+    /**
666
+     * Determine if the route only responds to HTTPS requests.
667
+     * 
668
+     * @return bool
669
+     */
670
+    public function secure()
671
+    {
672
+        return in_array('https', $this->action, true);
673
+    }
674
+
675
+    /**
676
+     * Set the container instance on the route.
677
+     * 
678
+     * @param  \Syscodes\Container\Container  $container
679
+     * 
680
+     * @return $this
681
+     */
682
+    public function setContainer(Container $container)
683
+    {
684
+        $this->container = $container;
685
+
686
+        return $this;
687
+    }
688
+
689
+    /**
690
+     * Dynamically access route parameters.
691
+     * 
692
+     * @param  string  $key
693
+     * 
694
+     * @return mixed
695
+     */
696
+    public function __get($key)
697
+    {
698
+        return $this->parameter($key);
699
+    }
700 700
 }
701 701
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/Routing/Concerns/RouteMap.php 1 patch
Indentation   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -29,139 +29,139 @@
 block discarded – undo
29 29
  */
30 30
 trait RouteMap
31 31
 {
32
-	/**
33
-	 * All of the verbs supported by the router.
34
-	 * 
35
-	 * @var array $verbs
36
-	 */
37
-	public static $verbs = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
32
+    /**
33
+     * All of the verbs supported by the router.
34
+     * 
35
+     * @var array $verbs
36
+     */
37
+    public static $verbs = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
38 38
 
39
-	/**
40
-	 * Add a route to the underlying route collection.
41
-	 *
42
-	 * @param  string  $method
43
-	 * @param  string  $route
44
-	 * @param  mixed  $action
45
-	 *
46
-	 * @return \Syscodes\Routing\Route
47
-	 */
48
-	abstract public function addRoute($method, $route, $action);
39
+    /**
40
+     * Add a route to the underlying route collection.
41
+     *
42
+     * @param  string  $method
43
+     * @param  string  $route
44
+     * @param  mixed  $action
45
+     *
46
+     * @return \Syscodes\Routing\Route
47
+     */
48
+    abstract public function addRoute($method, $route, $action);
49 49
 
50
-	/**
51
-	 * Add a route for all posible methods.
52
-	 *
53
-	 * @param  string  $route
54
-	 * @param  string|callable|null  $action
55
-	 *
56
-	 * @return void
57
-	 */
58
-	public function any($route, $action = null) 
59
-	{		
60
-		return $this->addRoute(self::$verbs, $route, $action);
61
-	}
50
+    /**
51
+     * Add a route for all posible methods.
52
+     *
53
+     * @param  string  $route
54
+     * @param  string|callable|null  $action
55
+     *
56
+     * @return void
57
+     */
58
+    public function any($route, $action = null) 
59
+    {		
60
+        return $this->addRoute(self::$verbs, $route, $action);
61
+    }
62 62
 	
63
-	/**
64
-	 * Add a route with delete method.
65
-	 *
66
-	 * @param  string  $route
67
-	 * @param  string|callable|null  $action
68
-	 *
69
-	 * @return void
70
-	 */
71
-	public function delete($route, $action = null) 
72
-	{
73
-		return $this->addRoute('DELETE', $route, $action);
74
-	}
63
+    /**
64
+     * Add a route with delete method.
65
+     *
66
+     * @param  string  $route
67
+     * @param  string|callable|null  $action
68
+     *
69
+     * @return void
70
+     */
71
+    public function delete($route, $action = null) 
72
+    {
73
+        return $this->addRoute('DELETE', $route, $action);
74
+    }
75 75
 
76
-	/**
77
-	 * Add a route with get method.
78
-	 *
79
-	 * @param  string  $route
80
-	 * @param  string|callable|null  $action
81
-	 *
82
-	 * @return void
83
-	 */
84
-	public function get($route, $action = null) 
85
-	{
86
-		return $this->addRoute(['GET', 'HEAD'], $route, $action);
87
-	}
76
+    /**
77
+     * Add a route with get method.
78
+     *
79
+     * @param  string  $route
80
+     * @param  string|callable|null  $action
81
+     *
82
+     * @return void
83
+     */
84
+    public function get($route, $action = null) 
85
+    {
86
+        return $this->addRoute(['GET', 'HEAD'], $route, $action);
87
+    }
88 88
 
89
-	/**
90
-	 * Add a route with head method.
91
-	 *
92
-	 * @param  string  $route
93
-	 * @param  string|callable|null  $action
94
-	 *
95
-	 * @return void
96
-	 */
97
-	public function head($route, $action = null)
98
-	{
99
-		return $this->addRoute('HEAD', $route, $action);
100
-	}
89
+    /**
90
+     * Add a route with head method.
91
+     *
92
+     * @param  string  $route
93
+     * @param  string|callable|null  $action
94
+     *
95
+     * @return void
96
+     */
97
+    public function head($route, $action = null)
98
+    {
99
+        return $this->addRoute('HEAD', $route, $action);
100
+    }
101 101
 
102
-	/**
103
-	 * Register a new route with the given methods.
104
-	 * 
105
-	 * @param  array|string  $methods
106
-	 * @param  string  $route
107
-	 * @param  string|callable|null  $action
108
-	 * 
109
-	 * @return void
110
-	 */
111
-	public function match($methods, $route, $action = null)
112
-	{
113
-		return $this->addRoute(array_map('strtoupper', (array) $methods), $route, $action);
114
-	}
102
+    /**
103
+     * Register a new route with the given methods.
104
+     * 
105
+     * @param  array|string  $methods
106
+     * @param  string  $route
107
+     * @param  string|callable|null  $action
108
+     * 
109
+     * @return void
110
+     */
111
+    public function match($methods, $route, $action = null)
112
+    {
113
+        return $this->addRoute(array_map('strtoupper', (array) $methods), $route, $action);
114
+    }
115 115
 
116
-	/**
117
-	 * Add a route with options method.
118
-	 *
119
-	 * @param  string  $route
120
-	 * @param  string|callable|null  $action
121
-	 *
122
-	 * @return void
123
-	 */
124
-	public function options($route, $action = null) 
125
-	{
126
-		return $this->addRoute('OPTIONS', $route, $action);
127
-	}
116
+    /**
117
+     * Add a route with options method.
118
+     *
119
+     * @param  string  $route
120
+     * @param  string|callable|null  $action
121
+     *
122
+     * @return void
123
+     */
124
+    public function options($route, $action = null) 
125
+    {
126
+        return $this->addRoute('OPTIONS', $route, $action);
127
+    }
128 128
 
129
-	/**
130
-	 * Add a route with patch method.
131
-	 *
132
-	 * @param  string  $route
133
-	 * @param  string|callable|null  $action
134
-	 *
135
-	 * @return void
136
-	 */
137
-	public function patch($route, $action = null)
138
-	{
139
-		return $this->addRoute('PATCH', $route, $action);
140
-	}
129
+    /**
130
+     * Add a route with patch method.
131
+     *
132
+     * @param  string  $route
133
+     * @param  string|callable|null  $action
134
+     *
135
+     * @return void
136
+     */
137
+    public function patch($route, $action = null)
138
+    {
139
+        return $this->addRoute('PATCH', $route, $action);
140
+    }
141 141
 
142
-	/**
143
-	 * Add a route with post method.
144
-	 *
145
-	 * @param  string  $route
146
-	 * @param  string|callable|null  $action
147
-	 *
148
-	 * @return void
149
-	 */
150
-	public function post($route, $action = null) 
151
-	{
152
-		return $this->addRoute('POST', $route, $action);
153
-	}
142
+    /**
143
+     * Add a route with post method.
144
+     *
145
+     * @param  string  $route
146
+     * @param  string|callable|null  $action
147
+     *
148
+     * @return void
149
+     */
150
+    public function post($route, $action = null) 
151
+    {
152
+        return $this->addRoute('POST', $route, $action);
153
+    }
154 154
 
155
-	/**
156
-	 * Add a route with put method.
157
-	 *
158
-	 * @param  string  $route
159
-	 * @param  string|callable|null  $action
160
-	 *
161
-	 * @return void
162
-	 */
163
-	public function put($route, $action = null) 
164
-	{
165
-		return $this->addRoute('PUT', $route, $action);
166
-	}  
155
+    /**
156
+     * Add a route with put method.
157
+     *
158
+     * @param  string  $route
159
+     * @param  string|callable|null  $action
160
+     *
161
+     * @return void
162
+     */
163
+    public function put($route, $action = null) 
164
+    {
165
+        return $this->addRoute('PUT', $route, $action);
166
+    }  
167 167
 }
168 168
\ No newline at end of file
Please login to merge, or discard this patch.