@@ -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 |
@@ -258,7 +258,7 @@ |
||
258 | 258 | */ |
259 | 259 | public function getSegments() |
260 | 260 | { |
261 | - return array_values(array_filter($this->segments, function ($value) { |
|
261 | + return array_values(array_filter($this->segments, function($value) { |
|
262 | 262 | return $value != ''; |
263 | 263 | })); |
264 | 264 | } |
@@ -34,497 +34,497 @@ |
||
34 | 34 | */ |
35 | 35 | class URI |
36 | 36 | { |
37 | - /** |
|
38 | - * Returns default schemes/ports. |
|
39 | - * |
|
40 | - * @var array $defaultPorts |
|
41 | - */ |
|
42 | - protected $defaultPorts = [ |
|
43 | - 'http' => 80, |
|
44 | - 'https' => 443, |
|
45 | - 'ftp' => 21, |
|
46 | - 'sftp' => 22 |
|
47 | - ]; |
|
48 | - |
|
49 | - /** |
|
50 | - * The name of any fragment. |
|
51 | - * |
|
52 | - * @var string $fragment |
|
53 | - */ |
|
54 | - protected $fragment = ''; |
|
55 | - |
|
56 | - /** |
|
57 | - * The URI Host. |
|
58 | - * |
|
59 | - * @var string $host |
|
60 | - */ |
|
61 | - protected $host; |
|
37 | + /** |
|
38 | + * Returns default schemes/ports. |
|
39 | + * |
|
40 | + * @var array $defaultPorts |
|
41 | + */ |
|
42 | + protected $defaultPorts = [ |
|
43 | + 'http' => 80, |
|
44 | + 'https' => 443, |
|
45 | + 'ftp' => 21, |
|
46 | + 'sftp' => 22 |
|
47 | + ]; |
|
48 | + |
|
49 | + /** |
|
50 | + * The name of any fragment. |
|
51 | + * |
|
52 | + * @var string $fragment |
|
53 | + */ |
|
54 | + protected $fragment = ''; |
|
55 | + |
|
56 | + /** |
|
57 | + * The URI Host. |
|
58 | + * |
|
59 | + * @var string $host |
|
60 | + */ |
|
61 | + protected $host; |
|
62 | 62 | |
63 | - /** |
|
64 | - * The URI User Password. |
|
65 | - * |
|
66 | - * @var string $password |
|
67 | - */ |
|
68 | - protected $password; |
|
69 | - |
|
70 | - /** |
|
71 | - * The URI path. |
|
72 | - * |
|
73 | - * @var string $path |
|
74 | - */ |
|
75 | - protected $path; |
|
76 | - |
|
77 | - /** |
|
78 | - * The URI Port. |
|
79 | - * |
|
80 | - * @var int $port |
|
81 | - */ |
|
82 | - protected $port; |
|
83 | - |
|
84 | - /** |
|
85 | - * The query string. |
|
86 | - * |
|
87 | - * @var string $query |
|
88 | - */ |
|
89 | - protected $query; |
|
90 | - |
|
91 | - /** |
|
92 | - * The URI Scheme. |
|
93 | - * |
|
94 | - * @var string $scheme |
|
95 | - */ |
|
96 | - protected $scheme = 'http'; |
|
97 | - |
|
98 | - /** |
|
99 | - * The URI segments. |
|
100 | - * |
|
101 | - * @var array $segments |
|
102 | - */ |
|
103 | - protected $segments = []; |
|
104 | - |
|
105 | - /** |
|
106 | - * Whether passwords should be shown in userInfo/authority calls. |
|
107 | - * |
|
108 | - * @var boolean $showPassword |
|
109 | - */ |
|
110 | - protected $showPassword = false; |
|
63 | + /** |
|
64 | + * The URI User Password. |
|
65 | + * |
|
66 | + * @var string $password |
|
67 | + */ |
|
68 | + protected $password; |
|
69 | + |
|
70 | + /** |
|
71 | + * The URI path. |
|
72 | + * |
|
73 | + * @var string $path |
|
74 | + */ |
|
75 | + protected $path; |
|
76 | + |
|
77 | + /** |
|
78 | + * The URI Port. |
|
79 | + * |
|
80 | + * @var int $port |
|
81 | + */ |
|
82 | + protected $port; |
|
83 | + |
|
84 | + /** |
|
85 | + * The query string. |
|
86 | + * |
|
87 | + * @var string $query |
|
88 | + */ |
|
89 | + protected $query; |
|
90 | + |
|
91 | + /** |
|
92 | + * The URI Scheme. |
|
93 | + * |
|
94 | + * @var string $scheme |
|
95 | + */ |
|
96 | + protected $scheme = 'http'; |
|
97 | + |
|
98 | + /** |
|
99 | + * The URI segments. |
|
100 | + * |
|
101 | + * @var array $segments |
|
102 | + */ |
|
103 | + protected $segments = []; |
|
104 | + |
|
105 | + /** |
|
106 | + * Whether passwords should be shown in userInfo/authority calls. |
|
107 | + * |
|
108 | + * @var boolean $showPassword |
|
109 | + */ |
|
110 | + protected $showPassword = false; |
|
111 | 111 | |
112 | - /** |
|
113 | - * The URI User Info. |
|
114 | - * |
|
115 | - * @var string $user |
|
116 | - */ |
|
117 | - protected $user; |
|
118 | - |
|
119 | - /** |
|
120 | - * Constructor. The URI class instance. |
|
121 | - * |
|
122 | - * @param string|null $uri |
|
123 | - * |
|
124 | - * @return void |
|
125 | - * |
|
126 | - * @throws \Syscodes\Http\Exceptions\HttpURIException |
|
127 | - */ |
|
128 | - public function __construct(string $uri = null) |
|
129 | - { |
|
130 | - if ( ! is_null($uri)) { |
|
131 | - $this->setUri($uri); |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Sets and overwrites any current URI information. |
|
137 | - * |
|
138 | - * @param string|null $uri |
|
139 | - * |
|
140 | - * @return mixed |
|
141 | - * |
|
142 | - * @throws \Syscodes\Http\Exceptions\HttpURIException |
|
143 | - */ |
|
144 | - public function setUri(string $uri = null) |
|
145 | - { |
|
146 | - if ( ! is_null($uri)) { |
|
147 | - $parts = parse_url($uri); |
|
148 | - |
|
149 | - if ($parts === false) { |
|
150 | - throw HttpURIException::UnableToParseURI($uri); |
|
151 | - } |
|
152 | - |
|
153 | - $this->applyParts($parts); |
|
154 | - } |
|
155 | - |
|
156 | - return $this; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Returns the full URI string. |
|
161 | - * |
|
162 | - * @return string The URI string |
|
163 | - */ |
|
164 | - public function get() |
|
165 | - { |
|
166 | - return '/'.ltrim($this->path, '/'); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Sets of URI string. |
|
171 | - * |
|
172 | - * @param string $uri |
|
173 | - * |
|
174 | - * @return $this |
|
175 | - */ |
|
176 | - public function set($uri) |
|
177 | - { |
|
178 | - $this->path = $uri; |
|
179 | - |
|
180 | - return $this; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Retrieve the path component of the URI. The path can either be empty or absolute |
|
185 | - * (starting with a slash) or rootless (not starting with a slash). |
|
186 | - * |
|
187 | - * @return string |
|
188 | - */ |
|
189 | - public function getPath() |
|
190 | - { |
|
191 | - return (is_null($this->path) ? '' : $this->path); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Sets the path portion of the URI. |
|
196 | - * |
|
197 | - * @param string $path |
|
198 | - * |
|
199 | - * @return void |
|
200 | - */ |
|
201 | - public function setPath(string $path) |
|
202 | - { |
|
203 | - $this->path = $this->filterPath($path); |
|
204 | - |
|
205 | - $this->filterSegments($this->path); |
|
206 | - |
|
207 | - return $this; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * Encodes any dangerous characters. |
|
212 | - * |
|
213 | - * @param string|null $path |
|
214 | - * |
|
215 | - * @return string |
|
216 | - */ |
|
217 | - protected function filterPath(string $path = null) |
|
218 | - { |
|
219 | - $path = urldecode($path); |
|
220 | - |
|
221 | - return $path; |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Filter the segments of path. |
|
226 | - * |
|
227 | - * @param string $uri |
|
228 | - * |
|
229 | - * @return string[] |
|
230 | - */ |
|
231 | - protected function filterSegments($uri) |
|
232 | - { |
|
233 | - $this->segments = (empty($uri) ? [] : explode('/', $uri)); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Get the specified URI segment, return default if it doesn't exist. |
|
238 | - * Segment index is 1 based, not 0 based. |
|
239 | - * |
|
240 | - * @param int $index The 1-based segment index |
|
241 | - * @param mixed $default The default value |
|
242 | - * |
|
243 | - * @return mixed |
|
244 | - */ |
|
245 | - public function getSegment(int $index, $default = null) |
|
246 | - { |
|
247 | - return Arr::get($this->getSegments(), $index - 1, $default); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Returns the segments of the path as an array. |
|
252 | - * |
|
253 | - * @return array The URI segments |
|
254 | - */ |
|
255 | - public function getSegments() |
|
256 | - { |
|
257 | - return array_values(array_filter($this->segments, function ($value) { |
|
258 | - return $value != ''; |
|
259 | - })); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Returns the total number of segment. |
|
264 | - * |
|
265 | - * @return int |
|
266 | - */ |
|
267 | - public function getTotalSegments() |
|
268 | - { |
|
269 | - return count($this->getSegments()); |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Retrieve the scheme component of the URI. |
|
274 | - * |
|
275 | - * @return string |
|
276 | - */ |
|
277 | - public function getScheme() |
|
278 | - { |
|
279 | - return $this->scheme; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Sets the scheme for this URI. |
|
284 | - * |
|
285 | - * @param string $str |
|
286 | - * |
|
287 | - * @return $this |
|
288 | - */ |
|
289 | - public function setScheme(string $str) |
|
290 | - { |
|
291 | - $str = preg_replace('~:(//)?$~', '', strtolower($str)); |
|
292 | - |
|
293 | - $this->scheme = $str; |
|
294 | - |
|
295 | - return $this->scheme; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Retrieve the user component of the URI. |
|
300 | - * |
|
301 | - * @return string|null |
|
302 | - */ |
|
303 | - public function getUserInfo() |
|
304 | - { |
|
305 | - $user = $this->user; |
|
306 | - |
|
307 | - if ($this->showPassword === true && ! empty($this->password)) { |
|
308 | - $user .= ":$this->password"; |
|
309 | - } |
|
310 | - |
|
311 | - return $user; |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Sets the userInfo/Authority portion of the URI. |
|
316 | - * |
|
317 | - * @param string $user |
|
318 | - * @param string $pass |
|
319 | - * |
|
320 | - * @return $this |
|
321 | - */ |
|
322 | - public function setUserInfo(string $user, string $pass) |
|
323 | - { |
|
324 | - $this->user = trim($user); |
|
325 | - $this->password = trim($pass); |
|
326 | - |
|
327 | - return $this; |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * Temporarily sets the URI to show a password in userInfo. |
|
332 | - * |
|
333 | - * @param boolean $option |
|
334 | - * |
|
335 | - * @return $this |
|
336 | - */ |
|
337 | - public function showPassword(bool $option = true) |
|
338 | - { |
|
339 | - $this->password = $option; |
|
340 | - |
|
341 | - return $this->password; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Retrieve the authority component of the URI. |
|
346 | - * |
|
347 | - * @param boolean $ignore |
|
348 | - * |
|
349 | - * @return string |
|
350 | - */ |
|
351 | - public function getAuthority(bool $ignore = false) |
|
352 | - { |
|
353 | - if (empty($this->host)) { |
|
354 | - return ''; |
|
355 | - } |
|
356 | - |
|
357 | - $authority = $this->host; |
|
358 | - |
|
359 | - if ( ! empty($this->getUserInfo())) { |
|
360 | - $authority = $this->getUserInfo().'@'.$authority; |
|
361 | - } |
|
362 | - |
|
363 | - if ( ! empty($this->port) && ! $ignore) { |
|
364 | - if ($this->port !== $this->defaultPorts[$this->scheme]) { |
|
365 | - $authority .= ":$this->port"; |
|
366 | - } |
|
367 | - } |
|
368 | - |
|
369 | - $this->showPassword = false; |
|
370 | - |
|
371 | - return $authority; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Parses the given string an saves the appropriate authority pieces. |
|
376 | - * |
|
377 | - * @param string $str |
|
378 | - * |
|
379 | - * @return $this |
|
380 | - */ |
|
381 | - public function setAuthority(string $str) |
|
382 | - { |
|
383 | - $parts = parse_url($str); |
|
384 | - |
|
385 | - if (empty($parts['host']) && ! empty($parts['path'])) { |
|
386 | - $parts['host'] = $parts['path']; |
|
387 | - unset($parts['path']); |
|
388 | - } |
|
389 | - |
|
390 | - $this->applyParts($parts); |
|
391 | - |
|
392 | - return $this; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Retrieve the host component of the URI. |
|
397 | - * |
|
398 | - * @return string |
|
399 | - */ |
|
400 | - public function getHost() |
|
401 | - { |
|
402 | - return $this->host; |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Sets the host name to use. |
|
407 | - * |
|
408 | - * @param string $str |
|
409 | - * |
|
410 | - * @return $this |
|
411 | - */ |
|
412 | - public function setHost(string $str) |
|
413 | - { |
|
414 | - $this->host = trim($str); |
|
415 | - |
|
416 | - return $this->host; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Retrieve the port component of the URI. |
|
421 | - * |
|
422 | - * @return int|null |
|
423 | - */ |
|
424 | - public function getPort() |
|
425 | - { |
|
426 | - return $this->port; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * Sets the port portion of the URI. |
|
431 | - * |
|
432 | - * @param int|null $port |
|
433 | - * |
|
434 | - * @return string |
|
435 | - */ |
|
436 | - public function setPort(int $port = null) |
|
437 | - { |
|
438 | - if (is_null($port)) { |
|
439 | - return $this; |
|
440 | - } |
|
441 | - |
|
442 | - if ($port <= 0 || $port > 65355) { |
|
443 | - throw HttpURIException::invalidPort($port); |
|
444 | - } |
|
445 | - |
|
446 | - $this->port = $port; |
|
447 | - |
|
448 | - return $this->port; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Retrieve a URI fragment. |
|
453 | - * |
|
454 | - * @return string |
|
455 | - */ |
|
456 | - public function getFragment() |
|
457 | - { |
|
458 | - return is_null($this->fragment) ? '' : $this->fragment; |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * Sets the fragment portion of the URI. |
|
463 | - * |
|
464 | - * @param string $str |
|
465 | - * |
|
466 | - * @return $this |
|
467 | - */ |
|
468 | - public function setFragment(string $str) |
|
469 | - { |
|
470 | - $this->fragment = trim($str, '# '); |
|
471 | - |
|
472 | - return $this->fragment; |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Saves our parts from a parse_url call. |
|
477 | - * |
|
478 | - * @param array $parts |
|
479 | - * |
|
480 | - * @return mixed |
|
481 | - */ |
|
482 | - public function applyParts(array $paths) |
|
483 | - { |
|
484 | - if (isset($parts['scheme'])) { |
|
485 | - $this->SetScheme(rtrim($parts['scheme'], ':/')); |
|
486 | - } else { |
|
487 | - $this->setScheme('http'); |
|
488 | - } |
|
489 | - |
|
490 | - if ( ! empty($parts['host'])) { |
|
491 | - $this->host = $parts['host']; |
|
492 | - } |
|
493 | - |
|
494 | - if (isset($parts['port'])) { |
|
495 | - if ( ! is_null($parts['port'])) { |
|
496 | - $this->port = $parts['port']; |
|
497 | - } |
|
498 | - } |
|
499 | - |
|
500 | - if ( ! empty($parts['user'])) { |
|
501 | - $this->user = $parts['user']; |
|
502 | - } |
|
503 | - |
|
504 | - if ( ! empty($parts['pass'])) { |
|
505 | - $this->password = $parts['pass']; |
|
506 | - } |
|
507 | - |
|
508 | - if ( ! empty($parts['path'])) { |
|
509 | - $this->path = $this->filterPath($parts['path']); |
|
510 | - } |
|
511 | - |
|
512 | - if ( ! empty($parts['fragment'])) { |
|
513 | - $this->fragment = $parts['fragment']; |
|
514 | - } |
|
515 | - |
|
516 | - if ( ! empty($parts['path'])) { |
|
517 | - $this->segments = explode('/', $parts['path'], '/'); |
|
518 | - } |
|
519 | - } |
|
520 | - |
|
521 | - /** |
|
522 | - * Returns the URI string. |
|
523 | - * |
|
524 | - * @return string |
|
525 | - */ |
|
526 | - public function __toString() |
|
527 | - { |
|
528 | - return (string) $this->getPath(); |
|
529 | - } |
|
112 | + /** |
|
113 | + * The URI User Info. |
|
114 | + * |
|
115 | + * @var string $user |
|
116 | + */ |
|
117 | + protected $user; |
|
118 | + |
|
119 | + /** |
|
120 | + * Constructor. The URI class instance. |
|
121 | + * |
|
122 | + * @param string|null $uri |
|
123 | + * |
|
124 | + * @return void |
|
125 | + * |
|
126 | + * @throws \Syscodes\Http\Exceptions\HttpURIException |
|
127 | + */ |
|
128 | + public function __construct(string $uri = null) |
|
129 | + { |
|
130 | + if ( ! is_null($uri)) { |
|
131 | + $this->setUri($uri); |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Sets and overwrites any current URI information. |
|
137 | + * |
|
138 | + * @param string|null $uri |
|
139 | + * |
|
140 | + * @return mixed |
|
141 | + * |
|
142 | + * @throws \Syscodes\Http\Exceptions\HttpURIException |
|
143 | + */ |
|
144 | + public function setUri(string $uri = null) |
|
145 | + { |
|
146 | + if ( ! is_null($uri)) { |
|
147 | + $parts = parse_url($uri); |
|
148 | + |
|
149 | + if ($parts === false) { |
|
150 | + throw HttpURIException::UnableToParseURI($uri); |
|
151 | + } |
|
152 | + |
|
153 | + $this->applyParts($parts); |
|
154 | + } |
|
155 | + |
|
156 | + return $this; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Returns the full URI string. |
|
161 | + * |
|
162 | + * @return string The URI string |
|
163 | + */ |
|
164 | + public function get() |
|
165 | + { |
|
166 | + return '/'.ltrim($this->path, '/'); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Sets of URI string. |
|
171 | + * |
|
172 | + * @param string $uri |
|
173 | + * |
|
174 | + * @return $this |
|
175 | + */ |
|
176 | + public function set($uri) |
|
177 | + { |
|
178 | + $this->path = $uri; |
|
179 | + |
|
180 | + return $this; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Retrieve the path component of the URI. The path can either be empty or absolute |
|
185 | + * (starting with a slash) or rootless (not starting with a slash). |
|
186 | + * |
|
187 | + * @return string |
|
188 | + */ |
|
189 | + public function getPath() |
|
190 | + { |
|
191 | + return (is_null($this->path) ? '' : $this->path); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Sets the path portion of the URI. |
|
196 | + * |
|
197 | + * @param string $path |
|
198 | + * |
|
199 | + * @return void |
|
200 | + */ |
|
201 | + public function setPath(string $path) |
|
202 | + { |
|
203 | + $this->path = $this->filterPath($path); |
|
204 | + |
|
205 | + $this->filterSegments($this->path); |
|
206 | + |
|
207 | + return $this; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * Encodes any dangerous characters. |
|
212 | + * |
|
213 | + * @param string|null $path |
|
214 | + * |
|
215 | + * @return string |
|
216 | + */ |
|
217 | + protected function filterPath(string $path = null) |
|
218 | + { |
|
219 | + $path = urldecode($path); |
|
220 | + |
|
221 | + return $path; |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Filter the segments of path. |
|
226 | + * |
|
227 | + * @param string $uri |
|
228 | + * |
|
229 | + * @return string[] |
|
230 | + */ |
|
231 | + protected function filterSegments($uri) |
|
232 | + { |
|
233 | + $this->segments = (empty($uri) ? [] : explode('/', $uri)); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Get the specified URI segment, return default if it doesn't exist. |
|
238 | + * Segment index is 1 based, not 0 based. |
|
239 | + * |
|
240 | + * @param int $index The 1-based segment index |
|
241 | + * @param mixed $default The default value |
|
242 | + * |
|
243 | + * @return mixed |
|
244 | + */ |
|
245 | + public function getSegment(int $index, $default = null) |
|
246 | + { |
|
247 | + return Arr::get($this->getSegments(), $index - 1, $default); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Returns the segments of the path as an array. |
|
252 | + * |
|
253 | + * @return array The URI segments |
|
254 | + */ |
|
255 | + public function getSegments() |
|
256 | + { |
|
257 | + return array_values(array_filter($this->segments, function ($value) { |
|
258 | + return $value != ''; |
|
259 | + })); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Returns the total number of segment. |
|
264 | + * |
|
265 | + * @return int |
|
266 | + */ |
|
267 | + public function getTotalSegments() |
|
268 | + { |
|
269 | + return count($this->getSegments()); |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Retrieve the scheme component of the URI. |
|
274 | + * |
|
275 | + * @return string |
|
276 | + */ |
|
277 | + public function getScheme() |
|
278 | + { |
|
279 | + return $this->scheme; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Sets the scheme for this URI. |
|
284 | + * |
|
285 | + * @param string $str |
|
286 | + * |
|
287 | + * @return $this |
|
288 | + */ |
|
289 | + public function setScheme(string $str) |
|
290 | + { |
|
291 | + $str = preg_replace('~:(//)?$~', '', strtolower($str)); |
|
292 | + |
|
293 | + $this->scheme = $str; |
|
294 | + |
|
295 | + return $this->scheme; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Retrieve the user component of the URI. |
|
300 | + * |
|
301 | + * @return string|null |
|
302 | + */ |
|
303 | + public function getUserInfo() |
|
304 | + { |
|
305 | + $user = $this->user; |
|
306 | + |
|
307 | + if ($this->showPassword === true && ! empty($this->password)) { |
|
308 | + $user .= ":$this->password"; |
|
309 | + } |
|
310 | + |
|
311 | + return $user; |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Sets the userInfo/Authority portion of the URI. |
|
316 | + * |
|
317 | + * @param string $user |
|
318 | + * @param string $pass |
|
319 | + * |
|
320 | + * @return $this |
|
321 | + */ |
|
322 | + public function setUserInfo(string $user, string $pass) |
|
323 | + { |
|
324 | + $this->user = trim($user); |
|
325 | + $this->password = trim($pass); |
|
326 | + |
|
327 | + return $this; |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Temporarily sets the URI to show a password in userInfo. |
|
332 | + * |
|
333 | + * @param boolean $option |
|
334 | + * |
|
335 | + * @return $this |
|
336 | + */ |
|
337 | + public function showPassword(bool $option = true) |
|
338 | + { |
|
339 | + $this->password = $option; |
|
340 | + |
|
341 | + return $this->password; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Retrieve the authority component of the URI. |
|
346 | + * |
|
347 | + * @param boolean $ignore |
|
348 | + * |
|
349 | + * @return string |
|
350 | + */ |
|
351 | + public function getAuthority(bool $ignore = false) |
|
352 | + { |
|
353 | + if (empty($this->host)) { |
|
354 | + return ''; |
|
355 | + } |
|
356 | + |
|
357 | + $authority = $this->host; |
|
358 | + |
|
359 | + if ( ! empty($this->getUserInfo())) { |
|
360 | + $authority = $this->getUserInfo().'@'.$authority; |
|
361 | + } |
|
362 | + |
|
363 | + if ( ! empty($this->port) && ! $ignore) { |
|
364 | + if ($this->port !== $this->defaultPorts[$this->scheme]) { |
|
365 | + $authority .= ":$this->port"; |
|
366 | + } |
|
367 | + } |
|
368 | + |
|
369 | + $this->showPassword = false; |
|
370 | + |
|
371 | + return $authority; |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Parses the given string an saves the appropriate authority pieces. |
|
376 | + * |
|
377 | + * @param string $str |
|
378 | + * |
|
379 | + * @return $this |
|
380 | + */ |
|
381 | + public function setAuthority(string $str) |
|
382 | + { |
|
383 | + $parts = parse_url($str); |
|
384 | + |
|
385 | + if (empty($parts['host']) && ! empty($parts['path'])) { |
|
386 | + $parts['host'] = $parts['path']; |
|
387 | + unset($parts['path']); |
|
388 | + } |
|
389 | + |
|
390 | + $this->applyParts($parts); |
|
391 | + |
|
392 | + return $this; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Retrieve the host component of the URI. |
|
397 | + * |
|
398 | + * @return string |
|
399 | + */ |
|
400 | + public function getHost() |
|
401 | + { |
|
402 | + return $this->host; |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Sets the host name to use. |
|
407 | + * |
|
408 | + * @param string $str |
|
409 | + * |
|
410 | + * @return $this |
|
411 | + */ |
|
412 | + public function setHost(string $str) |
|
413 | + { |
|
414 | + $this->host = trim($str); |
|
415 | + |
|
416 | + return $this->host; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Retrieve the port component of the URI. |
|
421 | + * |
|
422 | + * @return int|null |
|
423 | + */ |
|
424 | + public function getPort() |
|
425 | + { |
|
426 | + return $this->port; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * Sets the port portion of the URI. |
|
431 | + * |
|
432 | + * @param int|null $port |
|
433 | + * |
|
434 | + * @return string |
|
435 | + */ |
|
436 | + public function setPort(int $port = null) |
|
437 | + { |
|
438 | + if (is_null($port)) { |
|
439 | + return $this; |
|
440 | + } |
|
441 | + |
|
442 | + if ($port <= 0 || $port > 65355) { |
|
443 | + throw HttpURIException::invalidPort($port); |
|
444 | + } |
|
445 | + |
|
446 | + $this->port = $port; |
|
447 | + |
|
448 | + return $this->port; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Retrieve a URI fragment. |
|
453 | + * |
|
454 | + * @return string |
|
455 | + */ |
|
456 | + public function getFragment() |
|
457 | + { |
|
458 | + return is_null($this->fragment) ? '' : $this->fragment; |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * Sets the fragment portion of the URI. |
|
463 | + * |
|
464 | + * @param string $str |
|
465 | + * |
|
466 | + * @return $this |
|
467 | + */ |
|
468 | + public function setFragment(string $str) |
|
469 | + { |
|
470 | + $this->fragment = trim($str, '# '); |
|
471 | + |
|
472 | + return $this->fragment; |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Saves our parts from a parse_url call. |
|
477 | + * |
|
478 | + * @param array $parts |
|
479 | + * |
|
480 | + * @return mixed |
|
481 | + */ |
|
482 | + public function applyParts(array $paths) |
|
483 | + { |
|
484 | + if (isset($parts['scheme'])) { |
|
485 | + $this->SetScheme(rtrim($parts['scheme'], ':/')); |
|
486 | + } else { |
|
487 | + $this->setScheme('http'); |
|
488 | + } |
|
489 | + |
|
490 | + if ( ! empty($parts['host'])) { |
|
491 | + $this->host = $parts['host']; |
|
492 | + } |
|
493 | + |
|
494 | + if (isset($parts['port'])) { |
|
495 | + if ( ! is_null($parts['port'])) { |
|
496 | + $this->port = $parts['port']; |
|
497 | + } |
|
498 | + } |
|
499 | + |
|
500 | + if ( ! empty($parts['user'])) { |
|
501 | + $this->user = $parts['user']; |
|
502 | + } |
|
503 | + |
|
504 | + if ( ! empty($parts['pass'])) { |
|
505 | + $this->password = $parts['pass']; |
|
506 | + } |
|
507 | + |
|
508 | + if ( ! empty($parts['path'])) { |
|
509 | + $this->path = $this->filterPath($parts['path']); |
|
510 | + } |
|
511 | + |
|
512 | + if ( ! empty($parts['fragment'])) { |
|
513 | + $this->fragment = $parts['fragment']; |
|
514 | + } |
|
515 | + |
|
516 | + if ( ! empty($parts['path'])) { |
|
517 | + $this->segments = explode('/', $parts['path'], '/'); |
|
518 | + } |
|
519 | + } |
|
520 | + |
|
521 | + /** |
|
522 | + * Returns the URI string. |
|
523 | + * |
|
524 | + * @return string |
|
525 | + */ |
|
526 | + public function __toString() |
|
527 | + { |
|
528 | + return (string) $this->getPath(); |
|
529 | + } |
|
530 | 530 | } |
@@ -52,7 +52,7 @@ |
||
52 | 52 | * |
53 | 53 | * @var \Syscodes\Http\Headers $headers |
54 | 54 | */ |
55 | - public $headers; |
|
55 | + public $headers; |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Gets the protocol Http. |
@@ -30,96 +30,96 @@ |
||
30 | 30 | */ |
31 | 31 | class Status |
32 | 32 | { |
33 | - /** |
|
34 | - * The HTTP status code. |
|
35 | - * |
|
36 | - * @var int $status |
|
37 | - */ |
|
38 | - protected $status = 200; |
|
33 | + /** |
|
34 | + * The HTTP status code. |
|
35 | + * |
|
36 | + * @var int $status |
|
37 | + */ |
|
38 | + protected $status = 200; |
|
39 | 39 | |
40 | - /** |
|
41 | - * An array of status codes and messages. |
|
42 | - * |
|
43 | - * @var array $statusCode |
|
44 | - */ |
|
45 | - public $statusCodes = [ |
|
46 | - // 1xx: Informational |
|
47 | - 100 => 'Continue', |
|
48 | - 101 => 'Switching Protocols', |
|
49 | - 102 => 'Processing', |
|
40 | + /** |
|
41 | + * An array of status codes and messages. |
|
42 | + * |
|
43 | + * @var array $statusCode |
|
44 | + */ |
|
45 | + public $statusCodes = [ |
|
46 | + // 1xx: Informational |
|
47 | + 100 => 'Continue', |
|
48 | + 101 => 'Switching Protocols', |
|
49 | + 102 => 'Processing', |
|
50 | 50 | |
51 | - // 2xx: Success |
|
52 | - 200 => 'OK', |
|
53 | - 201 => 'Created', |
|
54 | - 202 => 'Accepted', |
|
55 | - 203 => 'Non-Authoritative Information', |
|
56 | - 204 => 'No Content', |
|
57 | - 205 => 'Reset Content', |
|
58 | - 206 => 'Partial Content', |
|
59 | - 207 => 'Multi-Status', |
|
60 | - 208 => 'Already Reported', |
|
61 | - 226 => 'IM Used', |
|
51 | + // 2xx: Success |
|
52 | + 200 => 'OK', |
|
53 | + 201 => 'Created', |
|
54 | + 202 => 'Accepted', |
|
55 | + 203 => 'Non-Authoritative Information', |
|
56 | + 204 => 'No Content', |
|
57 | + 205 => 'Reset Content', |
|
58 | + 206 => 'Partial Content', |
|
59 | + 207 => 'Multi-Status', |
|
60 | + 208 => 'Already Reported', |
|
61 | + 226 => 'IM Used', |
|
62 | 62 | |
63 | - // 3xx: Redirection |
|
64 | - 300 => 'Multiple Choices', |
|
65 | - 301 => 'Moved Permanently', |
|
66 | - 302 => 'Found', |
|
67 | - 303 => 'See Other', |
|
68 | - 304 => 'Not Modified', |
|
69 | - 305 => 'Use Proxy', |
|
70 | - 307 => 'Temporary Redirect', |
|
71 | - 308 => 'Permanent Redirect', |
|
63 | + // 3xx: Redirection |
|
64 | + 300 => 'Multiple Choices', |
|
65 | + 301 => 'Moved Permanently', |
|
66 | + 302 => 'Found', |
|
67 | + 303 => 'See Other', |
|
68 | + 304 => 'Not Modified', |
|
69 | + 305 => 'Use Proxy', |
|
70 | + 307 => 'Temporary Redirect', |
|
71 | + 308 => 'Permanent Redirect', |
|
72 | 72 | |
73 | - // 4xx: Client error |
|
74 | - 400 => 'Bad Request', |
|
75 | - 401 => 'Unauthorized', |
|
76 | - 402 => 'Payment Required', |
|
77 | - 403 => 'Forbidden', |
|
78 | - 404 => 'Not Found', |
|
79 | - 405 => 'Method Not Allowed', |
|
80 | - 406 => 'Not Acceptable', |
|
81 | - 407 => 'Proxy Authentication Required', |
|
82 | - 408 => 'Request Timeout', |
|
83 | - 409 => 'Conflict', |
|
84 | - 410 => 'Gone', |
|
85 | - 411 => 'Length Required', |
|
86 | - 412 => 'Precondition Failed', |
|
87 | - 413 => 'Request Entity Too Large', |
|
88 | - 414 => 'Request-URI Too Long', |
|
89 | - 415 => 'Unsupported Media Type', |
|
90 | - 416 => 'Requested Range Not Satisfiable', |
|
91 | - 417 => 'Expectation Failed', |
|
92 | - 418 => 'I\'m a Teapot', |
|
93 | - // 419 (Authentication Timeout) is a non-standard status code with unknown origin |
|
94 | - 421 => 'Misdirected Request', |
|
95 | - 422 => 'Unprocessable Entity', |
|
96 | - 423 => 'Locked', |
|
97 | - 424 => 'Failed Dependency', |
|
98 | - 426 => 'Upgrade Required', |
|
99 | - 428 => 'Precondition Required', |
|
100 | - 429 => 'Too Many Requests', |
|
101 | - 431 => 'Request Header Fields Too Large', |
|
102 | - 451 => 'Unavailable For Legal Reasons', |
|
73 | + // 4xx: Client error |
|
74 | + 400 => 'Bad Request', |
|
75 | + 401 => 'Unauthorized', |
|
76 | + 402 => 'Payment Required', |
|
77 | + 403 => 'Forbidden', |
|
78 | + 404 => 'Not Found', |
|
79 | + 405 => 'Method Not Allowed', |
|
80 | + 406 => 'Not Acceptable', |
|
81 | + 407 => 'Proxy Authentication Required', |
|
82 | + 408 => 'Request Timeout', |
|
83 | + 409 => 'Conflict', |
|
84 | + 410 => 'Gone', |
|
85 | + 411 => 'Length Required', |
|
86 | + 412 => 'Precondition Failed', |
|
87 | + 413 => 'Request Entity Too Large', |
|
88 | + 414 => 'Request-URI Too Long', |
|
89 | + 415 => 'Unsupported Media Type', |
|
90 | + 416 => 'Requested Range Not Satisfiable', |
|
91 | + 417 => 'Expectation Failed', |
|
92 | + 418 => 'I\'m a Teapot', |
|
93 | + // 419 (Authentication Timeout) is a non-standard status code with unknown origin |
|
94 | + 421 => 'Misdirected Request', |
|
95 | + 422 => 'Unprocessable Entity', |
|
96 | + 423 => 'Locked', |
|
97 | + 424 => 'Failed Dependency', |
|
98 | + 426 => 'Upgrade Required', |
|
99 | + 428 => 'Precondition Required', |
|
100 | + 429 => 'Too Many Requests', |
|
101 | + 431 => 'Request Header Fields Too Large', |
|
102 | + 451 => 'Unavailable For Legal Reasons', |
|
103 | 103 | |
104 | - // 5xx: Server error |
|
105 | - 500 => 'Internal Server Error', |
|
106 | - 501 => 'Not Implemented', |
|
107 | - 502 => 'Bad Gateway', |
|
108 | - 503 => 'Service Unavailable', |
|
109 | - 504 => 'Gateway Timeout', |
|
110 | - 505 => 'HTTP Version Not Supported', |
|
111 | - 506 => 'Variant Also Negotiates', |
|
112 | - 507 => 'Insufficient Storage', |
|
113 | - 508 => 'Loop Detected', |
|
114 | - 509 => 'Bandwidth Limit Exceeded', |
|
115 | - 510 => 'Not Extended', |
|
116 | - 511 => 'Network Authentication Required' |
|
117 | - ]; |
|
104 | + // 5xx: Server error |
|
105 | + 500 => 'Internal Server Error', |
|
106 | + 501 => 'Not Implemented', |
|
107 | + 502 => 'Bad Gateway', |
|
108 | + 503 => 'Service Unavailable', |
|
109 | + 504 => 'Gateway Timeout', |
|
110 | + 505 => 'HTTP Version Not Supported', |
|
111 | + 506 => 'Variant Also Negotiates', |
|
112 | + 507 => 'Insufficient Storage', |
|
113 | + 508 => 'Loop Detected', |
|
114 | + 509 => 'Bandwidth Limit Exceeded', |
|
115 | + 510 => 'Not Extended', |
|
116 | + 511 => 'Network Authentication Required' |
|
117 | + ]; |
|
118 | 118 | |
119 | - /** |
|
120 | - * Gets string of status code. |
|
121 | - * |
|
122 | - * @var string $statusText |
|
123 | - */ |
|
124 | - protected $statusText; |
|
119 | + /** |
|
120 | + * Gets string of status code. |
|
121 | + * |
|
122 | + * @var string $statusText |
|
123 | + */ |
|
124 | + protected $statusText; |
|
125 | 125 | } |
126 | 126 | \ No newline at end of file |
@@ -140,7 +140,7 @@ |
||
140 | 140 | * |
141 | 141 | * @return mixed |
142 | 142 | */ |
143 | - public function get($key, $default = null, $option = true) |
|
143 | + public function get($key, $default = null, $option = true) |
|
144 | 144 | { |
145 | 145 | $key = str_replace('_', '-', strtolower($key)); |
146 | 146 |
@@ -33,236 +33,236 @@ |
||
33 | 33 | */ |
34 | 34 | class Headers implements IteratorAggregate, Countable |
35 | 35 | { |
36 | - /** |
|
37 | - * An array of HTTP headers. |
|
38 | - * |
|
39 | - * @var array $herders |
|
40 | - */ |
|
41 | - protected $headers = []; |
|
36 | + /** |
|
37 | + * An array of HTTP headers. |
|
38 | + * |
|
39 | + * @var array $herders |
|
40 | + */ |
|
41 | + protected $headers = []; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Specifies the directives for the caching mechanisms in both |
|
45 | - * the requests and the responses. |
|
46 | - * |
|
47 | - * @var array $cacheControl |
|
48 | - */ |
|
49 | - protected $cacheControl = []; |
|
43 | + /** |
|
44 | + * Specifies the directives for the caching mechanisms in both |
|
45 | + * the requests and the responses. |
|
46 | + * |
|
47 | + * @var array $cacheControl |
|
48 | + */ |
|
49 | + protected $cacheControl = []; |
|
50 | 50 | |
51 | - /** |
|
52 | - * Constructor. The Headers class instance. |
|
53 | - * |
|
54 | - * @param array $headers |
|
55 | - * |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function __construct(array $headers = []) |
|
59 | - { |
|
60 | - foreach ($headers as $key => $values) { |
|
61 | - $this->set($key, $values); |
|
62 | - } |
|
63 | - } |
|
51 | + /** |
|
52 | + * Constructor. The Headers class instance. |
|
53 | + * |
|
54 | + * @param array $headers |
|
55 | + * |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function __construct(array $headers = []) |
|
59 | + { |
|
60 | + foreach ($headers as $key => $values) { |
|
61 | + $this->set($key, $values); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Returns all the headers. |
|
67 | - * |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public function all() |
|
71 | - { |
|
72 | - return $this->headers; |
|
73 | - } |
|
65 | + /** |
|
66 | + * Returns all the headers. |
|
67 | + * |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public function all() |
|
71 | + { |
|
72 | + return $this->headers; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Returns the parameter keys. |
|
77 | - * |
|
78 | - * @return array An array of parameter keys |
|
79 | - */ |
|
80 | - public function keys() |
|
81 | - { |
|
82 | - return array_keys($this->all()); |
|
83 | - } |
|
75 | + /** |
|
76 | + * Returns the parameter keys. |
|
77 | + * |
|
78 | + * @return array An array of parameter keys |
|
79 | + */ |
|
80 | + public function keys() |
|
81 | + { |
|
82 | + return array_keys($this->all()); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Replaces the current HTTP headers by a new set. |
|
87 | - * |
|
88 | - * @param array $headers |
|
89 | - * |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - public function replace(array $headers = []) |
|
93 | - { |
|
94 | - $this->headers = []; |
|
95 | - $this->add($headers); |
|
96 | - } |
|
85 | + /** |
|
86 | + * Replaces the current HTTP headers by a new set. |
|
87 | + * |
|
88 | + * @param array $headers |
|
89 | + * |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + public function replace(array $headers = []) |
|
93 | + { |
|
94 | + $this->headers = []; |
|
95 | + $this->add($headers); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Adds multiple header to the queue. |
|
100 | - * |
|
101 | - * @param array $headers The header name |
|
102 | - * |
|
103 | - * @return mixed |
|
104 | - */ |
|
105 | - public function add(array $headers) |
|
106 | - { |
|
107 | - foreach ($headers as $key => $values) { |
|
108 | - $this->set($key, $values); |
|
109 | - } |
|
98 | + /** |
|
99 | + * Adds multiple header to the queue. |
|
100 | + * |
|
101 | + * @param array $headers The header name |
|
102 | + * |
|
103 | + * @return mixed |
|
104 | + */ |
|
105 | + public function add(array $headers) |
|
106 | + { |
|
107 | + foreach ($headers as $key => $values) { |
|
108 | + $this->set($key, $values); |
|
109 | + } |
|
110 | 110 | |
111 | - return $this; |
|
112 | - } |
|
111 | + return $this; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Returns the headers, with original capitalizations. |
|
116 | - * |
|
117 | - * @return array An array of headers |
|
118 | - */ |
|
119 | - public function allPreserveCase() |
|
120 | - { |
|
121 | - $headers = []; |
|
114 | + /** |
|
115 | + * Returns the headers, with original capitalizations. |
|
116 | + * |
|
117 | + * @return array An array of headers |
|
118 | + */ |
|
119 | + public function allPreserveCase() |
|
120 | + { |
|
121 | + $headers = []; |
|
122 | 122 | |
123 | - foreach ($this->all() as $name => $value) { |
|
124 | - $headers[$name] = $value; |
|
125 | - } |
|
123 | + foreach ($this->all() as $name => $value) { |
|
124 | + $headers[$name] = $value; |
|
125 | + } |
|
126 | 126 | |
127 | - return $headers; |
|
128 | - } |
|
127 | + return $headers; |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Gets a header value by name. |
|
132 | - * |
|
133 | - * @param string $key The header name, or null for all headers |
|
134 | - * @param string|null $default The default value |
|
135 | - * @param bool $option Whether to return the option value or all header values |
|
136 | - * |
|
137 | - * @return mixed |
|
138 | - */ |
|
139 | - public function get($key, $default = null, $option = true) |
|
140 | - { |
|
141 | - $key = str_replace('_', '-', strtolower($key)); |
|
130 | + /** |
|
131 | + * Gets a header value by name. |
|
132 | + * |
|
133 | + * @param string $key The header name, or null for all headers |
|
134 | + * @param string|null $default The default value |
|
135 | + * @param bool $option Whether to return the option value or all header values |
|
136 | + * |
|
137 | + * @return mixed |
|
138 | + */ |
|
139 | + public function get($key, $default = null, $option = true) |
|
140 | + { |
|
141 | + $key = str_replace('_', '-', strtolower($key)); |
|
142 | 142 | |
143 | - $headers = $this->all(); |
|
143 | + $headers = $this->all(); |
|
144 | 144 | |
145 | - if ( ! array_key_exists($key, $headers)) { |
|
146 | - if (null === $default) { |
|
147 | - return $option ? null : []; |
|
148 | - } |
|
145 | + if ( ! array_key_exists($key, $headers)) { |
|
146 | + if (null === $default) { |
|
147 | + return $option ? null : []; |
|
148 | + } |
|
149 | 149 | |
150 | - return $option ? $default : [$default]; |
|
151 | - } |
|
150 | + return $option ? $default : [$default]; |
|
151 | + } |
|
152 | 152 | |
153 | - if ($option) { |
|
154 | - return count($headers[$key]) ? $headers[$key][0] : $default; |
|
155 | - } |
|
153 | + if ($option) { |
|
154 | + return count($headers[$key]) ? $headers[$key][0] : $default; |
|
155 | + } |
|
156 | 156 | |
157 | - return $headers[$key]; |
|
158 | - } |
|
157 | + return $headers[$key]; |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * Sets a header by name. |
|
162 | - * |
|
163 | - * @param string $key The header name |
|
164 | - * @param string $values The value or an array of values |
|
165 | - * @param bool $replace If you want to replace the value exists by the header, |
|
166 | - * it is not overwritten / overwritten when it is false |
|
167 | - * |
|
168 | - * @return $this |
|
169 | - */ |
|
170 | - public function set($key, $values, $replace = true) |
|
171 | - { |
|
172 | - $key = str_replace('_', '-', strtolower($key)); |
|
160 | + /** |
|
161 | + * Sets a header by name. |
|
162 | + * |
|
163 | + * @param string $key The header name |
|
164 | + * @param string $values The value or an array of values |
|
165 | + * @param bool $replace If you want to replace the value exists by the header, |
|
166 | + * it is not overwritten / overwritten when it is false |
|
167 | + * |
|
168 | + * @return $this |
|
169 | + */ |
|
170 | + public function set($key, $values, $replace = true) |
|
171 | + { |
|
172 | + $key = str_replace('_', '-', strtolower($key)); |
|
173 | 173 | |
174 | - if (is_array($values)) { |
|
175 | - $values = array_values($values); |
|
174 | + if (is_array($values)) { |
|
175 | + $values = array_values($values); |
|
176 | 176 | |
177 | - if (true === $replace || ! isset($this->headers[$key])) { |
|
178 | - $this->headers[$key] = $values; |
|
179 | - } else { |
|
180 | - $this->headers[$key] = array_merge($this->headers[$key], $values); |
|
181 | - } |
|
182 | - } else { |
|
183 | - if (true === $replace || ! isset($this->headers[$key])) { |
|
184 | - $this->headers[$key] = [$values]; |
|
185 | - } else { |
|
186 | - $this->headers[$key][] = $values; |
|
187 | - } |
|
188 | - } |
|
177 | + if (true === $replace || ! isset($this->headers[$key])) { |
|
178 | + $this->headers[$key] = $values; |
|
179 | + } else { |
|
180 | + $this->headers[$key] = array_merge($this->headers[$key], $values); |
|
181 | + } |
|
182 | + } else { |
|
183 | + if (true === $replace || ! isset($this->headers[$key])) { |
|
184 | + $this->headers[$key] = [$values]; |
|
185 | + } else { |
|
186 | + $this->headers[$key][] = $values; |
|
187 | + } |
|
188 | + } |
|
189 | 189 | |
190 | - return $this; |
|
191 | - } |
|
190 | + return $this; |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * Returns true if the HTTP header is defined. |
|
195 | - * |
|
196 | - * @param string $key The HTTP header |
|
197 | - * |
|
198 | - * @return bool true if the parameter exists, false otherwise |
|
199 | - */ |
|
200 | - public function has($key) |
|
201 | - { |
|
202 | - return array_key_exists(str_replace('_', '-', strtolower($key)), $this->all()); |
|
203 | - } |
|
193 | + /** |
|
194 | + * Returns true if the HTTP header is defined. |
|
195 | + * |
|
196 | + * @param string $key The HTTP header |
|
197 | + * |
|
198 | + * @return bool true if the parameter exists, false otherwise |
|
199 | + */ |
|
200 | + public function has($key) |
|
201 | + { |
|
202 | + return array_key_exists(str_replace('_', '-', strtolower($key)), $this->all()); |
|
203 | + } |
|
204 | 204 | |
205 | - /** |
|
206 | - * Removes a header. |
|
207 | - * |
|
208 | - * @param string $name The header name |
|
209 | - * |
|
210 | - * @return mixed |
|
211 | - */ |
|
212 | - public function remove($key) |
|
213 | - { |
|
214 | - $key = str_replace('_', '-', strtolower($key)); |
|
205 | + /** |
|
206 | + * Removes a header. |
|
207 | + * |
|
208 | + * @param string $name The header name |
|
209 | + * |
|
210 | + * @return mixed |
|
211 | + */ |
|
212 | + public function remove($key) |
|
213 | + { |
|
214 | + $key = str_replace('_', '-', strtolower($key)); |
|
215 | 215 | |
216 | - unset($this->headers[$key]); |
|
216 | + unset($this->headers[$key]); |
|
217 | 217 | |
218 | - if ('cache-control' === $key) { |
|
219 | - $this->cacheControl = []; |
|
220 | - } |
|
221 | - } |
|
218 | + if ('cache-control' === $key) { |
|
219 | + $this->cacheControl = []; |
|
220 | + } |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * Returns an iterator for headers. |
|
225 | - * |
|
226 | - * @return \ArrayIterator An \ArrayIterator instance |
|
227 | - */ |
|
228 | - public function getIterator() |
|
229 | - { |
|
230 | - return new ArrayIterator($this->headers); |
|
231 | - } |
|
223 | + /** |
|
224 | + * Returns an iterator for headers. |
|
225 | + * |
|
226 | + * @return \ArrayIterator An \ArrayIterator instance |
|
227 | + */ |
|
228 | + public function getIterator() |
|
229 | + { |
|
230 | + return new ArrayIterator($this->headers); |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * Returns the number of headers. |
|
235 | - * |
|
236 | - * @return int The number of headers |
|
237 | - */ |
|
238 | - public function count() |
|
239 | - { |
|
240 | - return count($this->headers); |
|
241 | - } |
|
233 | + /** |
|
234 | + * Returns the number of headers. |
|
235 | + * |
|
236 | + * @return int The number of headers |
|
237 | + */ |
|
238 | + public function count() |
|
239 | + { |
|
240 | + return count($this->headers); |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * Returns the headers as a string. |
|
245 | - * |
|
246 | - * @return string The headers |
|
247 | - */ |
|
248 | - public function __toString() |
|
249 | - { |
|
250 | - if ( ! $headers = $this->all()) { |
|
251 | - return ''; |
|
252 | - } |
|
243 | + /** |
|
244 | + * Returns the headers as a string. |
|
245 | + * |
|
246 | + * @return string The headers |
|
247 | + */ |
|
248 | + public function __toString() |
|
249 | + { |
|
250 | + if ( ! $headers = $this->all()) { |
|
251 | + return ''; |
|
252 | + } |
|
253 | 253 | |
254 | - ksort($headers); |
|
255 | - $max = max(array_map('strlen', array_keys($headers))) + 1; |
|
256 | - $content = ''; |
|
254 | + ksort($headers); |
|
255 | + $max = max(array_map('strlen', array_keys($headers))) + 1; |
|
256 | + $content = ''; |
|
257 | 257 | |
258 | - foreach ($headers as $name => $values) { |
|
259 | - $name = ucwords($name, '-'); |
|
258 | + foreach ($headers as $name => $values) { |
|
259 | + $name = ucwords($name, '-'); |
|
260 | 260 | |
261 | - foreach ($values as $value) { |
|
262 | - $content .= sprintf("%-{$max}s %s\r\n", $name.':', $value); |
|
263 | - } |
|
264 | - } |
|
261 | + foreach ($values as $value) { |
|
262 | + $content .= sprintf("%-{$max}s %s\r\n", $name.':', $value); |
|
263 | + } |
|
264 | + } |
|
265 | 265 | |
266 | - return $content; |
|
267 | - } |
|
266 | + return $content; |
|
267 | + } |
|
268 | 268 | } |
269 | 269 | \ No newline at end of file |
@@ -62,11 +62,11 @@ |
||
62 | 62 | */ |
63 | 63 | protected $locale; |
64 | 64 | |
65 | - /** |
|
66 | - * Boolean value whether the intl libraries exist on the system. |
|
67 | - * |
|
68 | - * @var bool $intlSupport |
|
69 | - */ |
|
65 | + /** |
|
66 | + * Boolean value whether the intl libraries exist on the system. |
|
67 | + * |
|
68 | + * @var bool $intlSupport |
|
69 | + */ |
|
70 | 70 | protected $intlSupport = false; |
71 | 71 | |
72 | 72 | /** |