@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | protected static function usesAction($uri) |
| 78 | 78 | { |
| 79 | - return ['uses' => function () use ($uri) { |
|
| 79 | + return ['uses' => function() use ($uri) { |
|
| 80 | 80 | throw new LogicException(__('route.hasNoAction', ['uri' => $uri])); |
| 81 | 81 | }]; |
| 82 | 82 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | protected static function findClosureAction(array $action) |
| 92 | 92 | { |
| 93 | - return Arr::first($action, function ($value, $key) { |
|
| 93 | + return Arr::first($action, function($value, $key) { |
|
| 94 | 94 | return is_callable($value) && is_numeric($key); |
| 95 | 95 | }); |
| 96 | 96 | } |
@@ -31,94 +31,94 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | interface Routable |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * Add a route for all posible methods. |
|
| 36 | - * |
|
| 37 | - * @param string $route |
|
| 38 | - * @param \Closure|array|string $action |
|
| 39 | - * |
|
| 40 | - * @return void |
|
| 41 | - */ |
|
| 42 | - public function any($route, $action); |
|
| 34 | + /** |
|
| 35 | + * Add a route for all posible methods. |
|
| 36 | + * |
|
| 37 | + * @param string $route |
|
| 38 | + * @param \Closure|array|string $action |
|
| 39 | + * |
|
| 40 | + * @return void |
|
| 41 | + */ |
|
| 42 | + public function any($route, $action); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Add a route with delete method. |
|
| 46 | - * |
|
| 47 | - * @param string $route |
|
| 48 | - * @param \Closure|array|string $action |
|
| 49 | - * |
|
| 50 | - * @return void |
|
| 51 | - */ |
|
| 52 | - public function delete($route, $action); |
|
| 44 | + /** |
|
| 45 | + * Add a route with delete method. |
|
| 46 | + * |
|
| 47 | + * @param string $route |
|
| 48 | + * @param \Closure|array|string $action |
|
| 49 | + * |
|
| 50 | + * @return void |
|
| 51 | + */ |
|
| 52 | + public function delete($route, $action); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Add a route with get method. |
|
| 56 | - * |
|
| 57 | - * @param string $route |
|
| 58 | - * @param \Closure|array|string $action |
|
| 59 | - * |
|
| 60 | - * @return void |
|
| 61 | - */ |
|
| 62 | - public function get($route, $action); |
|
| 54 | + /** |
|
| 55 | + * Add a route with get method. |
|
| 56 | + * |
|
| 57 | + * @param string $route |
|
| 58 | + * @param \Closure|array|string $action |
|
| 59 | + * |
|
| 60 | + * @return void |
|
| 61 | + */ |
|
| 62 | + public function get($route, $action); |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Add a route with head method. |
|
| 66 | - * |
|
| 67 | - * @param string $route |
|
| 68 | - * @param \Closure|array|string $action |
|
| 69 | - * |
|
| 70 | - * @return void |
|
| 71 | - */ |
|
| 72 | - public function head($route, $action); |
|
| 64 | + /** |
|
| 65 | + * Add a route with head method. |
|
| 66 | + * |
|
| 67 | + * @param string $route |
|
| 68 | + * @param \Closure|array|string $action |
|
| 69 | + * |
|
| 70 | + * @return void |
|
| 71 | + */ |
|
| 72 | + public function head($route, $action); |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Add a route with options method |
|
| 76 | - * |
|
| 77 | - * @param string $route |
|
| 78 | - * @param \Closure|array|string $action |
|
| 79 | - * |
|
| 80 | - * @return void |
|
| 81 | - */ |
|
| 82 | - public function options($route, $action); |
|
| 74 | + /** |
|
| 75 | + * Add a route with options method |
|
| 76 | + * |
|
| 77 | + * @param string $route |
|
| 78 | + * @param \Closure|array|string $action |
|
| 79 | + * |
|
| 80 | + * @return void |
|
| 81 | + */ |
|
| 82 | + public function options($route, $action); |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Add a route with patch method. |
|
| 86 | - * |
|
| 87 | - * @param string $route |
|
| 88 | - * @param \Closure|array|string $action |
|
| 89 | - * |
|
| 90 | - * @return void |
|
| 91 | - */ |
|
| 92 | - public function patch($route, $action); |
|
| 84 | + /** |
|
| 85 | + * Add a route with patch method. |
|
| 86 | + * |
|
| 87 | + * @param string $route |
|
| 88 | + * @param \Closure|array|string $action |
|
| 89 | + * |
|
| 90 | + * @return void |
|
| 91 | + */ |
|
| 92 | + public function patch($route, $action); |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Add a route with post method. |
|
| 96 | - * |
|
| 97 | - * @param string $route |
|
| 98 | - * @param \Closure|array|string $action |
|
| 99 | - * |
|
| 100 | - * @return void |
|
| 101 | - */ |
|
| 102 | - public function post($route, $action); |
|
| 94 | + /** |
|
| 95 | + * Add a route with post method. |
|
| 96 | + * |
|
| 97 | + * @param string $route |
|
| 98 | + * @param \Closure|array|string $action |
|
| 99 | + * |
|
| 100 | + * @return void |
|
| 101 | + */ |
|
| 102 | + public function post($route, $action); |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Add a route with put method. |
|
| 106 | - * |
|
| 107 | - * @param string $route |
|
| 108 | - * @param \Closure|array|string $action |
|
| 109 | - * |
|
| 110 | - * @return void |
|
| 111 | - */ |
|
| 112 | - public function put($route, $action); |
|
| 104 | + /** |
|
| 105 | + * Add a route with put method. |
|
| 106 | + * |
|
| 107 | + * @param string $route |
|
| 108 | + * @param \Closure|array|string $action |
|
| 109 | + * |
|
| 110 | + * @return void |
|
| 111 | + */ |
|
| 112 | + public function put($route, $action); |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Group a series of routes under a single URL segment. This is handy |
|
| 116 | - * for grouping items into an admin area. |
|
| 117 | - * |
|
| 118 | - * @param array $attributes |
|
| 119 | - * @param \Closure|string $callback |
|
| 120 | - * |
|
| 121 | - * @return void |
|
| 122 | - */ |
|
| 123 | - public function group(array $attributes, $parameters); |
|
| 114 | + /** |
|
| 115 | + * Group a series of routes under a single URL segment. This is handy |
|
| 116 | + * for grouping items into an admin area. |
|
| 117 | + * |
|
| 118 | + * @param array $attributes |
|
| 119 | + * @param \Closure|string $callback |
|
| 120 | + * |
|
| 121 | + * @return void |
|
| 122 | + */ |
|
| 123 | + public function group(array $attributes, $parameters); |
|
| 124 | 124 | } |
| 125 | 125 | \ No newline at end of file |
@@ -30,19 +30,19 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | interface Application |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * Runs the current command discovered on the CLI. |
|
| 35 | - * |
|
| 36 | - * @return void |
|
| 37 | - */ |
|
| 38 | - public function run(); |
|
| 33 | + /** |
|
| 34 | + * Runs the current command discovered on the CLI. |
|
| 35 | + * |
|
| 36 | + * @return void |
|
| 37 | + */ |
|
| 38 | + public function run(); |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Displays basic information about the Console. |
|
| 42 | - * |
|
| 43 | - * @return void |
|
| 44 | - * |
|
| 45 | - * @uses Version::RELEASE |
|
| 46 | - */ |
|
| 47 | - public function showHeader(); |
|
| 40 | + /** |
|
| 41 | + * Displays basic information about the Console. |
|
| 42 | + * |
|
| 43 | + * @return void |
|
| 44 | + * |
|
| 45 | + * @uses Version::RELEASE |
|
| 46 | + */ |
|
| 47 | + public function showHeader(); |
|
| 48 | 48 | } |
| 49 | 49 | \ No newline at end of file |
@@ -31,12 +31,12 @@ |
||
| 31 | 31 | interface Factory |
| 32 | 32 | { |
| 33 | 33 | /** |
| 34 | - * Check existance view file. |
|
| 35 | - * |
|
| 36 | - * @param string $view |
|
| 37 | - * |
|
| 38 | - * @return bool |
|
| 39 | - */ |
|
| 34 | + * Check existance view file. |
|
| 35 | + * |
|
| 36 | + * @param string $view |
|
| 37 | + * |
|
| 38 | + * @return bool |
|
| 39 | + */ |
|
| 40 | 40 | public function viewExists($view); |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -32,29 +32,29 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | interface View extends Renderable |
| 34 | 34 | { |
| 35 | - /** |
|
| 36 | - * Add a piece of data to the view. |
|
| 37 | - * |
|
| 38 | - * @example $view->assign($content, $data); |
|
| 39 | - * |
|
| 40 | - * @param string|array $key |
|
| 41 | - * @param mixed $value |
|
| 42 | - * |
|
| 43 | - * @return $this |
|
| 44 | - */ |
|
| 45 | - public function assign($key, $value = null); |
|
| 35 | + /** |
|
| 36 | + * Add a piece of data to the view. |
|
| 37 | + * |
|
| 38 | + * @example $view->assign($content, $data); |
|
| 39 | + * |
|
| 40 | + * @param string|array $key |
|
| 41 | + * @param mixed $value |
|
| 42 | + * |
|
| 43 | + * @return $this |
|
| 44 | + */ |
|
| 45 | + public function assign($key, $value = null); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Assigns a value by reference. The benefit of binding is that values can be altered |
|
| 49 | - * without re-setting them. It is also possible to bind variables before they have values. |
|
| 50 | - * Assigned values will be available as a variable within the view file: |
|
| 51 | - * |
|
| 52 | - * @example $view->bind('ref', $bar); |
|
| 53 | - * |
|
| 54 | - * @param string $key Variable name |
|
| 55 | - * @param mixed $value Referenced variable |
|
| 56 | - * |
|
| 57 | - * @return $this |
|
| 58 | - */ |
|
| 59 | - public function bind($key, & $value); |
|
| 47 | + /** |
|
| 48 | + * Assigns a value by reference. The benefit of binding is that values can be altered |
|
| 49 | + * without re-setting them. It is also possible to bind variables before they have values. |
|
| 50 | + * Assigned values will be available as a variable within the view file: |
|
| 51 | + * |
|
| 52 | + * @example $view->bind('ref', $bar); |
|
| 53 | + * |
|
| 54 | + * @param string $key Variable name |
|
| 55 | + * @param mixed $value Referenced variable |
|
| 56 | + * |
|
| 57 | + * @return $this |
|
| 58 | + */ |
|
| 59 | + public function bind($key, & $value); |
|
| 60 | 60 | } |
| 61 | 61 | \ No newline at end of file |
@@ -32,88 +32,88 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | interface Handler |
| 34 | 34 | { |
| 35 | - const ERROR_HANDLER = "HandleError"; |
|
| 36 | - const EXCEPTION_HANDLER = "handleException"; |
|
| 37 | - const SHUTDOWN_HANDLER = "handleShutdown"; |
|
| 35 | + const ERROR_HANDLER = "HandleError"; |
|
| 36 | + const EXCEPTION_HANDLER = "handleException"; |
|
| 37 | + const SHUTDOWN_HANDLER = "handleShutdown"; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Catches any uncaught errors and exceptions, including most Fatal errors. Will log the |
|
| 41 | - * error, display it if display_errors is on, and fire an event that allows custom actions |
|
| 42 | - * to be taken at this point. |
|
| 43 | - * |
|
| 44 | - * @param \Throwable $exception |
|
| 45 | - * |
|
| 46 | - * @return string |
|
| 47 | - */ |
|
| 48 | - public function handleException(Throwable $exception); |
|
| 39 | + /** |
|
| 40 | + * Catches any uncaught errors and exceptions, including most Fatal errors. Will log the |
|
| 41 | + * error, display it if display_errors is on, and fire an event that allows custom actions |
|
| 42 | + * to be taken at this point. |
|
| 43 | + * |
|
| 44 | + * @param \Throwable $exception |
|
| 45 | + * |
|
| 46 | + * @return string |
|
| 47 | + */ |
|
| 48 | + public function handleException(Throwable $exception); |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Pushes a handler to the end of the stack. |
|
| 52 | - * |
|
| 53 | - * @param string|callable $handler |
|
| 54 | - * |
|
| 55 | - * @return \Syscodes\Contracts\Debug\Handler |
|
| 56 | - */ |
|
| 57 | - public function pushHandler($handler); |
|
| 50 | + /** |
|
| 51 | + * Pushes a handler to the end of the stack. |
|
| 52 | + * |
|
| 53 | + * @param string|callable $handler |
|
| 54 | + * |
|
| 55 | + * @return \Syscodes\Contracts\Debug\Handler |
|
| 56 | + */ |
|
| 57 | + public function pushHandler($handler); |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Unregisters all handlers registered by this Debug instance. |
|
| 61 | - * |
|
| 62 | - * @return void |
|
| 63 | - */ |
|
| 64 | - public function off(); |
|
| 59 | + /** |
|
| 60 | + * Unregisters all handlers registered by this Debug instance. |
|
| 61 | + * |
|
| 62 | + * @return void |
|
| 63 | + */ |
|
| 64 | + public function off(); |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Registers this instance as an error handler. |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - public function on(); |
|
| 66 | + /** |
|
| 67 | + * Registers this instance as an error handler. |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + public function on(); |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Lenevor Exception push output directly to the client it the data |
|
| 75 | - * if they are true, but if it is false, the output will be returned |
|
| 76 | - * by exception. |
|
| 77 | - * |
|
| 78 | - * @param bool|int $send |
|
| 79 | - * |
|
| 80 | - * @return bool |
|
| 81 | - */ |
|
| 82 | - public function writeToOutput($send = null); |
|
| 73 | + /** |
|
| 74 | + * Lenevor Exception push output directly to the client it the data |
|
| 75 | + * if they are true, but if it is false, the output will be returned |
|
| 76 | + * by exception. |
|
| 77 | + * |
|
| 78 | + * @param bool|int $send |
|
| 79 | + * |
|
| 80 | + * @return bool |
|
| 81 | + */ |
|
| 82 | + public function writeToOutput($send = null); |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Error handler |
|
| 86 | - * |
|
| 87 | - * This will catch the php native error and treat it as a exception which will |
|
| 88 | - * provide a full back trace on all errors. |
|
| 89 | - * |
|
| 90 | - * @param int $level |
|
| 91 | - * @param string $message |
|
| 92 | - * @param string|null $file |
|
| 93 | - * @param int|null $line |
|
| 94 | - * |
|
| 95 | - * @throws \ErrorException |
|
| 96 | - */ |
|
| 97 | - public function handleError(int $level, string $message, string $file = null, int $line = null); |
|
| 84 | + /** |
|
| 85 | + * Error handler |
|
| 86 | + * |
|
| 87 | + * This will catch the php native error and treat it as a exception which will |
|
| 88 | + * provide a full back trace on all errors. |
|
| 89 | + * |
|
| 90 | + * @param int $level |
|
| 91 | + * @param string $message |
|
| 92 | + * @param string|null $file |
|
| 93 | + * @param int|null $line |
|
| 94 | + * |
|
| 95 | + * @throws \ErrorException |
|
| 96 | + */ |
|
| 97 | + public function handleError(int $level, string $message, string $file = null, int $line = null); |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Lenevor Exception will by default send HTTP code 500, but you may wish |
|
| 101 | - * to use 502, 503, or another 5xx family code. |
|
| 102 | - * |
|
| 103 | - * @param bool|int $code |
|
| 104 | - * |
|
| 105 | - * @return int|false |
|
| 106 | - * |
|
| 107 | - * @throws \InvalidArgumentException |
|
| 108 | - */ |
|
| 109 | - public function sendHttpCode($code = null); |
|
| 99 | + /** |
|
| 100 | + * Lenevor Exception will by default send HTTP code 500, but you may wish |
|
| 101 | + * to use 502, 503, or another 5xx family code. |
|
| 102 | + * |
|
| 103 | + * @param bool|int $code |
|
| 104 | + * |
|
| 105 | + * @return int|false |
|
| 106 | + * |
|
| 107 | + * @throws \InvalidArgumentException |
|
| 108 | + */ |
|
| 109 | + public function sendHttpCode($code = null); |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * This will catch errors that are generated at the shutdown level of execution. |
|
| 113 | - * |
|
| 114 | - * @return void |
|
| 115 | - * |
|
| 116 | - * @throws \ErrorException |
|
| 117 | - */ |
|
| 118 | - public function handleShutdown(); |
|
| 111 | + /** |
|
| 112 | + * This will catch errors that are generated at the shutdown level of execution. |
|
| 113 | + * |
|
| 114 | + * @return void |
|
| 115 | + * |
|
| 116 | + * @throws \ErrorException |
|
| 117 | + */ |
|
| 118 | + public function handleShutdown(); |
|
| 119 | 119 | } |
| 120 | 120 | \ No newline at end of file |
@@ -30,54 +30,54 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | interface Configure |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * Determine if the given configuration value exists. |
|
| 35 | - * |
|
| 36 | - * @param string $key |
|
| 37 | - * |
|
| 38 | - * @return bool |
|
| 39 | - */ |
|
| 40 | - public function has(string $key); |
|
| 33 | + /** |
|
| 34 | + * Determine if the given configuration value exists. |
|
| 35 | + * |
|
| 36 | + * @param string $key |
|
| 37 | + * |
|
| 38 | + * @return bool |
|
| 39 | + */ |
|
| 40 | + public function has(string $key); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Deletes a (dot notated) config item. |
|
| 44 | - * |
|
| 45 | - * @param string $key A (dot notated) config key |
|
| 46 | - * |
|
| 47 | - * @return array|bool |
|
| 48 | - * |
|
| 49 | - * @uses \Syscodes\Support\Arr |
|
| 50 | - */ |
|
| 51 | - public function erase(string $key); |
|
| 42 | + /** |
|
| 43 | + * Deletes a (dot notated) config item. |
|
| 44 | + * |
|
| 45 | + * @param string $key A (dot notated) config key |
|
| 46 | + * |
|
| 47 | + * @return array|bool |
|
| 48 | + * |
|
| 49 | + * @uses \Syscodes\Support\Arr |
|
| 50 | + */ |
|
| 51 | + public function erase(string $key); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Returns a (dot notated) config setting. |
|
| 55 | - * |
|
| 56 | - * @param string $key The dot-notated key or array of keys |
|
| 57 | - * @param mixed $default The default value |
|
| 58 | - * |
|
| 59 | - * @return mixed |
|
| 60 | - * |
|
| 61 | - * @uses \Syscodes\Support\Arr |
|
| 62 | - */ |
|
| 63 | - public function get(string $key, $default = null); |
|
| 53 | + /** |
|
| 54 | + * Returns a (dot notated) config setting. |
|
| 55 | + * |
|
| 56 | + * @param string $key The dot-notated key or array of keys |
|
| 57 | + * @param mixed $default The default value |
|
| 58 | + * |
|
| 59 | + * @return mixed |
|
| 60 | + * |
|
| 61 | + * @uses \Syscodes\Support\Arr |
|
| 62 | + */ |
|
| 63 | + public function get(string $key, $default = null); |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Sets a value in the config array. |
|
| 67 | - * |
|
| 68 | - * @param string $key The dot-notated key or array of keys |
|
| 69 | - * @param mixed $value The default value |
|
| 70 | - * |
|
| 71 | - * @return mixed |
|
| 72 | - * |
|
| 73 | - * @uses \Syscodes\Support\Arr |
|
| 74 | - */ |
|
| 75 | - public function set(string $key, $value); |
|
| 65 | + /** |
|
| 66 | + * Sets a value in the config array. |
|
| 67 | + * |
|
| 68 | + * @param string $key The dot-notated key or array of keys |
|
| 69 | + * @param mixed $value The default value |
|
| 70 | + * |
|
| 71 | + * @return mixed |
|
| 72 | + * |
|
| 73 | + * @uses \Syscodes\Support\Arr |
|
| 74 | + */ |
|
| 75 | + public function set(string $key, $value); |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Get all of the configuration items for the application. |
|
| 79 | - * |
|
| 80 | - * @return array |
|
| 81 | - */ |
|
| 82 | - public function all(); |
|
| 77 | + /** |
|
| 78 | + * Get all of the configuration items for the application. |
|
| 79 | + * |
|
| 80 | + * @return array |
|
| 81 | + */ |
|
| 82 | + public function all(); |
|
| 83 | 83 | } |
| 84 | 84 | \ No newline at end of file |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function extend($id, Closure $closure); |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Marks a callable as being a factory service. |
|
| 71 | - * |
|
| 72 | - * @param string $id |
|
| 73 | - * |
|
| 74 | - * @return \Closure |
|
| 75 | - */ |
|
| 69 | + /** |
|
| 70 | + * Marks a callable as being a factory service. |
|
| 71 | + * |
|
| 72 | + * @param string $id |
|
| 73 | + * |
|
| 74 | + * @return \Closure |
|
| 75 | + */ |
|
| 76 | 76 | public function factory($id); |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -82,14 +82,14 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function getBindings(); |
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Register an existing instance as singleton in the container. |
|
| 87 | - * |
|
| 88 | - * @param string $id |
|
| 89 | - * @param mixed $instance |
|
| 90 | - * |
|
| 91 | - * @return mixed |
|
| 92 | - */ |
|
| 85 | + /** |
|
| 86 | + * Register an existing instance as singleton in the container. |
|
| 87 | + * |
|
| 88 | + * @param string $id |
|
| 89 | + * @param mixed $instance |
|
| 90 | + * |
|
| 91 | + * @return mixed |
|
| 92 | + */ |
|
| 93 | 93 | public function instance($id, $instance); |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function set($id, string $value); |
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Register a singleton binding in the container. |
|
| 126 | - * |
|
| 127 | - * @param string $id |
|
| 128 | - * @param \Closure|string|null $value |
|
| 129 | - * |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 124 | + /** |
|
| 125 | + * Register a singleton binding in the container. |
|
| 126 | + * |
|
| 127 | + * @param string $id |
|
| 128 | + * @param \Closure|string|null $value |
|
| 129 | + * |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | 132 | public function singleton($id, $value = null); |
| 133 | 133 | } |
| 134 | 134 | \ No newline at end of file |
@@ -875,7 +875,7 @@ |
||
| 875 | 875 | |
| 876 | 876 | foreach ($this->cookies as $key => $value) |
| 877 | 877 | { |
| 878 | - $cookies[]= "{$key} = {$value}"; |
|
| 878 | + $cookies[] = "{$key} = {$value}"; |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | if ( ! empty($cookies)) |
@@ -39,868 +39,868 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class Request |
| 41 | 41 | { |
| 42 | - /** |
|
| 43 | - * Holds the global active request instance. |
|
| 44 | - * |
|
| 45 | - * @var bool $requestURI |
|
| 46 | - */ |
|
| 47 | - protected static $requestURI; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * The base URL. |
|
| 51 | - * |
|
| 52 | - * @var string $baseUrl |
|
| 53 | - */ |
|
| 54 | - protected $baseUrl; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Gets cookies ($_COOKIE). |
|
| 58 | - * |
|
| 59 | - * @var string $cookies |
|
| 60 | - */ |
|
| 61 | - public $cookies; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Gets the string with format JSON. |
|
| 65 | - * |
|
| 66 | - * @var string|resource|null $content |
|
| 67 | - */ |
|
| 68 | - protected $content; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * The default Locale this request. |
|
| 72 | - * |
|
| 73 | - * @var string $defaultLocale |
|
| 74 | - */ |
|
| 75 | - protected $defaultLocale = 'en'; |
|
| 42 | + /** |
|
| 43 | + * Holds the global active request instance. |
|
| 44 | + * |
|
| 45 | + * @var bool $requestURI |
|
| 46 | + */ |
|
| 47 | + protected static $requestURI; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * The base URL. |
|
| 51 | + * |
|
| 52 | + * @var string $baseUrl |
|
| 53 | + */ |
|
| 54 | + protected $baseUrl; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Gets cookies ($_COOKIE). |
|
| 58 | + * |
|
| 59 | + * @var string $cookies |
|
| 60 | + */ |
|
| 61 | + public $cookies; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Gets the string with format JSON. |
|
| 65 | + * |
|
| 66 | + * @var string|resource|null $content |
|
| 67 | + */ |
|
| 68 | + protected $content; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * The default Locale this request. |
|
| 72 | + * |
|
| 73 | + * @var string $defaultLocale |
|
| 74 | + */ |
|
| 75 | + protected $defaultLocale = 'en'; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Gets files request ($_FILES). |
|
| 79 | - * |
|
| 80 | - * @var string $files |
|
| 81 | - */ |
|
| 82 | - public $files; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * The detected uri and server variables. |
|
| 86 | - * |
|
| 87 | - * @var string $http |
|
| 88 | - */ |
|
| 89 | - protected $http; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * The decoded JSON content for the request. |
|
| 93 | - * |
|
| 94 | - * @var \Syscodes\Http\Contributors\Parameters|null $json |
|
| 95 | - */ |
|
| 96 | - protected $json; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * The current language of the application. |
|
| 100 | - * |
|
| 101 | - * @var string $languages |
|
| 102 | - */ |
|
| 103 | - protected $languages; |
|
| 77 | + /** |
|
| 78 | + * Gets files request ($_FILES). |
|
| 79 | + * |
|
| 80 | + * @var string $files |
|
| 81 | + */ |
|
| 82 | + public $files; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * The detected uri and server variables. |
|
| 86 | + * |
|
| 87 | + * @var string $http |
|
| 88 | + */ |
|
| 89 | + protected $http; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * The decoded JSON content for the request. |
|
| 93 | + * |
|
| 94 | + * @var \Syscodes\Http\Contributors\Parameters|null $json |
|
| 95 | + */ |
|
| 96 | + protected $json; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * The current language of the application. |
|
| 100 | + * |
|
| 101 | + * @var string $languages |
|
| 102 | + */ |
|
| 103 | + protected $languages; |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * The method name. |
|
| 107 | - * |
|
| 108 | - * @var string $method |
|
| 109 | - */ |
|
| 110 | - protected $method; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * The path info of URL. |
|
| 114 | - * |
|
| 115 | - * @var string $pathInfo |
|
| 116 | - */ |
|
| 117 | - protected $pathInfo; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Request body parameters ($_POST). |
|
| 121 | - * |
|
| 122 | - * @var \Syscodes\Http\Contributors\Parameters $request |
|
| 123 | - */ |
|
| 124 | - public $request; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Get request URI. |
|
| 128 | - * |
|
| 129 | - * @var string $requestToURI |
|
| 130 | - */ |
|
| 131 | - protected $requestToURI; |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * The detected uri and server variables ($_FILES). |
|
| 135 | - * |
|
| 136 | - * @var array $server |
|
| 137 | - */ |
|
| 138 | - public $server = []; |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * List of routes uri. |
|
| 142 | - * |
|
| 143 | - * @var string|array $uri |
|
| 144 | - */ |
|
| 145 | - public $uri; |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Stores the valid locale codes. |
|
| 149 | - * |
|
| 150 | - * @var array $validLocales |
|
| 151 | - */ |
|
| 152 | - protected $validLocales = []; |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Constructor: Create new the Request class. |
|
| 156 | - * |
|
| 157 | - * @param array $request |
|
| 158 | - * @param array $cookies |
|
| 159 | - * @param array $files |
|
| 160 | - * @param array $server |
|
| 161 | - * @param string|resource|null $content (null by default) |
|
| 162 | - * |
|
| 163 | - * @return void |
|
| 164 | - */ |
|
| 165 | - public function __construct(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null) |
|
| 166 | - { |
|
| 167 | - static::$requestURI = $this; |
|
| 105 | + /** |
|
| 106 | + * The method name. |
|
| 107 | + * |
|
| 108 | + * @var string $method |
|
| 109 | + */ |
|
| 110 | + protected $method; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * The path info of URL. |
|
| 114 | + * |
|
| 115 | + * @var string $pathInfo |
|
| 116 | + */ |
|
| 117 | + protected $pathInfo; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Request body parameters ($_POST). |
|
| 121 | + * |
|
| 122 | + * @var \Syscodes\Http\Contributors\Parameters $request |
|
| 123 | + */ |
|
| 124 | + public $request; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Get request URI. |
|
| 128 | + * |
|
| 129 | + * @var string $requestToURI |
|
| 130 | + */ |
|
| 131 | + protected $requestToURI; |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * The detected uri and server variables ($_FILES). |
|
| 135 | + * |
|
| 136 | + * @var array $server |
|
| 137 | + */ |
|
| 138 | + public $server = []; |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * List of routes uri. |
|
| 142 | + * |
|
| 143 | + * @var string|array $uri |
|
| 144 | + */ |
|
| 145 | + public $uri; |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Stores the valid locale codes. |
|
| 149 | + * |
|
| 150 | + * @var array $validLocales |
|
| 151 | + */ |
|
| 152 | + protected $validLocales = []; |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Constructor: Create new the Request class. |
|
| 156 | + * |
|
| 157 | + * @param array $request |
|
| 158 | + * @param array $cookies |
|
| 159 | + * @param array $files |
|
| 160 | + * @param array $server |
|
| 161 | + * @param string|resource|null $content (null by default) |
|
| 162 | + * |
|
| 163 | + * @return void |
|
| 164 | + */ |
|
| 165 | + public function __construct(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null) |
|
| 166 | + { |
|
| 167 | + static::$requestURI = $this; |
|
| 168 | 168 | |
| 169 | - $this->initialize($request, $cookies, $files, $server, $content); |
|
| 170 | - |
|
| 171 | - $this->detectURI(config('app.uriProtocol'), config('app.baseUrl')); |
|
| 172 | - |
|
| 173 | - $this->detectLocale(); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Sets the parameters for this request. |
|
| 178 | - * |
|
| 179 | - * @param array $request |
|
| 180 | - * @param array $cookies |
|
| 181 | - * @param array $files |
|
| 182 | - * @param array $server |
|
| 183 | - * |
|
| 184 | - * @return void |
|
| 185 | - */ |
|
| 186 | - public function initialize(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null) |
|
| 187 | - { |
|
| 188 | - $this->request = new Parameters($request); |
|
| 189 | - $this->cookies = new Inputs($cookies); |
|
| 190 | - $this->files = new Files($files); |
|
| 191 | - $this->server = new Server($server); |
|
| 192 | - $this->headers = new Headers($this->server->all()); |
|
| 193 | - |
|
| 194 | - $this->uri = new URI; |
|
| 195 | - $this->http = new Http; |
|
| 196 | - $this->method = null; |
|
| 197 | - $this->baseUrl = null; |
|
| 198 | - $this->content = $content; |
|
| 199 | - $this->pathInfo = null; |
|
| 200 | - $this->languages = null; |
|
| 201 | - $this->validLocales = config('app.supportedLocales'); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Create a new Syscodes HTTP request from server variables. |
|
| 206 | - * |
|
| 207 | - * @return static |
|
| 208 | - */ |
|
| 209 | - public static function capture() |
|
| 210 | - { |
|
| 211 | - return static::createFromRequest(static::createFromRequestGlobals()); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Creates an Syscodes request from of the Request class instance. |
|
| 216 | - * |
|
| 217 | - * @param \Syscodes\Http\Request $request |
|
| 218 | - * |
|
| 219 | - * @return static |
|
| 220 | - */ |
|
| 221 | - public static function createFromRequest($request) |
|
| 222 | - { |
|
| 223 | - $newRequest = (new static)->duplicate( |
|
| 224 | - $request->request->all(), $request->cookies->all(), |
|
| 225 | - $request->files->all(), $request->server->all() |
|
| 226 | - ); |
|
| 227 | - |
|
| 228 | - $newRequest->content = $request->content; |
|
| 229 | - |
|
| 230 | - return $newRequest; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Creates a new request with value from PHP's super global. |
|
| 235 | - * |
|
| 236 | - * @return static |
|
| 237 | - */ |
|
| 238 | - public static function createFromRequestGlobals() |
|
| 239 | - { |
|
| 240 | - $request = static::createFromRequestFactory($_POST, $_COOKIE, $_FILES, $_SERVER); |
|
| 241 | - |
|
| 242 | - return $request; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Creates a new request from a factory. |
|
| 247 | - * |
|
| 248 | - * @param array $request |
|
| 249 | - * @param array $cookies |
|
| 250 | - * @param array $files |
|
| 251 | - * @param array $server |
|
| 252 | - * |
|
| 253 | - * @return static |
|
| 254 | - */ |
|
| 255 | - protected static function createFromRequestFactory(array $request = [], array $cookies = [], array $files = [], array $server = []) |
|
| 256 | - { |
|
| 257 | - if (self::$requestURI) { |
|
| 258 | - $request = (self::$requestURI)($request, $cookies, $files, $server); |
|
| 259 | - |
|
| 260 | - if ( ! $request instanceof self) { |
|
| 261 | - throw new LogicException('The Request active must return an instance of Syscodes\Http\Request'); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - return $request; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return new static($request, $cookies, $files, $server); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Clones a request and overrides some of its parameters. |
|
| 272 | - * |
|
| 273 | - * @param array $request |
|
| 274 | - * @param array $cookies |
|
| 275 | - * @param array $files |
|
| 276 | - * @param array $server |
|
| 277 | - * |
|
| 278 | - * @return static |
|
| 279 | - */ |
|
| 280 | - public function duplicate(array $request = [], array $cookies = [], array $files = [], array $server = []) |
|
| 281 | - { |
|
| 282 | - $duplicate = clone $this; |
|
| 283 | - |
|
| 284 | - if (null !== $request) { |
|
| 285 | - $duplicate->request = new Parameters($request); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if (null !== $cookies) { |
|
| 289 | - $duplicate->cookies = new Inputs($cookies); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if (null !== $files) { |
|
| 293 | - $duplicate->files = new Files($files); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - if (null !== $server) { |
|
| 297 | - $duplicate->server = new Server($server); |
|
| 298 | - $duplicate->headers = new Headers($duplicate->server->all()); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - $duplicate->uri = new URI; |
|
| 302 | - $duplicate->http = new Http; |
|
| 303 | - $duplicate->locale = null; |
|
| 304 | - $duplicate->method = null; |
|
| 305 | - $duplicate->baseUrl = null; |
|
| 306 | - $duplicate->pathInfo = null; |
|
| 307 | - $duplicate->validLocales = config('app.supportedLocales'); |
|
| 308 | - |
|
| 309 | - return $duplicate; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Returns the active request currently being used. |
|
| 314 | - * |
|
| 315 | - * @param \Syscodes\Http\Request|bool|null $request Overwrite current request |
|
| 316 | - * before returning, false prevents |
|
| 317 | - * overwrite |
|
| 318 | - * |
|
| 319 | - * @return \Syscodes\Http\Request |
|
| 320 | - */ |
|
| 321 | - public static function active($request = false) |
|
| 322 | - { |
|
| 323 | - if ($request !== false) { |
|
| 324 | - static::$requestURI = $request; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - return static::$requestURI; |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Returns the desired segment, or $default if it does not exist. |
|
| 332 | - * |
|
| 333 | - * @param int $index The segment number (1-based index) |
|
| 334 | - * @param mixed $default Default value to return |
|
| 335 | - * |
|
| 336 | - * @return string |
|
| 337 | - */ |
|
| 338 | - public function segment($index, $default = null) |
|
| 339 | - { |
|
| 340 | - if ($request = static::active()) { |
|
| 341 | - return $request->uri->getSegment($index, $default); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - return null; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * Returns all segments in an array. For total of segments |
|
| 349 | - * used the function PHP count(). |
|
| 350 | - * |
|
| 351 | - * @return array |
|
| 352 | - */ |
|
| 353 | - public function segments() |
|
| 354 | - { |
|
| 355 | - if ($request = static::active()) { |
|
| 356 | - return $request->uri->getSegments(); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - return null; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Returns the total number of segment. |
|
| 364 | - * |
|
| 365 | - * @return int|null |
|
| 366 | - */ |
|
| 367 | - public function totalSegments() |
|
| 368 | - { |
|
| 369 | - if ($request = static::active()) { |
|
| 370 | - return $request->uri->getTotalSegments(); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - return null; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Detects and returns the current URI based on a number of different server variables. |
|
| 378 | - * |
|
| 379 | - * @param string $protocol |
|
| 380 | - * @param string $baseUrl |
|
| 381 | - * |
|
| 382 | - * @return string |
|
| 383 | - */ |
|
| 384 | - protected function detectURI(string $protocol, string $baseUrl) |
|
| 385 | - { |
|
| 386 | - $this->uri->setPath($this->http->detectPath($protocol)); |
|
| 387 | - |
|
| 388 | - $baseUrl = ! empty($baseUrl) ? rtrim($baseUrl, '/ ').'/' : $baseUrl; |
|
| 389 | - |
|
| 390 | - if ( ! empty($baseUrl)) { |
|
| 391 | - $this->uri->setScheme(parse_url($baseUrl, PHP_URL_SCHEME)); |
|
| 392 | - $this->uri->setHost(parse_url($baseUrl, PHP_URL_HOST)); |
|
| 393 | - $this->uri->setPort(parse_url($baseUrl, PHP_URL_PORT)); |
|
| 394 | - } else { |
|
| 395 | - if ( ! $this->http->isCli()) { |
|
| 396 | - exit('You have an empty or invalid base URL. The baseURL value must be set in config/app.php, or through the .env file.'); |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Handles setting up the locale, auto-detecting of language. |
|
| 403 | - * |
|
| 404 | - * @return void |
|
| 405 | - */ |
|
| 406 | - public function detectLocale() |
|
| 407 | - { |
|
| 408 | - $this->languages = $this->defaultLocale = config('app.locale'); |
|
| 409 | - |
|
| 410 | - $this->setLocale($this->validLocales); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Returns the default locale as set. |
|
| 415 | - * |
|
| 416 | - * @return string |
|
| 417 | - */ |
|
| 418 | - public function getDefaultLocale() |
|
| 419 | - { |
|
| 420 | - return $this->defaultLocale; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Gets the current locale, with a fallback to the default. |
|
| 425 | - * |
|
| 426 | - * @return string |
|
| 427 | - */ |
|
| 428 | - public function getLocale() |
|
| 429 | - { |
|
| 430 | - return $this->languages ?: $this->defaultLocale; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Sets the locale string for this request. |
|
| 435 | - * |
|
| 436 | - * @param string $locale |
|
| 437 | - * |
|
| 438 | - * @return \Syscodes\Http\Request |
|
| 439 | - */ |
|
| 440 | - public function setLocale($locale) |
|
| 441 | - { |
|
| 442 | - if ( ! in_array($locale, $this->validLocales)) { |
|
| 443 | - $locale = $this->defaultLocale; |
|
| 444 | - } |
|
| 169 | + $this->initialize($request, $cookies, $files, $server, $content); |
|
| 170 | + |
|
| 171 | + $this->detectURI(config('app.uriProtocol'), config('app.baseUrl')); |
|
| 172 | + |
|
| 173 | + $this->detectLocale(); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Sets the parameters for this request. |
|
| 178 | + * |
|
| 179 | + * @param array $request |
|
| 180 | + * @param array $cookies |
|
| 181 | + * @param array $files |
|
| 182 | + * @param array $server |
|
| 183 | + * |
|
| 184 | + * @return void |
|
| 185 | + */ |
|
| 186 | + public function initialize(array $request = [], array $cookies = [], array $files = [], array $server = [], $content = null) |
|
| 187 | + { |
|
| 188 | + $this->request = new Parameters($request); |
|
| 189 | + $this->cookies = new Inputs($cookies); |
|
| 190 | + $this->files = new Files($files); |
|
| 191 | + $this->server = new Server($server); |
|
| 192 | + $this->headers = new Headers($this->server->all()); |
|
| 193 | + |
|
| 194 | + $this->uri = new URI; |
|
| 195 | + $this->http = new Http; |
|
| 196 | + $this->method = null; |
|
| 197 | + $this->baseUrl = null; |
|
| 198 | + $this->content = $content; |
|
| 199 | + $this->pathInfo = null; |
|
| 200 | + $this->languages = null; |
|
| 201 | + $this->validLocales = config('app.supportedLocales'); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Create a new Syscodes HTTP request from server variables. |
|
| 206 | + * |
|
| 207 | + * @return static |
|
| 208 | + */ |
|
| 209 | + public static function capture() |
|
| 210 | + { |
|
| 211 | + return static::createFromRequest(static::createFromRequestGlobals()); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Creates an Syscodes request from of the Request class instance. |
|
| 216 | + * |
|
| 217 | + * @param \Syscodes\Http\Request $request |
|
| 218 | + * |
|
| 219 | + * @return static |
|
| 220 | + */ |
|
| 221 | + public static function createFromRequest($request) |
|
| 222 | + { |
|
| 223 | + $newRequest = (new static)->duplicate( |
|
| 224 | + $request->request->all(), $request->cookies->all(), |
|
| 225 | + $request->files->all(), $request->server->all() |
|
| 226 | + ); |
|
| 227 | + |
|
| 228 | + $newRequest->content = $request->content; |
|
| 229 | + |
|
| 230 | + return $newRequest; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Creates a new request with value from PHP's super global. |
|
| 235 | + * |
|
| 236 | + * @return static |
|
| 237 | + */ |
|
| 238 | + public static function createFromRequestGlobals() |
|
| 239 | + { |
|
| 240 | + $request = static::createFromRequestFactory($_POST, $_COOKIE, $_FILES, $_SERVER); |
|
| 241 | + |
|
| 242 | + return $request; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Creates a new request from a factory. |
|
| 247 | + * |
|
| 248 | + * @param array $request |
|
| 249 | + * @param array $cookies |
|
| 250 | + * @param array $files |
|
| 251 | + * @param array $server |
|
| 252 | + * |
|
| 253 | + * @return static |
|
| 254 | + */ |
|
| 255 | + protected static function createFromRequestFactory(array $request = [], array $cookies = [], array $files = [], array $server = []) |
|
| 256 | + { |
|
| 257 | + if (self::$requestURI) { |
|
| 258 | + $request = (self::$requestURI)($request, $cookies, $files, $server); |
|
| 259 | + |
|
| 260 | + if ( ! $request instanceof self) { |
|
| 261 | + throw new LogicException('The Request active must return an instance of Syscodes\Http\Request'); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + return $request; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return new static($request, $cookies, $files, $server); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Clones a request and overrides some of its parameters. |
|
| 272 | + * |
|
| 273 | + * @param array $request |
|
| 274 | + * @param array $cookies |
|
| 275 | + * @param array $files |
|
| 276 | + * @param array $server |
|
| 277 | + * |
|
| 278 | + * @return static |
|
| 279 | + */ |
|
| 280 | + public function duplicate(array $request = [], array $cookies = [], array $files = [], array $server = []) |
|
| 281 | + { |
|
| 282 | + $duplicate = clone $this; |
|
| 283 | + |
|
| 284 | + if (null !== $request) { |
|
| 285 | + $duplicate->request = new Parameters($request); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if (null !== $cookies) { |
|
| 289 | + $duplicate->cookies = new Inputs($cookies); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if (null !== $files) { |
|
| 293 | + $duplicate->files = new Files($files); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + if (null !== $server) { |
|
| 297 | + $duplicate->server = new Server($server); |
|
| 298 | + $duplicate->headers = new Headers($duplicate->server->all()); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + $duplicate->uri = new URI; |
|
| 302 | + $duplicate->http = new Http; |
|
| 303 | + $duplicate->locale = null; |
|
| 304 | + $duplicate->method = null; |
|
| 305 | + $duplicate->baseUrl = null; |
|
| 306 | + $duplicate->pathInfo = null; |
|
| 307 | + $duplicate->validLocales = config('app.supportedLocales'); |
|
| 308 | + |
|
| 309 | + return $duplicate; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Returns the active request currently being used. |
|
| 314 | + * |
|
| 315 | + * @param \Syscodes\Http\Request|bool|null $request Overwrite current request |
|
| 316 | + * before returning, false prevents |
|
| 317 | + * overwrite |
|
| 318 | + * |
|
| 319 | + * @return \Syscodes\Http\Request |
|
| 320 | + */ |
|
| 321 | + public static function active($request = false) |
|
| 322 | + { |
|
| 323 | + if ($request !== false) { |
|
| 324 | + static::$requestURI = $request; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + return static::$requestURI; |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Returns the desired segment, or $default if it does not exist. |
|
| 332 | + * |
|
| 333 | + * @param int $index The segment number (1-based index) |
|
| 334 | + * @param mixed $default Default value to return |
|
| 335 | + * |
|
| 336 | + * @return string |
|
| 337 | + */ |
|
| 338 | + public function segment($index, $default = null) |
|
| 339 | + { |
|
| 340 | + if ($request = static::active()) { |
|
| 341 | + return $request->uri->getSegment($index, $default); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + return null; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * Returns all segments in an array. For total of segments |
|
| 349 | + * used the function PHP count(). |
|
| 350 | + * |
|
| 351 | + * @return array |
|
| 352 | + */ |
|
| 353 | + public function segments() |
|
| 354 | + { |
|
| 355 | + if ($request = static::active()) { |
|
| 356 | + return $request->uri->getSegments(); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + return null; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Returns the total number of segment. |
|
| 364 | + * |
|
| 365 | + * @return int|null |
|
| 366 | + */ |
|
| 367 | + public function totalSegments() |
|
| 368 | + { |
|
| 369 | + if ($request = static::active()) { |
|
| 370 | + return $request->uri->getTotalSegments(); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + return null; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Detects and returns the current URI based on a number of different server variables. |
|
| 378 | + * |
|
| 379 | + * @param string $protocol |
|
| 380 | + * @param string $baseUrl |
|
| 381 | + * |
|
| 382 | + * @return string |
|
| 383 | + */ |
|
| 384 | + protected function detectURI(string $protocol, string $baseUrl) |
|
| 385 | + { |
|
| 386 | + $this->uri->setPath($this->http->detectPath($protocol)); |
|
| 387 | + |
|
| 388 | + $baseUrl = ! empty($baseUrl) ? rtrim($baseUrl, '/ ').'/' : $baseUrl; |
|
| 389 | + |
|
| 390 | + if ( ! empty($baseUrl)) { |
|
| 391 | + $this->uri->setScheme(parse_url($baseUrl, PHP_URL_SCHEME)); |
|
| 392 | + $this->uri->setHost(parse_url($baseUrl, PHP_URL_HOST)); |
|
| 393 | + $this->uri->setPort(parse_url($baseUrl, PHP_URL_PORT)); |
|
| 394 | + } else { |
|
| 395 | + if ( ! $this->http->isCli()) { |
|
| 396 | + exit('You have an empty or invalid base URL. The baseURL value must be set in config/app.php, or through the .env file.'); |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Handles setting up the locale, auto-detecting of language. |
|
| 403 | + * |
|
| 404 | + * @return void |
|
| 405 | + */ |
|
| 406 | + public function detectLocale() |
|
| 407 | + { |
|
| 408 | + $this->languages = $this->defaultLocale = config('app.locale'); |
|
| 409 | + |
|
| 410 | + $this->setLocale($this->validLocales); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Returns the default locale as set. |
|
| 415 | + * |
|
| 416 | + * @return string |
|
| 417 | + */ |
|
| 418 | + public function getDefaultLocale() |
|
| 419 | + { |
|
| 420 | + return $this->defaultLocale; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Gets the current locale, with a fallback to the default. |
|
| 425 | + * |
|
| 426 | + * @return string |
|
| 427 | + */ |
|
| 428 | + public function getLocale() |
|
| 429 | + { |
|
| 430 | + return $this->languages ?: $this->defaultLocale; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Sets the locale string for this request. |
|
| 435 | + * |
|
| 436 | + * @param string $locale |
|
| 437 | + * |
|
| 438 | + * @return \Syscodes\Http\Request |
|
| 439 | + */ |
|
| 440 | + public function setLocale($locale) |
|
| 441 | + { |
|
| 442 | + if ( ! in_array($locale, $this->validLocales)) { |
|
| 443 | + $locale = $this->defaultLocale; |
|
| 444 | + } |
|
| 445 | 445 | |
| 446 | - $this->languages = $locale; |
|
| 447 | - |
|
| 448 | - try { |
|
| 449 | - if (class_exists('Locale', false)) { |
|
| 450 | - Locale::setDefault($locale); |
|
| 451 | - } |
|
| 452 | - } catch (Exception $exception) {} |
|
| 453 | - |
|
| 454 | - return $this; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Returns the full request string. |
|
| 459 | - * |
|
| 460 | - * @return string|null The Request string |
|
| 461 | - */ |
|
| 462 | - public function get() |
|
| 463 | - { |
|
| 464 | - if ($request = static::active()) { |
|
| 465 | - return $request->uri->get(); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - return null; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * Get the JSON payload for the request. |
|
| 473 | - * |
|
| 474 | - * @param string|null $key (null by default) |
|
| 475 | - * @param mixed $default (null by default) |
|
| 476 | - * |
|
| 477 | - * @return \Syscodes\Http\Contributors\Parameters|mixed |
|
| 478 | - */ |
|
| 479 | - public function json($key = null, $default = null) |
|
| 480 | - { |
|
| 481 | - if ( ! isset($this->json)) { |
|
| 482 | - $this->json = new Parameters((array) json_decode($this->getContent(), true)); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - if (is_null($key)) { |
|
| 486 | - return $this->json; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - return Arr::get($this->json->all(), $key, $default); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * Set the JSON payload for the request |
|
| 494 | - * |
|
| 495 | - * @param \Syscodes\Http\Contributors\Parameters $json |
|
| 496 | - * |
|
| 497 | - * @return $this |
|
| 498 | - */ |
|
| 499 | - public function setJson($json) |
|
| 500 | - { |
|
| 501 | - $this->json = $json; |
|
| 502 | - |
|
| 503 | - return $this; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Returns whether this is an AJAX request or not. |
|
| 508 | - * |
|
| 509 | - * @return bool |
|
| 510 | - */ |
|
| 511 | - public function isXmlHttpRequest() |
|
| 512 | - { |
|
| 513 | - return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && |
|
| 514 | - strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest'; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * Returns the input method used (GET, POST, DELETE, etc.). |
|
| 519 | - * |
|
| 520 | - * @return string |
|
| 521 | - * |
|
| 522 | - * @throws \LogicException |
|
| 523 | - */ |
|
| 524 | - public function getmethod() |
|
| 525 | - { |
|
| 526 | - if (null !== $this->method) { |
|
| 527 | - return $this->method; |
|
| 528 | - } |
|
| 446 | + $this->languages = $locale; |
|
| 447 | + |
|
| 448 | + try { |
|
| 449 | + if (class_exists('Locale', false)) { |
|
| 450 | + Locale::setDefault($locale); |
|
| 451 | + } |
|
| 452 | + } catch (Exception $exception) {} |
|
| 453 | + |
|
| 454 | + return $this; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Returns the full request string. |
|
| 459 | + * |
|
| 460 | + * @return string|null The Request string |
|
| 461 | + */ |
|
| 462 | + public function get() |
|
| 463 | + { |
|
| 464 | + if ($request = static::active()) { |
|
| 465 | + return $request->uri->get(); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + return null; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * Get the JSON payload for the request. |
|
| 473 | + * |
|
| 474 | + * @param string|null $key (null by default) |
|
| 475 | + * @param mixed $default (null by default) |
|
| 476 | + * |
|
| 477 | + * @return \Syscodes\Http\Contributors\Parameters|mixed |
|
| 478 | + */ |
|
| 479 | + public function json($key = null, $default = null) |
|
| 480 | + { |
|
| 481 | + if ( ! isset($this->json)) { |
|
| 482 | + $this->json = new Parameters((array) json_decode($this->getContent(), true)); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + if (is_null($key)) { |
|
| 486 | + return $this->json; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + return Arr::get($this->json->all(), $key, $default); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * Set the JSON payload for the request |
|
| 494 | + * |
|
| 495 | + * @param \Syscodes\Http\Contributors\Parameters $json |
|
| 496 | + * |
|
| 497 | + * @return $this |
|
| 498 | + */ |
|
| 499 | + public function setJson($json) |
|
| 500 | + { |
|
| 501 | + $this->json = $json; |
|
| 502 | + |
|
| 503 | + return $this; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Returns whether this is an AJAX request or not. |
|
| 508 | + * |
|
| 509 | + * @return bool |
|
| 510 | + */ |
|
| 511 | + public function isXmlHttpRequest() |
|
| 512 | + { |
|
| 513 | + return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && |
|
| 514 | + strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest'; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * Returns the input method used (GET, POST, DELETE, etc.). |
|
| 519 | + * |
|
| 520 | + * @return string |
|
| 521 | + * |
|
| 522 | + * @throws \LogicException |
|
| 523 | + */ |
|
| 524 | + public function getmethod() |
|
| 525 | + { |
|
| 526 | + if (null !== $this->method) { |
|
| 527 | + return $this->method; |
|
| 528 | + } |
|
| 529 | 529 | |
| 530 | - $method = strtoupper($this->server->get('REQUEST_METHOD', 'GET')); |
|
| 530 | + $method = strtoupper($this->server->get('REQUEST_METHOD', 'GET')); |
|
| 531 | 531 | |
| 532 | - if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) { |
|
| 533 | - return $this->method = $method; |
|
| 534 | - } |
|
| 532 | + if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) { |
|
| 533 | + return $this->method = $method; |
|
| 534 | + } |
|
| 535 | 535 | |
| 536 | - if ( ! preg_match('~^[A-Z]++$#~D', $method)) { |
|
| 537 | - throw new logicException(sprintf('Invalid method override "%s"', $method)); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - return $this->method = $method; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * Sets the request method. |
|
| 545 | - * |
|
| 546 | - * @param string $method |
|
| 547 | - * |
|
| 548 | - * @return string |
|
| 549 | - */ |
|
| 550 | - public function setMethod(string $method) |
|
| 551 | - { |
|
| 552 | - $this->method = null; |
|
| 553 | - |
|
| 554 | - $this->server->set('REQUEST_METHOD', $method); |
|
| 555 | - } |
|
| 536 | + if ( ! preg_match('~^[A-Z]++$#~D', $method)) { |
|
| 537 | + throw new logicException(sprintf('Invalid method override "%s"', $method)); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + return $this->method = $method; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * Sets the request method. |
|
| 545 | + * |
|
| 546 | + * @param string $method |
|
| 547 | + * |
|
| 548 | + * @return string |
|
| 549 | + */ |
|
| 550 | + public function setMethod(string $method) |
|
| 551 | + { |
|
| 552 | + $this->method = null; |
|
| 553 | + |
|
| 554 | + $this->server->set('REQUEST_METHOD', $method); |
|
| 555 | + } |
|
| 556 | 556 | |
| 557 | - /** |
|
| 558 | - * Determine if the current request URI matches a pattern. |
|
| 559 | - * |
|
| 560 | - * @param mixed ...$patterns |
|
| 561 | - * |
|
| 562 | - * @return bool |
|
| 563 | - */ |
|
| 564 | - public function is(...$patterns) |
|
| 565 | - { |
|
| 566 | - $path = $this->decodedPath(); |
|
| 557 | + /** |
|
| 558 | + * Determine if the current request URI matches a pattern. |
|
| 559 | + * |
|
| 560 | + * @param mixed ...$patterns |
|
| 561 | + * |
|
| 562 | + * @return bool |
|
| 563 | + */ |
|
| 564 | + public function is(...$patterns) |
|
| 565 | + { |
|
| 566 | + $path = $this->decodedPath(); |
|
| 567 | 567 | |
| 568 | - foreach ($patterns as $pattern) { |
|
| 569 | - if (Str::is($pattern, $path)) { |
|
| 570 | - return true; |
|
| 571 | - } |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - return false; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Determine if the route name matches a given pattern. |
|
| 579 | - * |
|
| 580 | - * @param mixed ...$patterns |
|
| 581 | - * |
|
| 582 | - * @return bool |
|
| 583 | - */ |
|
| 584 | - public function routeIs(...$patterns) |
|
| 585 | - { |
|
| 586 | - return $this->route() && $this->route()->is(...$patterns); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * Get the route handling the request. |
|
| 591 | - * |
|
| 592 | - * @param string|null $param (null by default) |
|
| 593 | - * @param mixed $default (null by default) |
|
| 594 | - * |
|
| 595 | - * @return \Syscodes\Routing\Route|object|string|null |
|
| 596 | - */ |
|
| 597 | - public function route($param = null, $default = null) |
|
| 598 | - { |
|
| 599 | - $route = $this->getRoute(); |
|
| 600 | - |
|
| 601 | - if (is_null($route) || is_null($param)) { |
|
| 602 | - return $route; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - return $route->parameter($param, $default); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Get the current decoded path info for the request. |
|
| 610 | - * |
|
| 611 | - * @return string |
|
| 612 | - */ |
|
| 613 | - public function decodedPath() |
|
| 614 | - { |
|
| 615 | - return rawurldecode($this->path()); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * Get the current path info for the request. |
|
| 620 | - * |
|
| 621 | - * @return string |
|
| 622 | - */ |
|
| 623 | - public function path() |
|
| 624 | - { |
|
| 625 | - $path = trim($this->getPathInfo(), '/'); |
|
| 626 | - |
|
| 627 | - return $path == '' ? '/' : $path; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * Retunrs the request body content. |
|
| 632 | - * |
|
| 633 | - * @return string |
|
| 634 | - */ |
|
| 635 | - public function getContent() |
|
| 636 | - { |
|
| 637 | - if (null === $this->content || false === $this->content) |
|
| 638 | - { |
|
| 639 | - $this->content = file_get_contents('php://input'); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - return $this->content; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * Returns the path being requested relative to the executed script. |
|
| 647 | - * |
|
| 648 | - * @return string |
|
| 649 | - */ |
|
| 650 | - public function getPathInfo() |
|
| 651 | - { |
|
| 652 | - if (null === $this->pathInfo) |
|
| 653 | - { |
|
| 654 | - $this->pathInfo = $this->http->parsePathInfo(); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - return $this->pathInfo; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Returns the root URL from which this request is executed. |
|
| 662 | - * |
|
| 663 | - * @return string |
|
| 664 | - */ |
|
| 665 | - public function getBaseUrl() |
|
| 666 | - { |
|
| 667 | - if (null === $this->baseUrl) |
|
| 668 | - { |
|
| 669 | - $this->baseUrl = $this->http->parseBaseUrl(); |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - return $this->baseUrl; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * Returns the requested URI. |
|
| 677 | - * |
|
| 678 | - * @return string |
|
| 679 | - */ |
|
| 680 | - public function getRequestUri() |
|
| 681 | - { |
|
| 682 | - if (null === $this->requestToUri) { |
|
| 683 | - $this->requestToUri = $this->http->parseRequestUri(); |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - return $this->requestToUri; |
|
| 687 | - } |
|
| 568 | + foreach ($patterns as $pattern) { |
|
| 569 | + if (Str::is($pattern, $path)) { |
|
| 570 | + return true; |
|
| 571 | + } |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + return false; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Determine if the route name matches a given pattern. |
|
| 579 | + * |
|
| 580 | + * @param mixed ...$patterns |
|
| 581 | + * |
|
| 582 | + * @return bool |
|
| 583 | + */ |
|
| 584 | + public function routeIs(...$patterns) |
|
| 585 | + { |
|
| 586 | + return $this->route() && $this->route()->is(...$patterns); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * Get the route handling the request. |
|
| 591 | + * |
|
| 592 | + * @param string|null $param (null by default) |
|
| 593 | + * @param mixed $default (null by default) |
|
| 594 | + * |
|
| 595 | + * @return \Syscodes\Routing\Route|object|string|null |
|
| 596 | + */ |
|
| 597 | + public function route($param = null, $default = null) |
|
| 598 | + { |
|
| 599 | + $route = $this->getRoute(); |
|
| 600 | + |
|
| 601 | + if (is_null($route) || is_null($param)) { |
|
| 602 | + return $route; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + return $route->parameter($param, $default); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Get the current decoded path info for the request. |
|
| 610 | + * |
|
| 611 | + * @return string |
|
| 612 | + */ |
|
| 613 | + public function decodedPath() |
|
| 614 | + { |
|
| 615 | + return rawurldecode($this->path()); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * Get the current path info for the request. |
|
| 620 | + * |
|
| 621 | + * @return string |
|
| 622 | + */ |
|
| 623 | + public function path() |
|
| 624 | + { |
|
| 625 | + $path = trim($this->getPathInfo(), '/'); |
|
| 626 | + |
|
| 627 | + return $path == '' ? '/' : $path; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * Retunrs the request body content. |
|
| 632 | + * |
|
| 633 | + * @return string |
|
| 634 | + */ |
|
| 635 | + public function getContent() |
|
| 636 | + { |
|
| 637 | + if (null === $this->content || false === $this->content) |
|
| 638 | + { |
|
| 639 | + $this->content = file_get_contents('php://input'); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + return $this->content; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Returns the path being requested relative to the executed script. |
|
| 647 | + * |
|
| 648 | + * @return string |
|
| 649 | + */ |
|
| 650 | + public function getPathInfo() |
|
| 651 | + { |
|
| 652 | + if (null === $this->pathInfo) |
|
| 653 | + { |
|
| 654 | + $this->pathInfo = $this->http->parsePathInfo(); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + return $this->pathInfo; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Returns the root URL from which this request is executed. |
|
| 662 | + * |
|
| 663 | + * @return string |
|
| 664 | + */ |
|
| 665 | + public function getBaseUrl() |
|
| 666 | + { |
|
| 667 | + if (null === $this->baseUrl) |
|
| 668 | + { |
|
| 669 | + $this->baseUrl = $this->http->parseBaseUrl(); |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + return $this->baseUrl; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * Returns the requested URI. |
|
| 677 | + * |
|
| 678 | + * @return string |
|
| 679 | + */ |
|
| 680 | + public function getRequestUri() |
|
| 681 | + { |
|
| 682 | + if (null === $this->requestToUri) { |
|
| 683 | + $this->requestToUri = $this->http->parseRequestUri(); |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + return $this->requestToUri; |
|
| 687 | + } |
|
| 688 | 688 | |
| 689 | - /** |
|
| 690 | - * Gets the request's scheme. |
|
| 691 | - * |
|
| 692 | - * @return string |
|
| 693 | - */ |
|
| 694 | - public function getScheme() |
|
| 695 | - { |
|
| 696 | - return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http'); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * Returns the host name. |
|
| 701 | - * |
|
| 702 | - * @return void |
|
| 703 | - */ |
|
| 704 | - public function getHost() |
|
| 705 | - { |
|
| 706 | - if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) { |
|
| 707 | - $host = $forawardedHost[0]; |
|
| 708 | - } elseif ( ! $host = $this->headers->get('HOST')) { |
|
| 709 | - if ( ! $host = $this->server->get('SERVER_NAME')) { |
|
| 710 | - $host = $this->server->get('REMOTE_ADDR', ''); |
|
| 711 | - } |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - $host = $_SERVER['SERVER_NAME']; |
|
| 715 | - |
|
| 716 | - $host = strtolower(preg_replace('/:\d+$/', '', trim(($host)))); |
|
| 689 | + /** |
|
| 690 | + * Gets the request's scheme. |
|
| 691 | + * |
|
| 692 | + * @return string |
|
| 693 | + */ |
|
| 694 | + public function getScheme() |
|
| 695 | + { |
|
| 696 | + return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http'); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * Returns the host name. |
|
| 701 | + * |
|
| 702 | + * @return void |
|
| 703 | + */ |
|
| 704 | + public function getHost() |
|
| 705 | + { |
|
| 706 | + if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) { |
|
| 707 | + $host = $forawardedHost[0]; |
|
| 708 | + } elseif ( ! $host = $this->headers->get('HOST')) { |
|
| 709 | + if ( ! $host = $this->server->get('SERVER_NAME')) { |
|
| 710 | + $host = $this->server->get('REMOTE_ADDR', ''); |
|
| 711 | + } |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + $host = $_SERVER['SERVER_NAME']; |
|
| 715 | + |
|
| 716 | + $host = strtolower(preg_replace('/:\d+$/', '', trim(($host)))); |
|
| 717 | 717 | |
| 718 | - return $host; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - /** |
|
| 722 | - * Returns the port on which the request is made. |
|
| 723 | - * |
|
| 724 | - * @return int |
|
| 725 | - */ |
|
| 726 | - public function getPort() |
|
| 727 | - { |
|
| 728 | - if ( ! $this->server->get('HTTP_HOST')) |
|
| 729 | - { |
|
| 730 | - return $this->server->get('SERVER_PORT'); |
|
| 731 | - } |
|
| 718 | + return $host; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + /** |
|
| 722 | + * Returns the port on which the request is made. |
|
| 723 | + * |
|
| 724 | + * @return int |
|
| 725 | + */ |
|
| 726 | + public function getPort() |
|
| 727 | + { |
|
| 728 | + if ( ! $this->server->get('HTTP_HOST')) |
|
| 729 | + { |
|
| 730 | + return $this->server->get('SERVER_PORT'); |
|
| 731 | + } |
|
| 732 | 732 | |
| 733 | - return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80); |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - /** |
|
| 737 | - * Returns the HTTP host being requested. |
|
| 738 | - * |
|
| 739 | - * @return string |
|
| 740 | - */ |
|
| 741 | - public function getHttpHost() |
|
| 742 | - { |
|
| 743 | - $scheme = $this->getScheme(); |
|
| 744 | - $port = $this->getPort(); |
|
| 745 | - |
|
| 746 | - if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) |
|
| 747 | - { |
|
| 748 | - return $this->getHost(); |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - return $this->getHost().':'.$port; |
|
| 752 | - } |
|
| 753 | - |
|
| 754 | - /** |
|
| 755 | - * Gets the scheme and HTTP host. |
|
| 756 | - * |
|
| 757 | - * @return string |
|
| 758 | - */ |
|
| 759 | - public function getSchemeWithHttpHost() |
|
| 760 | - { |
|
| 761 | - return $this->getScheme().'://'.$this->getHttpHost(); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - /** |
|
| 765 | - * Get the root URL for the application. |
|
| 766 | - * |
|
| 767 | - * @return string |
|
| 768 | - */ |
|
| 769 | - public function root() |
|
| 770 | - { |
|
| 771 | - return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/'); |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - /** |
|
| 775 | - * Get the URL for the request. |
|
| 776 | - * |
|
| 777 | - * @return string |
|
| 778 | - */ |
|
| 779 | - public function url() |
|
| 780 | - { |
|
| 781 | - return trim(preg_replace('/\?.*/', '', $this->get()), '/'); |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - /** |
|
| 785 | - * Returns the referer. |
|
| 786 | - * |
|
| 787 | - * @param string $default |
|
| 788 | - * |
|
| 789 | - * @return string |
|
| 790 | - */ |
|
| 791 | - public function referer(string $default = '') |
|
| 792 | - { |
|
| 793 | - return $this->server->get('HTTP_REFERER', $default); |
|
| 794 | - } |
|
| 733 | + return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80); |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + /** |
|
| 737 | + * Returns the HTTP host being requested. |
|
| 738 | + * |
|
| 739 | + * @return string |
|
| 740 | + */ |
|
| 741 | + public function getHttpHost() |
|
| 742 | + { |
|
| 743 | + $scheme = $this->getScheme(); |
|
| 744 | + $port = $this->getPort(); |
|
| 745 | + |
|
| 746 | + if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) |
|
| 747 | + { |
|
| 748 | + return $this->getHost(); |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + return $this->getHost().':'.$port; |
|
| 752 | + } |
|
| 753 | + |
|
| 754 | + /** |
|
| 755 | + * Gets the scheme and HTTP host. |
|
| 756 | + * |
|
| 757 | + * @return string |
|
| 758 | + */ |
|
| 759 | + public function getSchemeWithHttpHost() |
|
| 760 | + { |
|
| 761 | + return $this->getScheme().'://'.$this->getHttpHost(); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + /** |
|
| 765 | + * Get the root URL for the application. |
|
| 766 | + * |
|
| 767 | + * @return string |
|
| 768 | + */ |
|
| 769 | + public function root() |
|
| 770 | + { |
|
| 771 | + return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/'); |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + /** |
|
| 775 | + * Get the URL for the request. |
|
| 776 | + * |
|
| 777 | + * @return string |
|
| 778 | + */ |
|
| 779 | + public function url() |
|
| 780 | + { |
|
| 781 | + return trim(preg_replace('/\?.*/', '', $this->get()), '/'); |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + /** |
|
| 785 | + * Returns the referer. |
|
| 786 | + * |
|
| 787 | + * @param string $default |
|
| 788 | + * |
|
| 789 | + * @return string |
|
| 790 | + */ |
|
| 791 | + public function referer(string $default = '') |
|
| 792 | + { |
|
| 793 | + return $this->server->get('HTTP_REFERER', $default); |
|
| 794 | + } |
|
| 795 | 795 | |
| 796 | - /** |
|
| 797 | - * Attempts to detect if the current connection is secure through |
|
| 798 | - * over HTTPS protocol. |
|
| 799 | - * |
|
| 800 | - * @return bool |
|
| 801 | - */ |
|
| 802 | - public function secure() |
|
| 803 | - { |
|
| 804 | - if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') { |
|
| 805 | - return true; |
|
| 806 | - } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') { |
|
| 807 | - return true; |
|
| 808 | - } elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') { |
|
| 809 | - return true; |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - return false; |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * Returns the user agent. |
|
| 817 | - * |
|
| 818 | - * @param string|null $default |
|
| 819 | - * |
|
| 820 | - * @return string |
|
| 821 | - */ |
|
| 822 | - public function userAgent(string $default = null) |
|
| 823 | - { |
|
| 824 | - return $this->server->get('HTTP_USER_AGENT', $default); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * Get the route resolver. |
|
| 829 | - * |
|
| 830 | - * @return \Syscodes\Routing\Router |
|
| 831 | - */ |
|
| 832 | - public function getRoute() |
|
| 833 | - { |
|
| 834 | - return app('router'); |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - /** |
|
| 838 | - * Get an element from the request. |
|
| 839 | - * |
|
| 840 | - * @return string[] |
|
| 841 | - */ |
|
| 842 | - public function __get($key) |
|
| 843 | - { |
|
| 844 | - $all = $this->server->all(); |
|
| 845 | - |
|
| 846 | - if (array_key_exists($key, $all)) { |
|
| 847 | - return $all[$key]; |
|
| 848 | - } else { |
|
| 849 | - return $key; |
|
| 850 | - } |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * Returns the Request as an HTTP string. |
|
| 855 | - * |
|
| 856 | - * @return string |
|
| 857 | - */ |
|
| 858 | - public function __toString() |
|
| 859 | - { |
|
| 860 | - try |
|
| 861 | - { |
|
| 862 | - $content = $this->getContent(); |
|
| 863 | - } |
|
| 864 | - catch (LogicException $e) |
|
| 865 | - { |
|
| 866 | - if (PHP_VERSION_ID > 70400) |
|
| 867 | - { |
|
| 868 | - throw $e; |
|
| 869 | - } |
|
| 870 | - |
|
| 871 | - return trigger_error($e, E_USER_ERROR); |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - $cookieHeader = ''; |
|
| 875 | - $cookies = []; |
|
| 876 | - |
|
| 877 | - foreach ($this->cookies as $key => $value) |
|
| 878 | - { |
|
| 879 | - $cookies[]= "{$key} = {$value}"; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - if ( ! empty($cookies)) |
|
| 883 | - { |
|
| 884 | - $cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n"; |
|
| 885 | - } |
|
| 796 | + /** |
|
| 797 | + * Attempts to detect if the current connection is secure through |
|
| 798 | + * over HTTPS protocol. |
|
| 799 | + * |
|
| 800 | + * @return bool |
|
| 801 | + */ |
|
| 802 | + public function secure() |
|
| 803 | + { |
|
| 804 | + if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') { |
|
| 805 | + return true; |
|
| 806 | + } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') { |
|
| 807 | + return true; |
|
| 808 | + } elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') { |
|
| 809 | + return true; |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + return false; |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * Returns the user agent. |
|
| 817 | + * |
|
| 818 | + * @param string|null $default |
|
| 819 | + * |
|
| 820 | + * @return string |
|
| 821 | + */ |
|
| 822 | + public function userAgent(string $default = null) |
|
| 823 | + { |
|
| 824 | + return $this->server->get('HTTP_USER_AGENT', $default); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * Get the route resolver. |
|
| 829 | + * |
|
| 830 | + * @return \Syscodes\Routing\Router |
|
| 831 | + */ |
|
| 832 | + public function getRoute() |
|
| 833 | + { |
|
| 834 | + return app('router'); |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + /** |
|
| 838 | + * Get an element from the request. |
|
| 839 | + * |
|
| 840 | + * @return string[] |
|
| 841 | + */ |
|
| 842 | + public function __get($key) |
|
| 843 | + { |
|
| 844 | + $all = $this->server->all(); |
|
| 845 | + |
|
| 846 | + if (array_key_exists($key, $all)) { |
|
| 847 | + return $all[$key]; |
|
| 848 | + } else { |
|
| 849 | + return $key; |
|
| 850 | + } |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * Returns the Request as an HTTP string. |
|
| 855 | + * |
|
| 856 | + * @return string |
|
| 857 | + */ |
|
| 858 | + public function __toString() |
|
| 859 | + { |
|
| 860 | + try |
|
| 861 | + { |
|
| 862 | + $content = $this->getContent(); |
|
| 863 | + } |
|
| 864 | + catch (LogicException $e) |
|
| 865 | + { |
|
| 866 | + if (PHP_VERSION_ID > 70400) |
|
| 867 | + { |
|
| 868 | + throw $e; |
|
| 869 | + } |
|
| 870 | + |
|
| 871 | + return trigger_error($e, E_USER_ERROR); |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + $cookieHeader = ''; |
|
| 875 | + $cookies = []; |
|
| 876 | + |
|
| 877 | + foreach ($this->cookies as $key => $value) |
|
| 878 | + { |
|
| 879 | + $cookies[]= "{$key} = {$value}"; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + if ( ! empty($cookies)) |
|
| 883 | + { |
|
| 884 | + $cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n"; |
|
| 885 | + } |
|
| 886 | 886 | |
| 887 | - return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n". |
|
| 888 | - $this->headers. |
|
| 889 | - $cookieHeader."\r\n". |
|
| 890 | - $content; |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - /** |
|
| 894 | - * Clones the current request. |
|
| 895 | - * |
|
| 896 | - * @return void |
|
| 897 | - */ |
|
| 898 | - public function __clone() |
|
| 899 | - { |
|
| 900 | - $this->request = clone $this->request; |
|
| 901 | - $this->cookies = clone $this->cookies; |
|
| 902 | - $this->files = clone $this->files; |
|
| 903 | - $this->server = clone $this->server; |
|
| 904 | - $this->headers = clone $this->headers; |
|
| 905 | - } |
|
| 887 | + return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n". |
|
| 888 | + $this->headers. |
|
| 889 | + $cookieHeader."\r\n". |
|
| 890 | + $content; |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + /** |
|
| 894 | + * Clones the current request. |
|
| 895 | + * |
|
| 896 | + * @return void |
|
| 897 | + */ |
|
| 898 | + public function __clone() |
|
| 899 | + { |
|
| 900 | + $this->request = clone $this->request; |
|
| 901 | + $this->cookies = clone $this->cookies; |
|
| 902 | + $this->files = clone $this->files; |
|
| 903 | + $this->server = clone $this->server; |
|
| 904 | + $this->headers = clone $this->headers; |
|
| 905 | + } |
|
| 906 | 906 | } |
| 907 | 907 | \ No newline at end of file |
@@ -860,8 +860,7 @@ |
||
| 860 | 860 | try |
| 861 | 861 | { |
| 862 | 862 | $content = $this->getContent(); |
| 863 | - } |
|
| 864 | - catch (LogicException $e) |
|
| 863 | + } catch (LogicException $e) |
|
| 865 | 864 | { |
| 866 | 865 | if (PHP_VERSION_ID > 70400) |
| 867 | 866 | { |