@@ -38,160 +38,160 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | trait HttpRequest |
| 40 | 40 | { |
| 41 | - /** |
|
| 42 | - * Get the http method parameter. |
|
| 43 | - * |
|
| 44 | - * @var bool $httpMethodParameterOverride |
|
| 45 | - */ |
|
| 46 | - protected static $httpMethodParameterOverride = false; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Holds the global active request instance. |
|
| 50 | - * |
|
| 51 | - * @var bool $requestURI |
|
| 52 | - */ |
|
| 53 | - protected static $requestURI; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Get the custom parameters. |
|
| 57 | - * |
|
| 58 | - * @var \Syscodes\Components\Http\Loaders\Parameters $attributes |
|
| 59 | - */ |
|
| 60 | - public $attributes; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * The base URL. |
|
| 64 | - * |
|
| 65 | - * @var string $baseUrl |
|
| 66 | - */ |
|
| 67 | - protected $baseUrl; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Get the client ip. |
|
| 71 | - * |
|
| 72 | - * @var mixed $clientIp |
|
| 73 | - */ |
|
| 74 | - protected $clientIp; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Gets cookies ($_COOKIE). |
|
| 78 | - * |
|
| 79 | - * @var \Syscodes\Components\Http\Loaders\Inputs $cookies |
|
| 80 | - */ |
|
| 81 | - public $cookies; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Gets the string with format JSON. |
|
| 85 | - * |
|
| 86 | - * @var string|resource|object|null $content |
|
| 87 | - */ |
|
| 88 | - protected $content; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * The default Locale this request. |
|
| 92 | - * |
|
| 93 | - * @var string $defaultLocale |
|
| 94 | - */ |
|
| 95 | - protected $defaultLocale = 'en'; |
|
| 41 | + /** |
|
| 42 | + * Get the http method parameter. |
|
| 43 | + * |
|
| 44 | + * @var bool $httpMethodParameterOverride |
|
| 45 | + */ |
|
| 46 | + protected static $httpMethodParameterOverride = false; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Holds the global active request instance. |
|
| 50 | + * |
|
| 51 | + * @var bool $requestURI |
|
| 52 | + */ |
|
| 53 | + protected static $requestURI; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Get the custom parameters. |
|
| 57 | + * |
|
| 58 | + * @var \Syscodes\Components\Http\Loaders\Parameters $attributes |
|
| 59 | + */ |
|
| 60 | + public $attributes; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * The base URL. |
|
| 64 | + * |
|
| 65 | + * @var string $baseUrl |
|
| 66 | + */ |
|
| 67 | + protected $baseUrl; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Get the client ip. |
|
| 71 | + * |
|
| 72 | + * @var mixed $clientIp |
|
| 73 | + */ |
|
| 74 | + protected $clientIp; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Gets cookies ($_COOKIE). |
|
| 78 | + * |
|
| 79 | + * @var \Syscodes\Components\Http\Loaders\Inputs $cookies |
|
| 80 | + */ |
|
| 81 | + public $cookies; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Gets the string with format JSON. |
|
| 85 | + * |
|
| 86 | + * @var string|resource|object|null $content |
|
| 87 | + */ |
|
| 88 | + protected $content; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * The default Locale this request. |
|
| 92 | + * |
|
| 93 | + * @var string $defaultLocale |
|
| 94 | + */ |
|
| 95 | + protected $defaultLocale = 'en'; |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Gets files request ($_FILES). |
|
| 99 | - * |
|
| 100 | - * @var \Syscodes\Components\Http\Loaders\Files $files |
|
| 101 | - */ |
|
| 102 | - public $files; |
|
| 97 | + /** |
|
| 98 | + * Gets files request ($_FILES). |
|
| 99 | + * |
|
| 100 | + * @var \Syscodes\Components\Http\Loaders\Files $files |
|
| 101 | + */ |
|
| 102 | + public $files; |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Get the headers request ($_SERVER). |
|
| 106 | - * |
|
| 107 | - * @var \Syscodes\Components\Http\Loaders\Headers $headers |
|
| 108 | - */ |
|
| 109 | - public $headers; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * The current language of the application. |
|
| 113 | - * |
|
| 114 | - * @var string $languages |
|
| 115 | - */ |
|
| 116 | - protected $languages; |
|
| 104 | + /** |
|
| 105 | + * Get the headers request ($_SERVER). |
|
| 106 | + * |
|
| 107 | + * @var \Syscodes\Components\Http\Loaders\Headers $headers |
|
| 108 | + */ |
|
| 109 | + public $headers; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * The current language of the application. |
|
| 113 | + * |
|
| 114 | + * @var string $languages |
|
| 115 | + */ |
|
| 116 | + protected $languages; |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Get the locale. |
|
| 120 | - * |
|
| 121 | - * @var string $locale |
|
| 122 | - */ |
|
| 123 | - protected $locale; |
|
| 118 | + /** |
|
| 119 | + * Get the locale. |
|
| 120 | + * |
|
| 121 | + * @var string $locale |
|
| 122 | + */ |
|
| 123 | + protected $locale; |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * The method name. |
|
| 127 | - * |
|
| 128 | - * @var string $method |
|
| 129 | - */ |
|
| 130 | - protected $method; |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Query string parameters ($_GET). |
|
| 134 | - * |
|
| 135 | - * @var \Syscodes\Components\Http\Loaders\Parameters $query |
|
| 136 | - */ |
|
| 137 | - public $query; |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Request body parameters ($_POST). |
|
| 141 | - * |
|
| 142 | - * @var \Syscodes\Components\Http\Loaders\Parameters $request |
|
| 143 | - */ |
|
| 144 | - public $request; |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * The detected uri and server variables ($_SERVER). |
|
| 148 | - * |
|
| 149 | - * @var \Syscodes\Components\Http\Loaders\Server $server |
|
| 150 | - */ |
|
| 151 | - public $server; |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * List of routes uri. |
|
| 155 | - * |
|
| 156 | - * @var \Syscodes\Components\Http\URI $uri |
|
| 157 | - */ |
|
| 158 | - public $uri; |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Stores the valid locale codes. |
|
| 162 | - * |
|
| 163 | - * @var array $validLocales |
|
| 164 | - */ |
|
| 165 | - protected $validLocales = []; |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Constructor. Create new the Request class. |
|
| 169 | - * |
|
| 170 | - * @param array $query |
|
| 171 | - * @param array $request |
|
| 172 | - * @param array $attributes |
|
| 173 | - * @param array $cookies |
|
| 174 | - * @param array $files |
|
| 175 | - * @param array $server |
|
| 176 | - * @param string|resource|null $content |
|
| 177 | - * |
|
| 178 | - * @return void |
|
| 179 | - */ |
|
| 180 | - public function __construct( |
|
| 181 | - array $query = [], |
|
| 182 | - array $request = [], |
|
| 183 | - array $attributes = [], |
|
| 184 | - array $cookies = [], |
|
| 185 | - array $files = [], |
|
| 186 | - array $server = [], |
|
| 187 | - $content = null |
|
| 188 | - ) { |
|
| 189 | - $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content); |
|
| 125 | + /** |
|
| 126 | + * The method name. |
|
| 127 | + * |
|
| 128 | + * @var string $method |
|
| 129 | + */ |
|
| 130 | + protected $method; |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Query string parameters ($_GET). |
|
| 134 | + * |
|
| 135 | + * @var \Syscodes\Components\Http\Loaders\Parameters $query |
|
| 136 | + */ |
|
| 137 | + public $query; |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Request body parameters ($_POST). |
|
| 141 | + * |
|
| 142 | + * @var \Syscodes\Components\Http\Loaders\Parameters $request |
|
| 143 | + */ |
|
| 144 | + public $request; |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * The detected uri and server variables ($_SERVER). |
|
| 148 | + * |
|
| 149 | + * @var \Syscodes\Components\Http\Loaders\Server $server |
|
| 150 | + */ |
|
| 151 | + public $server; |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * List of routes uri. |
|
| 155 | + * |
|
| 156 | + * @var \Syscodes\Components\Http\URI $uri |
|
| 157 | + */ |
|
| 158 | + public $uri; |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Stores the valid locale codes. |
|
| 162 | + * |
|
| 163 | + * @var array $validLocales |
|
| 164 | + */ |
|
| 165 | + protected $validLocales = []; |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Constructor. Create new the Request class. |
|
| 169 | + * |
|
| 170 | + * @param array $query |
|
| 171 | + * @param array $request |
|
| 172 | + * @param array $attributes |
|
| 173 | + * @param array $cookies |
|
| 174 | + * @param array $files |
|
| 175 | + * @param array $server |
|
| 176 | + * @param string|resource|null $content |
|
| 177 | + * |
|
| 178 | + * @return void |
|
| 179 | + */ |
|
| 180 | + public function __construct( |
|
| 181 | + array $query = [], |
|
| 182 | + array $request = [], |
|
| 183 | + array $attributes = [], |
|
| 184 | + array $cookies = [], |
|
| 185 | + array $files = [], |
|
| 186 | + array $server = [], |
|
| 187 | + $content = null |
|
| 188 | + ) { |
|
| 189 | + $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content); |
|
| 190 | 190 | |
| 191 | - $this->detectLocale(); |
|
| 192 | - } |
|
| 191 | + $this->detectLocale(); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - /** |
|
| 194 | + /** |
|
| 195 | 195 | * Enables support for the _method request parameter to determine the intended HTTP method. |
| 196 | 196 | * |
| 197 | 197 | * @return void |
@@ -201,361 +201,361 @@ discard block |
||
| 201 | 201 | self::$httpMethodParameterOverride = true; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * Checks whether support for the _method request parameter is enabled. |
|
| 206 | - * |
|
| 207 | - * @return bool |
|
| 208 | - */ |
|
| 209 | - public static function getHttpMethodParameterOverride(): bool |
|
| 210 | - { |
|
| 211 | - return self::$httpMethodParameterOverride; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Creates an Syscodes request from of the Request class instance. |
|
| 216 | - * |
|
| 217 | - * @param \Syscodes\Components\Http\Request $request |
|
| 218 | - * |
|
| 219 | - * @return static |
|
| 220 | - */ |
|
| 221 | - public static function createFromRequest($request): static |
|
| 222 | - { |
|
| 223 | - $newRequest = (new static)->duplicate( |
|
| 224 | - $request->query->all(), $request->request->all(), $request->attributes->all(), |
|
| 225 | - $request->cookies->all(), $request->files->all(), $request->server->all() |
|
| 226 | - ); |
|
| 204 | + /** |
|
| 205 | + * Checks whether support for the _method request parameter is enabled. |
|
| 206 | + * |
|
| 207 | + * @return bool |
|
| 208 | + */ |
|
| 209 | + public static function getHttpMethodParameterOverride(): bool |
|
| 210 | + { |
|
| 211 | + return self::$httpMethodParameterOverride; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Creates an Syscodes request from of the Request class instance. |
|
| 216 | + * |
|
| 217 | + * @param \Syscodes\Components\Http\Request $request |
|
| 218 | + * |
|
| 219 | + * @return static |
|
| 220 | + */ |
|
| 221 | + public static function createFromRequest($request): static |
|
| 222 | + { |
|
| 223 | + $newRequest = (new static)->duplicate( |
|
| 224 | + $request->query->all(), $request->request->all(), $request->attributes->all(), |
|
| 225 | + $request->cookies->all(), $request->files->all(), $request->server->all() |
|
| 226 | + ); |
|
| 227 | 227 | |
| 228 | - $newRequest->headers->replace($request->headers->all()); |
|
| 228 | + $newRequest->headers->replace($request->headers->all()); |
|
| 229 | 229 | |
| 230 | - $newRequest->content = $request->content; |
|
| 230 | + $newRequest->content = $request->content; |
|
| 231 | 231 | |
| 232 | - if ($newRequest->isJson()) { |
|
| 233 | - $newRequest->request = $newRequest->json(); |
|
| 234 | - } |
|
| 232 | + if ($newRequest->isJson()) { |
|
| 233 | + $newRequest->request = $newRequest->json(); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - return $newRequest; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Creates a new request with value from PHP's super global. |
|
| 241 | - * |
|
| 242 | - * @return static |
|
| 243 | - */ |
|
| 244 | - public static function createFromRequestGlobals(): static |
|
| 245 | - { |
|
| 246 | - $request = static::createFromRequestFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER); |
|
| 247 | - |
|
| 248 | - if (Str::startsWith($request->headers->get('CONTENT_TYPE', ''), 'application/x-www-form-urlencoded') |
|
| 249 | - && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])) { |
|
| 250 | - parse_str($request->getContent(), $data); |
|
| 251 | - $request->request = new Inputs($data); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return $request; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Creates a new request from a factory. |
|
| 259 | - * |
|
| 260 | - * @param array $query |
|
| 261 | - * @param array $request |
|
| 262 | - * @param array $attributes |
|
| 263 | - * @param array $cookies |
|
| 264 | - * @param array $files |
|
| 265 | - * @param array $server |
|
| 266 | - * |
|
| 267 | - * @return static |
|
| 268 | - */ |
|
| 269 | - private static function createFromRequestFactory( |
|
| 270 | - array $query = [], |
|
| 271 | - array $request = [], |
|
| 272 | - array $attributes = [] , |
|
| 273 | - array $cookies = [], |
|
| 274 | - array $files = [], |
|
| 275 | - array $server = [] |
|
| 276 | - ): static { |
|
| 277 | - if (self::$requestURI) { |
|
| 278 | - $request = (self::$requestURI)($query, $request, [], $cookies, $files, $server); |
|
| 279 | - |
|
| 280 | - if ( ! $request instanceof self) { |
|
| 281 | - throw new LogicException('The Request active must return an instance of Syscodes\Components\Http\Request'); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $request; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - return new static($query, $request, $attributes, $cookies, $files, $server); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Returns the factory request currently being used. |
|
| 292 | - * |
|
| 293 | - * @param \Syscodes\Components\Http\Request|callable|null $request |
|
| 294 | - * |
|
| 295 | - * @return void |
|
| 296 | - */ |
|
| 297 | - public static function setFactory(?callable $request): void |
|
| 298 | - { |
|
| 299 | - self::$requestURI = $request; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Sets the parameters for this request. |
|
| 304 | - * |
|
| 305 | - * @param array $query |
|
| 306 | - * @param array $request |
|
| 307 | - * @param array $attributes |
|
| 308 | - * @param array $cookies |
|
| 309 | - * @param array $files |
|
| 310 | - * @param array $server |
|
| 311 | - * |
|
| 312 | - * @return void |
|
| 313 | - */ |
|
| 314 | - public function initialize( |
|
| 315 | - array $query = [], |
|
| 316 | - array $request = [], |
|
| 317 | - array $attributes = [], |
|
| 318 | - array $cookies = [], |
|
| 319 | - array $files = [], |
|
| 320 | - array $server = [], |
|
| 321 | - $content = null |
|
| 322 | - ): void { |
|
| 323 | - $this->query = new Inputs($query); |
|
| 324 | - $this->request = new Inputs($request); |
|
| 325 | - $this->attributes = new Parameters($attributes); |
|
| 326 | - $this->cookies = new Inputs($cookies); |
|
| 327 | - $this->files = new Files($files); |
|
| 328 | - $this->server = new Server($server); |
|
| 329 | - $this->headers = new Headers($this->server->all()); |
|
| 330 | - |
|
| 331 | - // Variables initialized |
|
| 332 | - $this->uri = new URI; |
|
| 333 | - $this->method = null; |
|
| 334 | - $this->baseUrl = null; |
|
| 335 | - $this->content = $content; |
|
| 336 | - $this->pathInfo = null; |
|
| 337 | - $this->languages = null; |
|
| 338 | - $this->acceptableContentTypes = null; |
|
| 339 | - $this->validLocales = config('app.supportedLocales'); |
|
| 340 | - $this->clientIp = new RequestClientIP($this->server->all()); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Clones a request and overrides some of its parameters. |
|
| 345 | - * |
|
| 346 | - * @param array|null $query |
|
| 347 | - * @param array|null $request |
|
| 348 | - * @param array|null $attributes |
|
| 349 | - * @param array|null $cookies |
|
| 350 | - * @param array|null $files |
|
| 351 | - * @param array|null $server |
|
| 352 | - * |
|
| 353 | - * @return static |
|
| 354 | - */ |
|
| 355 | - public function duplicate( |
|
| 356 | - array $query = null, |
|
| 357 | - array $request = null, |
|
| 358 | - array $attributes = null, |
|
| 359 | - array $cookies = null, |
|
| 360 | - array $files = null, |
|
| 361 | - array $server = null |
|
| 362 | - ): static { |
|
| 363 | - $duplicate = clone $this; |
|
| 364 | - |
|
| 365 | - if (null !== $query) { |
|
| 366 | - $duplicate->query = new Inputs($query); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - if (null !== $request) { |
|
| 370 | - $duplicate->request = new Inputs($request); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - if (null !== $attributes) { |
|
| 374 | - $duplicate->attributes = new Parameters($attributes); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - if (null !== $cookies) { |
|
| 378 | - $duplicate->cookies = new Inputs($cookies); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - if (null !== $files) { |
|
| 382 | - $duplicate->files = new Files($files); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - if (null !== $server) { |
|
| 386 | - $duplicate->server = new Server($server); |
|
| 387 | - $duplicate->headers = new Headers($duplicate->server->all()); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - $duplicate->uri = new URI; |
|
| 391 | - $duplicate->locale = null; |
|
| 392 | - $duplicate->method = null; |
|
| 393 | - $duplicate->baseUrl = null; |
|
| 394 | - $duplicate->pathInfo = null; |
|
| 395 | - $duplicate->validLocales = config('app.supportedLocales'); |
|
| 396 | - $duplicate->clientIp = new RequestClientIP($duplicate->server->all()); |
|
| 397 | - |
|
| 398 | - return $duplicate; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Handles setting up the locale, auto-detecting of language. |
|
| 403 | - * |
|
| 404 | - * @return void |
|
| 405 | - */ |
|
| 406 | - public function detectLocale(): void |
|
| 407 | - { |
|
| 408 | - $this->languages = $this->defaultLocale = config('app.locale'); |
|
| 409 | - |
|
| 410 | - $this->setLocale($this->validLocales[0]); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Returns the default locale as set. |
|
| 415 | - * |
|
| 416 | - * @return string |
|
| 417 | - */ |
|
| 418 | - public function getDefaultLocale(): string |
|
| 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(): string |
|
| 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 static |
|
| 439 | - */ |
|
| 440 | - public function setLocale(string $locale): static |
|
| 441 | - { |
|
| 442 | - if ( ! in_array($locale, $this->validLocales, true)) { |
|
| 443 | - $locale = $this->defaultLocale; |
|
| 444 | - } |
|
| 236 | + return $newRequest; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Creates a new request with value from PHP's super global. |
|
| 241 | + * |
|
| 242 | + * @return static |
|
| 243 | + */ |
|
| 244 | + public static function createFromRequestGlobals(): static |
|
| 245 | + { |
|
| 246 | + $request = static::createFromRequestFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER); |
|
| 247 | + |
|
| 248 | + if (Str::startsWith($request->headers->get('CONTENT_TYPE', ''), 'application/x-www-form-urlencoded') |
|
| 249 | + && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])) { |
|
| 250 | + parse_str($request->getContent(), $data); |
|
| 251 | + $request->request = new Inputs($data); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return $request; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Creates a new request from a factory. |
|
| 259 | + * |
|
| 260 | + * @param array $query |
|
| 261 | + * @param array $request |
|
| 262 | + * @param array $attributes |
|
| 263 | + * @param array $cookies |
|
| 264 | + * @param array $files |
|
| 265 | + * @param array $server |
|
| 266 | + * |
|
| 267 | + * @return static |
|
| 268 | + */ |
|
| 269 | + private static function createFromRequestFactory( |
|
| 270 | + array $query = [], |
|
| 271 | + array $request = [], |
|
| 272 | + array $attributes = [] , |
|
| 273 | + array $cookies = [], |
|
| 274 | + array $files = [], |
|
| 275 | + array $server = [] |
|
| 276 | + ): static { |
|
| 277 | + if (self::$requestURI) { |
|
| 278 | + $request = (self::$requestURI)($query, $request, [], $cookies, $files, $server); |
|
| 279 | + |
|
| 280 | + if ( ! $request instanceof self) { |
|
| 281 | + throw new LogicException('The Request active must return an instance of Syscodes\Components\Http\Request'); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $request; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + return new static($query, $request, $attributes, $cookies, $files, $server); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Returns the factory request currently being used. |
|
| 292 | + * |
|
| 293 | + * @param \Syscodes\Components\Http\Request|callable|null $request |
|
| 294 | + * |
|
| 295 | + * @return void |
|
| 296 | + */ |
|
| 297 | + public static function setFactory(?callable $request): void |
|
| 298 | + { |
|
| 299 | + self::$requestURI = $request; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Sets the parameters for this request. |
|
| 304 | + * |
|
| 305 | + * @param array $query |
|
| 306 | + * @param array $request |
|
| 307 | + * @param array $attributes |
|
| 308 | + * @param array $cookies |
|
| 309 | + * @param array $files |
|
| 310 | + * @param array $server |
|
| 311 | + * |
|
| 312 | + * @return void |
|
| 313 | + */ |
|
| 314 | + public function initialize( |
|
| 315 | + array $query = [], |
|
| 316 | + array $request = [], |
|
| 317 | + array $attributes = [], |
|
| 318 | + array $cookies = [], |
|
| 319 | + array $files = [], |
|
| 320 | + array $server = [], |
|
| 321 | + $content = null |
|
| 322 | + ): void { |
|
| 323 | + $this->query = new Inputs($query); |
|
| 324 | + $this->request = new Inputs($request); |
|
| 325 | + $this->attributes = new Parameters($attributes); |
|
| 326 | + $this->cookies = new Inputs($cookies); |
|
| 327 | + $this->files = new Files($files); |
|
| 328 | + $this->server = new Server($server); |
|
| 329 | + $this->headers = new Headers($this->server->all()); |
|
| 330 | + |
|
| 331 | + // Variables initialized |
|
| 332 | + $this->uri = new URI; |
|
| 333 | + $this->method = null; |
|
| 334 | + $this->baseUrl = null; |
|
| 335 | + $this->content = $content; |
|
| 336 | + $this->pathInfo = null; |
|
| 337 | + $this->languages = null; |
|
| 338 | + $this->acceptableContentTypes = null; |
|
| 339 | + $this->validLocales = config('app.supportedLocales'); |
|
| 340 | + $this->clientIp = new RequestClientIP($this->server->all()); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Clones a request and overrides some of its parameters. |
|
| 345 | + * |
|
| 346 | + * @param array|null $query |
|
| 347 | + * @param array|null $request |
|
| 348 | + * @param array|null $attributes |
|
| 349 | + * @param array|null $cookies |
|
| 350 | + * @param array|null $files |
|
| 351 | + * @param array|null $server |
|
| 352 | + * |
|
| 353 | + * @return static |
|
| 354 | + */ |
|
| 355 | + public function duplicate( |
|
| 356 | + array $query = null, |
|
| 357 | + array $request = null, |
|
| 358 | + array $attributes = null, |
|
| 359 | + array $cookies = null, |
|
| 360 | + array $files = null, |
|
| 361 | + array $server = null |
|
| 362 | + ): static { |
|
| 363 | + $duplicate = clone $this; |
|
| 364 | + |
|
| 365 | + if (null !== $query) { |
|
| 366 | + $duplicate->query = new Inputs($query); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + if (null !== $request) { |
|
| 370 | + $duplicate->request = new Inputs($request); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + if (null !== $attributes) { |
|
| 374 | + $duplicate->attributes = new Parameters($attributes); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + if (null !== $cookies) { |
|
| 378 | + $duplicate->cookies = new Inputs($cookies); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + if (null !== $files) { |
|
| 382 | + $duplicate->files = new Files($files); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + if (null !== $server) { |
|
| 386 | + $duplicate->server = new Server($server); |
|
| 387 | + $duplicate->headers = new Headers($duplicate->server->all()); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + $duplicate->uri = new URI; |
|
| 391 | + $duplicate->locale = null; |
|
| 392 | + $duplicate->method = null; |
|
| 393 | + $duplicate->baseUrl = null; |
|
| 394 | + $duplicate->pathInfo = null; |
|
| 395 | + $duplicate->validLocales = config('app.supportedLocales'); |
|
| 396 | + $duplicate->clientIp = new RequestClientIP($duplicate->server->all()); |
|
| 397 | + |
|
| 398 | + return $duplicate; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Handles setting up the locale, auto-detecting of language. |
|
| 403 | + * |
|
| 404 | + * @return void |
|
| 405 | + */ |
|
| 406 | + public function detectLocale(): void |
|
| 407 | + { |
|
| 408 | + $this->languages = $this->defaultLocale = config('app.locale'); |
|
| 409 | + |
|
| 410 | + $this->setLocale($this->validLocales[0]); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Returns the default locale as set. |
|
| 415 | + * |
|
| 416 | + * @return string |
|
| 417 | + */ |
|
| 418 | + public function getDefaultLocale(): string |
|
| 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(): string |
|
| 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 static |
|
| 439 | + */ |
|
| 440 | + public function setLocale(string $locale): static |
|
| 441 | + { |
|
| 442 | + if ( ! in_array($locale, $this->validLocales, true)) { |
|
| 443 | + $locale = $this->defaultLocale; |
|
| 444 | + } |
|
| 445 | 445 | |
| 446 | - $this->languages = $locale; |
|
| 446 | + $this->languages = $locale; |
|
| 447 | 447 | |
| 448 | - Locale::setDefault($locale); |
|
| 448 | + Locale::setDefault($locale); |
|
| 449 | 449 | |
| 450 | - return $this; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Returns the host name. |
|
| 455 | - * |
|
| 456 | - * @return string |
|
| 457 | - */ |
|
| 458 | - public function getHost(): string |
|
| 459 | - { |
|
| 460 | - if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) { |
|
| 461 | - $host = $forwardedHost[0]; |
|
| 462 | - } elseif ( ! $host = $this->headers->get('HOST')) { |
|
| 463 | - if ( ! $host = $this->server->get('SERVER_NAME')) { |
|
| 464 | - $host = $this->server->get('REMOTE_ADDR', ''); |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - $host = strtolower(preg_replace('/:\d+$/', '', trim(($host)))); |
|
| 450 | + return $this; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Returns the host name. |
|
| 455 | + * |
|
| 456 | + * @return string |
|
| 457 | + */ |
|
| 458 | + public function getHost(): string |
|
| 459 | + { |
|
| 460 | + if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) { |
|
| 461 | + $host = $forwardedHost[0]; |
|
| 462 | + } elseif ( ! $host = $this->headers->get('HOST')) { |
|
| 463 | + if ( ! $host = $this->server->get('SERVER_NAME')) { |
|
| 464 | + $host = $this->server->get('REMOTE_ADDR', ''); |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + $host = strtolower(preg_replace('/:\d+$/', '', trim(($host)))); |
|
| 469 | 469 | |
| 470 | - return $this->uri->setHost($host); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Returns the port on which the request is made. |
|
| 475 | - * |
|
| 476 | - * @return int |
|
| 477 | - */ |
|
| 478 | - public function getPort(): int |
|
| 479 | - { |
|
| 480 | - if ( ! $this->server->get('HTTP_HOST')) { |
|
| 481 | - return $this->server->get('SERVER_PORT'); |
|
| 482 | - } |
|
| 470 | + return $this->uri->setHost($host); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Returns the port on which the request is made. |
|
| 475 | + * |
|
| 476 | + * @return int |
|
| 477 | + */ |
|
| 478 | + public function getPort(): int |
|
| 479 | + { |
|
| 480 | + if ( ! $this->server->get('HTTP_HOST')) { |
|
| 481 | + return $this->server->get('SERVER_PORT'); |
|
| 482 | + } |
|
| 483 | 483 | |
| 484 | - return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Gets the request's scheme. |
|
| 489 | - * |
|
| 490 | - * @return string |
|
| 491 | - */ |
|
| 492 | - public function getScheme(): string |
|
| 493 | - { |
|
| 494 | - return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http'); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Get the user. |
|
| 499 | - * |
|
| 500 | - * @return string|null |
|
| 501 | - */ |
|
| 502 | - public function getUser(): ?string |
|
| 503 | - { |
|
| 504 | - $user = $this->uri->setUser( |
|
| 505 | - $this->headers->get('PHP_AUTH_USER') |
|
| 506 | - ); |
|
| 507 | - |
|
| 508 | - return $user; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * Get the password. |
|
| 513 | - * |
|
| 514 | - * @return string|null |
|
| 515 | - */ |
|
| 516 | - public function getPassword(): ?string |
|
| 517 | - { |
|
| 518 | - $password = $this->uri->setPassword( |
|
| 519 | - $this->headers->get('PHP_AUTH_PW') |
|
| 520 | - ); |
|
| 521 | - |
|
| 522 | - return $password; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * Gets the user info. |
|
| 527 | - * |
|
| 528 | - * @return string|null |
|
| 529 | - */ |
|
| 530 | - public function getUserInfo(): ?string |
|
| 531 | - { |
|
| 532 | - return $this->uri->getUserInfo(); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * Returns the HTTP host being requested. |
|
| 537 | - * |
|
| 538 | - * @return string |
|
| 539 | - */ |
|
| 540 | - public function getHttpHost(): string |
|
| 541 | - { |
|
| 542 | - $scheme = $this->getScheme(); |
|
| 543 | - $port = $this->getPort(); |
|
| 544 | - |
|
| 545 | - if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) { |
|
| 546 | - return $this->getHost(); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - return $this->getHost().':'.$port; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Gets the scheme and HTTP host. |
|
| 554 | - * |
|
| 555 | - * @return string |
|
| 556 | - */ |
|
| 557 | - public function getSchemeWithHttpHost(): string |
|
| 558 | - { |
|
| 559 | - return $this->getScheme().'://'.$this->getHttpHost(); |
|
| 560 | - } |
|
| 484 | + return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Gets the request's scheme. |
|
| 489 | + * |
|
| 490 | + * @return string |
|
| 491 | + */ |
|
| 492 | + public function getScheme(): string |
|
| 493 | + { |
|
| 494 | + return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http'); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Get the user. |
|
| 499 | + * |
|
| 500 | + * @return string|null |
|
| 501 | + */ |
|
| 502 | + public function getUser(): ?string |
|
| 503 | + { |
|
| 504 | + $user = $this->uri->setUser( |
|
| 505 | + $this->headers->get('PHP_AUTH_USER') |
|
| 506 | + ); |
|
| 507 | + |
|
| 508 | + return $user; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * Get the password. |
|
| 513 | + * |
|
| 514 | + * @return string|null |
|
| 515 | + */ |
|
| 516 | + public function getPassword(): ?string |
|
| 517 | + { |
|
| 518 | + $password = $this->uri->setPassword( |
|
| 519 | + $this->headers->get('PHP_AUTH_PW') |
|
| 520 | + ); |
|
| 521 | + |
|
| 522 | + return $password; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * Gets the user info. |
|
| 527 | + * |
|
| 528 | + * @return string|null |
|
| 529 | + */ |
|
| 530 | + public function getUserInfo(): ?string |
|
| 531 | + { |
|
| 532 | + return $this->uri->getUserInfo(); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * Returns the HTTP host being requested. |
|
| 537 | + * |
|
| 538 | + * @return string |
|
| 539 | + */ |
|
| 540 | + public function getHttpHost(): string |
|
| 541 | + { |
|
| 542 | + $scheme = $this->getScheme(); |
|
| 543 | + $port = $this->getPort(); |
|
| 544 | + |
|
| 545 | + if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) { |
|
| 546 | + return $this->getHost(); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + return $this->getHost().':'.$port; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Gets the scheme and HTTP host. |
|
| 554 | + * |
|
| 555 | + * @return string |
|
| 556 | + */ |
|
| 557 | + public function getSchemeWithHttpHost(): string |
|
| 558 | + { |
|
| 559 | + return $this->getScheme().'://'.$this->getHttpHost(); |
|
| 560 | + } |
|
| 561 | 561 | } |
| 562 | 562 | \ No newline at end of file |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | private static function createFromRequestFactory( |
| 270 | 270 | array $query = [], |
| 271 | 271 | array $request = [], |
| 272 | - array $attributes = [] , |
|
| 272 | + array $attributes = [], |
|
| 273 | 273 | array $cookies = [], |
| 274 | 274 | array $files = [], |
| 275 | 275 | array $server = [] |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | $scheme = $this->getScheme(); |
| 543 | 543 | $port = $this->getPort(); |
| 544 | 544 | |
| 545 | - if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) { |
|
| 545 | + if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) { |
|
| 546 | 546 | return $this->getHost(); |
| 547 | 547 | } |
| 548 | 548 | |
@@ -43,283 +43,283 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | class Request |
| 45 | 45 | { |
| 46 | - use HttpRequest, |
|
| 47 | - HttpResources, |
|
| 48 | - CanBePrecognitive, |
|
| 49 | - InteractsWithInput, |
|
| 50 | - InteractsWithFlashData, |
|
| 51 | - InteractsWithContentTypes; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Get the acceptable of content types. |
|
| 55 | - * |
|
| 56 | - * @var string[] $acceptableContenTypes |
|
| 57 | - */ |
|
| 58 | - protected $acceptableContentTypes; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * The decoded JSON content for the request. |
|
| 62 | - * |
|
| 63 | - * @var \Syscodes\Components\Http\Loaders\Parameters|null $json |
|
| 64 | - */ |
|
| 65 | - protected $json; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * The path info of URL. |
|
| 69 | - * |
|
| 70 | - * @var string $pathInfo |
|
| 71 | - */ |
|
| 72 | - protected $pathInfo; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Get request URI. |
|
| 76 | - * |
|
| 77 | - * @var string $requestToUri |
|
| 78 | - */ |
|
| 79 | - protected $requestToUri; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Get the route resolver callback. |
|
| 83 | - * |
|
| 84 | - * @var \Closure $routeResolver |
|
| 85 | - */ |
|
| 86 | - protected $routeResolver; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * The Session implementation. |
|
| 90 | - * |
|
| 91 | - * @var \Syscodes\Components\Contracts\Session\Session $session |
|
| 92 | - */ |
|
| 93 | - protected $session; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Create a new Syscodes HTTP request from server variables. |
|
| 97 | - * |
|
| 98 | - * @return static |
|
| 99 | - */ |
|
| 100 | - public static function capture(): static |
|
| 101 | - { |
|
| 102 | - static::enabledHttpMethodParameterOverride(); |
|
| 46 | + use HttpRequest, |
|
| 47 | + HttpResources, |
|
| 48 | + CanBePrecognitive, |
|
| 49 | + InteractsWithInput, |
|
| 50 | + InteractsWithFlashData, |
|
| 51 | + InteractsWithContentTypes; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Get the acceptable of content types. |
|
| 55 | + * |
|
| 56 | + * @var string[] $acceptableContenTypes |
|
| 57 | + */ |
|
| 58 | + protected $acceptableContentTypes; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * The decoded JSON content for the request. |
|
| 62 | + * |
|
| 63 | + * @var \Syscodes\Components\Http\Loaders\Parameters|null $json |
|
| 64 | + */ |
|
| 65 | + protected $json; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * The path info of URL. |
|
| 69 | + * |
|
| 70 | + * @var string $pathInfo |
|
| 71 | + */ |
|
| 72 | + protected $pathInfo; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Get request URI. |
|
| 76 | + * |
|
| 77 | + * @var string $requestToUri |
|
| 78 | + */ |
|
| 79 | + protected $requestToUri; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Get the route resolver callback. |
|
| 83 | + * |
|
| 84 | + * @var \Closure $routeResolver |
|
| 85 | + */ |
|
| 86 | + protected $routeResolver; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * The Session implementation. |
|
| 90 | + * |
|
| 91 | + * @var \Syscodes\Components\Contracts\Session\Session $session |
|
| 92 | + */ |
|
| 93 | + protected $session; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Create a new Syscodes HTTP request from server variables. |
|
| 97 | + * |
|
| 98 | + * @return static |
|
| 99 | + */ |
|
| 100 | + public static function capture(): static |
|
| 101 | + { |
|
| 102 | + static::enabledHttpMethodParameterOverride(); |
|
| 103 | 103 | |
| 104 | - return static::createFromRequest(static::createFromRequestGlobals()); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Returns the desired segment, or $default if it does not exist. |
|
| 109 | - * |
|
| 110 | - * @param int $index The segment number (1-based index) |
|
| 111 | - * @param mixed $default Default value to return |
|
| 112 | - * |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - public function segment($index, $default = null) |
|
| 116 | - { |
|
| 117 | - return $this->uri->getSegment($index, $default); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Returns all segments in an array. For total of segments |
|
| 122 | - * used the function PHP count(). |
|
| 123 | - * |
|
| 124 | - * @return array|null |
|
| 125 | - */ |
|
| 126 | - public function segments() |
|
| 127 | - { |
|
| 128 | - return $this->uri->getSegments(); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Returns the total number of segment. |
|
| 133 | - * |
|
| 134 | - * @return int|null |
|
| 135 | - */ |
|
| 136 | - public function totalSegments() |
|
| 137 | - { |
|
| 138 | - return $this->uri->getTotalSegments(); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Returns the full request string. |
|
| 143 | - * |
|
| 144 | - * @param string $key |
|
| 145 | - * @param mixed $default |
|
| 146 | - * |
|
| 147 | - * @return mixed |
|
| 148 | - */ |
|
| 149 | - public function get(string $key, $default = null) |
|
| 150 | - { |
|
| 151 | - if ($this !== $result = $this->attributes->get($key, $this)) { |
|
| 152 | - return $result; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - if ($this->query->has($key)) { |
|
| 156 | - return $this->query->all()[$key]; |
|
| 157 | - } |
|
| 104 | + return static::createFromRequest(static::createFromRequestGlobals()); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Returns the desired segment, or $default if it does not exist. |
|
| 109 | + * |
|
| 110 | + * @param int $index The segment number (1-based index) |
|
| 111 | + * @param mixed $default Default value to return |
|
| 112 | + * |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + public function segment($index, $default = null) |
|
| 116 | + { |
|
| 117 | + return $this->uri->getSegment($index, $default); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Returns all segments in an array. For total of segments |
|
| 122 | + * used the function PHP count(). |
|
| 123 | + * |
|
| 124 | + * @return array|null |
|
| 125 | + */ |
|
| 126 | + public function segments() |
|
| 127 | + { |
|
| 128 | + return $this->uri->getSegments(); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Returns the total number of segment. |
|
| 133 | + * |
|
| 134 | + * @return int|null |
|
| 135 | + */ |
|
| 136 | + public function totalSegments() |
|
| 137 | + { |
|
| 138 | + return $this->uri->getTotalSegments(); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Returns the full request string. |
|
| 143 | + * |
|
| 144 | + * @param string $key |
|
| 145 | + * @param mixed $default |
|
| 146 | + * |
|
| 147 | + * @return mixed |
|
| 148 | + */ |
|
| 149 | + public function get(string $key, $default = null) |
|
| 150 | + { |
|
| 151 | + if ($this !== $result = $this->attributes->get($key, $this)) { |
|
| 152 | + return $result; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + if ($this->query->has($key)) { |
|
| 156 | + return $this->query->all()[$key]; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - if ($this->request->has($key)) { |
|
| 160 | - return $this->request->all()[$key]; |
|
| 161 | - } |
|
| 159 | + if ($this->request->has($key)) { |
|
| 160 | + return $this->request->all()[$key]; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - return $default; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Gets the Session. |
|
| 168 | - * |
|
| 169 | - * @return \Syscodes\Components\Http\Session\SessionInterface |
|
| 170 | - * |
|
| 171 | - * @throws \Syscodes\Components\Http\Exceptions\SessionNotFoundException |
|
| 172 | - */ |
|
| 173 | - public function getSession() |
|
| 174 | - { |
|
| 175 | - $this->hasSession() |
|
| 176 | - ? new SessionDecorator($this->session()) |
|
| 177 | - : throw new SessionNotFoundException; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Whether the request contains a Session object. |
|
| 182 | - * |
|
| 183 | - * @return bool |
|
| 184 | - */ |
|
| 185 | - public function hasSession(): bool |
|
| 186 | - { |
|
| 187 | - return ! is_null($this->session); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Get the session associated with the request. |
|
| 192 | - * |
|
| 193 | - * @return \Syscodes\Components\Contracts\Session\Session |
|
| 194 | - * |
|
| 195 | - * @throws RuntimeException |
|
| 196 | - */ |
|
| 197 | - public function session() |
|
| 198 | - { |
|
| 199 | - if ( ! $this->hasSession()) { |
|
| 200 | - throw new RuntimeException('Session store not set on request'); |
|
| 201 | - } |
|
| 163 | + return $default; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Gets the Session. |
|
| 168 | + * |
|
| 169 | + * @return \Syscodes\Components\Http\Session\SessionInterface |
|
| 170 | + * |
|
| 171 | + * @throws \Syscodes\Components\Http\Exceptions\SessionNotFoundException |
|
| 172 | + */ |
|
| 173 | + public function getSession() |
|
| 174 | + { |
|
| 175 | + $this->hasSession() |
|
| 176 | + ? new SessionDecorator($this->session()) |
|
| 177 | + : throw new SessionNotFoundException; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Whether the request contains a Session object. |
|
| 182 | + * |
|
| 183 | + * @return bool |
|
| 184 | + */ |
|
| 185 | + public function hasSession(): bool |
|
| 186 | + { |
|
| 187 | + return ! is_null($this->session); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Get the session associated with the request. |
|
| 192 | + * |
|
| 193 | + * @return \Syscodes\Components\Contracts\Session\Session |
|
| 194 | + * |
|
| 195 | + * @throws RuntimeException |
|
| 196 | + */ |
|
| 197 | + public function session() |
|
| 198 | + { |
|
| 199 | + if ( ! $this->hasSession()) { |
|
| 200 | + throw new RuntimeException('Session store not set on request'); |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - return $this->session; |
|
| 204 | - } |
|
| 203 | + return $this->session; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * Set the session instance on the request. |
|
| 208 | - * |
|
| 209 | - * @param \Syscodes\Components\Contracts\Session\Session $session |
|
| 210 | - * |
|
| 211 | - * @return void |
|
| 212 | - */ |
|
| 213 | - public function setSession($session): void |
|
| 214 | - { |
|
| 215 | - $this->session = $session; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Get the JSON payload for the request. |
|
| 220 | - * |
|
| 221 | - * @param string|null $key |
|
| 222 | - * @param mixed $default |
|
| 223 | - * |
|
| 224 | - * @return \Syscodes\Components\Http\Loaders\Parameters|mixed |
|
| 225 | - */ |
|
| 226 | - public function json($key = null, $default = null) |
|
| 227 | - { |
|
| 228 | - if ( ! isset($this->json)) { |
|
| 229 | - $this->json = new Parameters((array) json_decode($this->getContent(), true)); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - if (is_null($key)) { |
|
| 233 | - return $this->json; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - return Arr::get($this->json->all(), $key, $default); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Set the JSON payload for the request. |
|
| 241 | - * |
|
| 242 | - * @param \Syscodes\Components\Http\Loaders\Parameters $json |
|
| 243 | - * |
|
| 244 | - * @return static |
|
| 245 | - */ |
|
| 246 | - public function setJson($json): static |
|
| 247 | - { |
|
| 248 | - $this->json = $json; |
|
| 249 | - |
|
| 250 | - return $this; |
|
| 251 | - } |
|
| 206 | + /** |
|
| 207 | + * Set the session instance on the request. |
|
| 208 | + * |
|
| 209 | + * @param \Syscodes\Components\Contracts\Session\Session $session |
|
| 210 | + * |
|
| 211 | + * @return void |
|
| 212 | + */ |
|
| 213 | + public function setSession($session): void |
|
| 214 | + { |
|
| 215 | + $this->session = $session; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Get the JSON payload for the request. |
|
| 220 | + * |
|
| 221 | + * @param string|null $key |
|
| 222 | + * @param mixed $default |
|
| 223 | + * |
|
| 224 | + * @return \Syscodes\Components\Http\Loaders\Parameters|mixed |
|
| 225 | + */ |
|
| 226 | + public function json($key = null, $default = null) |
|
| 227 | + { |
|
| 228 | + if ( ! isset($this->json)) { |
|
| 229 | + $this->json = new Parameters((array) json_decode($this->getContent(), true)); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + if (is_null($key)) { |
|
| 233 | + return $this->json; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + return Arr::get($this->json->all(), $key, $default); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Set the JSON payload for the request. |
|
| 241 | + * |
|
| 242 | + * @param \Syscodes\Components\Http\Loaders\Parameters $json |
|
| 243 | + * |
|
| 244 | + * @return static |
|
| 245 | + */ |
|
| 246 | + public function setJson($json): static |
|
| 247 | + { |
|
| 248 | + $this->json = $json; |
|
| 249 | + |
|
| 250 | + return $this; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Gets a list of content types acceptable by the client browser in preferable order. |
|
| 255 | - * |
|
| 256 | - * @return string[] |
|
| 257 | - */ |
|
| 258 | - public function getAcceptableContentTypes(): array |
|
| 259 | - { |
|
| 260 | - if (null !== $this->acceptableContentTypes) { |
|
| 261 | - return $this->acceptableContentTypes; |
|
| 262 | - } |
|
| 253 | + /** |
|
| 254 | + * Gets a list of content types acceptable by the client browser in preferable order. |
|
| 255 | + * |
|
| 256 | + * @return string[] |
|
| 257 | + */ |
|
| 258 | + public function getAcceptableContentTypes(): array |
|
| 259 | + { |
|
| 260 | + if (null !== $this->acceptableContentTypes) { |
|
| 261 | + return $this->acceptableContentTypes; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - return $this->acceptableContentTypes = array_map('strval', [$this->headers->get('Accept')]); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Returns whether this is an AJAX request or not. |
|
| 269 | - * Alias of isXmlHttpRequest(). |
|
| 270 | - * |
|
| 271 | - * @return bool |
|
| 272 | - */ |
|
| 273 | - public function ajax(): bool |
|
| 274 | - { |
|
| 275 | - return $this->isXmlHttpRequest(); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Returns whether this is an AJAX request or not. |
|
| 280 | - * |
|
| 281 | - * @return bool |
|
| 282 | - */ |
|
| 283 | - public function isXmlHttpRequest(): bool |
|
| 284 | - { |
|
| 285 | - return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && |
|
| 286 | - strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest'; |
|
| 287 | - } |
|
| 264 | + return $this->acceptableContentTypes = array_map('strval', [$this->headers->get('Accept')]); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Returns whether this is an AJAX request or not. |
|
| 269 | + * Alias of isXmlHttpRequest(). |
|
| 270 | + * |
|
| 271 | + * @return bool |
|
| 272 | + */ |
|
| 273 | + public function ajax(): bool |
|
| 274 | + { |
|
| 275 | + return $this->isXmlHttpRequest(); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Returns whether this is an AJAX request or not. |
|
| 280 | + * |
|
| 281 | + * @return bool |
|
| 282 | + */ |
|
| 283 | + public function isXmlHttpRequest(): bool |
|
| 284 | + { |
|
| 285 | + return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && |
|
| 286 | + strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest'; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - /** |
|
| 290 | - * Determine if the request is the result of a PJAX call. |
|
| 291 | - * |
|
| 292 | - * @return bool |
|
| 293 | - */ |
|
| 294 | - public function pjax(): bool |
|
| 295 | - { |
|
| 296 | - return $this->headers->get('X-PJAX') == true; |
|
| 297 | - } |
|
| 289 | + /** |
|
| 290 | + * Determine if the request is the result of a PJAX call. |
|
| 291 | + * |
|
| 292 | + * @return bool |
|
| 293 | + */ |
|
| 294 | + public function pjax(): bool |
|
| 295 | + { |
|
| 296 | + return $this->headers->get('X-PJAX') == true; |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Determine if the request is the result of a prefetch call. |
|
| 301 | - * |
|
| 302 | - * @return bool |
|
| 303 | - */ |
|
| 304 | - public function prefetch(): bool |
|
| 305 | - { |
|
| 306 | - return strcasecmp($this->server->get('HTTP_X_MOZ') ?? '', 'prefetch') === 0 || |
|
| 307 | - strcasecmp($this->headers->get('Purpose') ?? '', 'prefetch') === 0; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Checks if the method request is of specified type. |
|
| 312 | - * |
|
| 313 | - * @param string $method |
|
| 314 | - * |
|
| 315 | - * @return bool |
|
| 316 | - */ |
|
| 317 | - public function isMethod(string $method): bool |
|
| 318 | - { |
|
| 319 | - return $this->getMethod() === strtoupper($method); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 299 | + /** |
|
| 300 | + * Determine if the request is the result of a prefetch call. |
|
| 301 | + * |
|
| 302 | + * @return bool |
|
| 303 | + */ |
|
| 304 | + public function prefetch(): bool |
|
| 305 | + { |
|
| 306 | + return strcasecmp($this->server->get('HTTP_X_MOZ') ?? '', 'prefetch') === 0 || |
|
| 307 | + strcasecmp($this->headers->get('Purpose') ?? '', 'prefetch') === 0; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Checks if the method request is of specified type. |
|
| 312 | + * |
|
| 313 | + * @param string $method |
|
| 314 | + * |
|
| 315 | + * @return bool |
|
| 316 | + */ |
|
| 317 | + public function isMethod(string $method): bool |
|
| 318 | + { |
|
| 319 | + return $this->getMethod() === strtoupper($method); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | 323 | * Alias of the request method. |
| 324 | 324 | * |
| 325 | 325 | * @return string |
@@ -329,414 +329,414 @@ discard block |
||
| 329 | 329 | return $this->getMethod(); |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - /** |
|
| 333 | - * Returns the input method used (GET, POST, DELETE, etc.). |
|
| 334 | - * |
|
| 335 | - * @return string |
|
| 336 | - * |
|
| 337 | - * @throws \LogicException |
|
| 338 | - */ |
|
| 339 | - public function getmethod(): string |
|
| 340 | - { |
|
| 341 | - if (null !== $this->method) { |
|
| 342 | - return $this->method; |
|
| 343 | - } |
|
| 332 | + /** |
|
| 333 | + * Returns the input method used (GET, POST, DELETE, etc.). |
|
| 334 | + * |
|
| 335 | + * @return string |
|
| 336 | + * |
|
| 337 | + * @throws \LogicException |
|
| 338 | + */ |
|
| 339 | + public function getmethod(): string |
|
| 340 | + { |
|
| 341 | + if (null !== $this->method) { |
|
| 342 | + return $this->method; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - $this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET')); |
|
| 345 | + $this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET')); |
|
| 346 | 346 | |
| 347 | - if ('POST' !== $this->method) { |
|
| 348 | - return $this->method; |
|
| 349 | - } |
|
| 347 | + if ('POST' !== $this->method) { |
|
| 348 | + return $this->method; |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | - $method = $this->headers->get('X-HTTP-METHOD-OVERRIDE'); |
|
| 351 | + $method = $this->headers->get('X-HTTP-METHOD-OVERRIDE'); |
|
| 352 | 352 | |
| 353 | - if ( ! $method && self::$httpMethodParameterOverride) { |
|
| 354 | - $method = $this->request->get('_method', $this->query->get('_method', 'POST')); |
|
| 355 | - } |
|
| 353 | + if ( ! $method && self::$httpMethodParameterOverride) { |
|
| 354 | + $method = $this->request->get('_method', $this->query->get('_method', 'POST')); |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - if ( ! is_string($method)) { |
|
| 358 | - return $this->method; |
|
| 359 | - } |
|
| 357 | + if ( ! is_string($method)) { |
|
| 358 | + return $this->method; |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - $method = strtoupper($method); |
|
| 361 | + $method = strtoupper($method); |
|
| 362 | 362 | |
| 363 | - if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) { |
|
| 364 | - return $this->method = $method; |
|
| 365 | - } |
|
| 363 | + if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) { |
|
| 364 | + return $this->method = $method; |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | - if ( ! preg_match('/^[A-Z]++$/D', $method)) { |
|
| 368 | - throw new LogicException(sprintf('Invalid method override "%s".', $method)); |
|
| 369 | - } |
|
| 367 | + if ( ! preg_match('/^[A-Z]++$/D', $method)) { |
|
| 368 | + throw new LogicException(sprintf('Invalid method override "%s".', $method)); |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | - return $this->method = $method; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Sets the request method. |
|
| 376 | - * |
|
| 377 | - * @param string $method |
|
| 378 | - * |
|
| 379 | - * @return void |
|
| 380 | - */ |
|
| 381 | - public function setMethod(string $method): void |
|
| 382 | - { |
|
| 383 | - $this->method = null; |
|
| 384 | - |
|
| 385 | - $this->server->set('REQUEST_METHOD', $method); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Get the input source for the request. |
|
| 390 | - * |
|
| 391 | - * @return \Syscodes\Components\Http\Loaders\Parameters |
|
| 392 | - */ |
|
| 393 | - public function getInputSource() |
|
| 394 | - { |
|
| 395 | - if ($this->isJson()) { |
|
| 396 | - return $this->json(); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - return in_array($this->getMethod(), ['GET', 'HEAD']) ? $this->query : $this->request; |
|
| 400 | - } |
|
| 371 | + return $this->method = $method; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Sets the request method. |
|
| 376 | + * |
|
| 377 | + * @param string $method |
|
| 378 | + * |
|
| 379 | + * @return void |
|
| 380 | + */ |
|
| 381 | + public function setMethod(string $method): void |
|
| 382 | + { |
|
| 383 | + $this->method = null; |
|
| 384 | + |
|
| 385 | + $this->server->set('REQUEST_METHOD', $method); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Get the input source for the request. |
|
| 390 | + * |
|
| 391 | + * @return \Syscodes\Components\Http\Loaders\Parameters |
|
| 392 | + */ |
|
| 393 | + public function getInputSource() |
|
| 394 | + { |
|
| 395 | + if ($this->isJson()) { |
|
| 396 | + return $this->json(); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + return in_array($this->getMethod(), ['GET', 'HEAD']) ? $this->query : $this->request; |
|
| 400 | + } |
|
| 401 | 401 | |
| 402 | - /** |
|
| 403 | - * Determine if the current request URI matches a pattern. |
|
| 404 | - * |
|
| 405 | - * @param mixed ...$patterns |
|
| 406 | - * |
|
| 407 | - * @return bool |
|
| 408 | - */ |
|
| 409 | - public function is(...$patterns): bool |
|
| 410 | - { |
|
| 411 | - $path = $this->decodedPath(); |
|
| 402 | + /** |
|
| 403 | + * Determine if the current request URI matches a pattern. |
|
| 404 | + * |
|
| 405 | + * @param mixed ...$patterns |
|
| 406 | + * |
|
| 407 | + * @return bool |
|
| 408 | + */ |
|
| 409 | + public function is(...$patterns): bool |
|
| 410 | + { |
|
| 411 | + $path = $this->decodedPath(); |
|
| 412 | 412 | |
| 413 | - foreach ($patterns as $pattern) { |
|
| 414 | - if (Str::is($pattern, $path)) { |
|
| 415 | - return true; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - return false; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Determine if the route name matches a given pattern. |
|
| 424 | - * |
|
| 425 | - * @param mixed ...$patterns |
|
| 426 | - * |
|
| 427 | - * @return bool |
|
| 428 | - */ |
|
| 429 | - public function routeIs(...$patterns): bool |
|
| 430 | - { |
|
| 431 | - return $this->route() && $this->route()->is(...$patterns); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Get the route handling the request. |
|
| 436 | - * |
|
| 437 | - * @param string|null $param |
|
| 438 | - * @param mixed $default |
|
| 439 | - * |
|
| 440 | - * @return \Syscodes\Components\Routing\Route|object|string|null |
|
| 441 | - */ |
|
| 442 | - public function route($param = null, $default = null) |
|
| 443 | - { |
|
| 444 | - $route = call_user_func($this->getRouteResolver()); |
|
| 445 | - |
|
| 446 | - if (is_null($route) || is_null($param)) { |
|
| 447 | - return $route; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - return $route->parameter($param, $default); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Get the current decoded path info for the request. |
|
| 455 | - * |
|
| 456 | - * @return string |
|
| 457 | - */ |
|
| 458 | - public function decodedPath(): string |
|
| 459 | - { |
|
| 460 | - return rawurldecode($this->path()); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Get the current path info for the request. |
|
| 465 | - * |
|
| 466 | - * @return string |
|
| 467 | - */ |
|
| 468 | - public function path(): string |
|
| 469 | - { |
|
| 470 | - $path = trim($this->getPathInfo(), '/'); |
|
| 471 | - |
|
| 472 | - return $path == '' ? '/' : $path; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Get the full URL for the request. |
|
| 477 | - * |
|
| 478 | - * @return string |
|
| 479 | - */ |
|
| 480 | - public function fullUrl(): string |
|
| 481 | - { |
|
| 482 | - $query = $this->getQueryString(); |
|
| 413 | + foreach ($patterns as $pattern) { |
|
| 414 | + if (Str::is($pattern, $path)) { |
|
| 415 | + return true; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + return false; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Determine if the route name matches a given pattern. |
|
| 424 | + * |
|
| 425 | + * @param mixed ...$patterns |
|
| 426 | + * |
|
| 427 | + * @return bool |
|
| 428 | + */ |
|
| 429 | + public function routeIs(...$patterns): bool |
|
| 430 | + { |
|
| 431 | + return $this->route() && $this->route()->is(...$patterns); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Get the route handling the request. |
|
| 436 | + * |
|
| 437 | + * @param string|null $param |
|
| 438 | + * @param mixed $default |
|
| 439 | + * |
|
| 440 | + * @return \Syscodes\Components\Routing\Route|object|string|null |
|
| 441 | + */ |
|
| 442 | + public function route($param = null, $default = null) |
|
| 443 | + { |
|
| 444 | + $route = call_user_func($this->getRouteResolver()); |
|
| 445 | + |
|
| 446 | + if (is_null($route) || is_null($param)) { |
|
| 447 | + return $route; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + return $route->parameter($param, $default); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Get the current decoded path info for the request. |
|
| 455 | + * |
|
| 456 | + * @return string |
|
| 457 | + */ |
|
| 458 | + public function decodedPath(): string |
|
| 459 | + { |
|
| 460 | + return rawurldecode($this->path()); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Get the current path info for the request. |
|
| 465 | + * |
|
| 466 | + * @return string |
|
| 467 | + */ |
|
| 468 | + public function path(): string |
|
| 469 | + { |
|
| 470 | + $path = trim($this->getPathInfo(), '/'); |
|
| 471 | + |
|
| 472 | + return $path == '' ? '/' : $path; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Get the full URL for the request. |
|
| 477 | + * |
|
| 478 | + * @return string |
|
| 479 | + */ |
|
| 480 | + public function fullUrl(): string |
|
| 481 | + { |
|
| 482 | + $query = $this->getQueryString(); |
|
| 483 | 483 | |
| 484 | - $question = $this->getBaseUrl().$this->getPathInfo() === '/' ? '/?' : '?'; |
|
| 484 | + $question = $this->getBaseUrl().$this->getPathInfo() === '/' ? '/?' : '?'; |
|
| 485 | 485 | |
| 486 | - return $query ? $this->url().$question.$query : $this->url(); |
|
| 487 | - } |
|
| 486 | + return $query ? $this->url().$question.$query : $this->url(); |
|
| 487 | + } |
|
| 488 | 488 | |
| 489 | - /** |
|
| 490 | - * Generates the normalized query string for the Request. |
|
| 491 | - * |
|
| 492 | - * @return string |
|
| 493 | - */ |
|
| 494 | - public function getQueryString(): ?string |
|
| 495 | - { |
|
| 496 | - $queryString = RequestUtils::normalizedQueryString($this->server->get('QUERY_STRING')); |
|
| 489 | + /** |
|
| 490 | + * Generates the normalized query string for the Request. |
|
| 491 | + * |
|
| 492 | + * @return string |
|
| 493 | + */ |
|
| 494 | + public function getQueryString(): ?string |
|
| 495 | + { |
|
| 496 | + $queryString = RequestUtils::normalizedQueryString($this->server->get('QUERY_STRING')); |
|
| 497 | 497 | |
| 498 | - return '' === $queryString ? null : $queryString; |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * Retunrs the request body content. |
|
| 503 | - * |
|
| 504 | - * @return string |
|
| 505 | - */ |
|
| 506 | - public function getContent(): string |
|
| 507 | - { |
|
| 508 | - if (null === $this->content || false === $this->content) { |
|
| 509 | - $this->content = file_get_contents('php://input'); |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - return $this->content; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Returns the path being requested relative to the executed script. |
|
| 517 | - * |
|
| 518 | - * @return string |
|
| 519 | - */ |
|
| 520 | - public function getPathInfo(): string |
|
| 521 | - { |
|
| 522 | - if (null === $this->pathInfo) { |
|
| 523 | - $this->pathInfo = $this->parsePathInfo(); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - return $this->pathInfo; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Returns the root URL from which this request is executed. |
|
| 531 | - * |
|
| 532 | - * @return string |
|
| 533 | - */ |
|
| 534 | - public function getBaseUrl(): string |
|
| 535 | - { |
|
| 536 | - if (null === $this->baseUrl) { |
|
| 537 | - $this->baseUrl = $this->parseBaseUrl(); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - return $this->baseUrl; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * Returns the requested URI. |
|
| 545 | - * |
|
| 546 | - * @return string |
|
| 547 | - */ |
|
| 548 | - public function getRequestUri(): string |
|
| 549 | - { |
|
| 550 | - if (null === $this->requestToUri) { |
|
| 551 | - $this->requestToUri = $this->parseRequestUri(); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - return $this->requestToUri; |
|
| 555 | - } |
|
| 498 | + return '' === $queryString ? null : $queryString; |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * Retunrs the request body content. |
|
| 503 | + * |
|
| 504 | + * @return string |
|
| 505 | + */ |
|
| 506 | + public function getContent(): string |
|
| 507 | + { |
|
| 508 | + if (null === $this->content || false === $this->content) { |
|
| 509 | + $this->content = file_get_contents('php://input'); |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + return $this->content; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Returns the path being requested relative to the executed script. |
|
| 517 | + * |
|
| 518 | + * @return string |
|
| 519 | + */ |
|
| 520 | + public function getPathInfo(): string |
|
| 521 | + { |
|
| 522 | + if (null === $this->pathInfo) { |
|
| 523 | + $this->pathInfo = $this->parsePathInfo(); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + return $this->pathInfo; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Returns the root URL from which this request is executed. |
|
| 531 | + * |
|
| 532 | + * @return string |
|
| 533 | + */ |
|
| 534 | + public function getBaseUrl(): string |
|
| 535 | + { |
|
| 536 | + if (null === $this->baseUrl) { |
|
| 537 | + $this->baseUrl = $this->parseBaseUrl(); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + return $this->baseUrl; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * Returns the requested URI. |
|
| 545 | + * |
|
| 546 | + * @return string |
|
| 547 | + */ |
|
| 548 | + public function getRequestUri(): string |
|
| 549 | + { |
|
| 550 | + if (null === $this->requestToUri) { |
|
| 551 | + $this->requestToUri = $this->parseRequestUri(); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + return $this->requestToUri; |
|
| 555 | + } |
|
| 556 | 556 | |
| 557 | - /** |
|
| 558 | - * Generates a normalized URI (URL) for the Request. |
|
| 559 | - * |
|
| 560 | - * @return string |
|
| 561 | - */ |
|
| 562 | - public function getUri(): string |
|
| 563 | - { |
|
| 564 | - if (null !== $query = $this->getQueryString()) { |
|
| 565 | - $query = '?'.$query; |
|
| 566 | - } |
|
| 557 | + /** |
|
| 558 | + * Generates a normalized URI (URL) for the Request. |
|
| 559 | + * |
|
| 560 | + * @return string |
|
| 561 | + */ |
|
| 562 | + public function getUri(): string |
|
| 563 | + { |
|
| 564 | + if (null !== $query = $this->getQueryString()) { |
|
| 565 | + $query = '?'.$query; |
|
| 566 | + } |
|
| 567 | 567 | |
| 568 | - return $this->getSchemeWithHttpHost().$this->getBaseUrl().$this->getPathInfo().$query; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Get the root URL for the application. |
|
| 573 | - * |
|
| 574 | - * @return string |
|
| 575 | - */ |
|
| 576 | - public function root(): string |
|
| 577 | - { |
|
| 578 | - return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/'); |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * Get the URL for the request. |
|
| 583 | - * |
|
| 584 | - * @return string |
|
| 585 | - */ |
|
| 586 | - public function url(): string |
|
| 587 | - { |
|
| 588 | - // Changed $this->path() for $this->getUri() |
|
| 589 | - return rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/'); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Returns the referer. |
|
| 594 | - * |
|
| 595 | - * @param string $default |
|
| 596 | - * |
|
| 597 | - * @return string |
|
| 598 | - */ |
|
| 599 | - public function referer(string $default = ''): string |
|
| 600 | - { |
|
| 601 | - return $this->server->get('HTTP_REFERER', $default); |
|
| 602 | - } |
|
| 568 | + return $this->getSchemeWithHttpHost().$this->getBaseUrl().$this->getPathInfo().$query; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Get the root URL for the application. |
|
| 573 | + * |
|
| 574 | + * @return string |
|
| 575 | + */ |
|
| 576 | + public function root(): string |
|
| 577 | + { |
|
| 578 | + return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/'); |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * Get the URL for the request. |
|
| 583 | + * |
|
| 584 | + * @return string |
|
| 585 | + */ |
|
| 586 | + public function url(): string |
|
| 587 | + { |
|
| 588 | + // Changed $this->path() for $this->getUri() |
|
| 589 | + return rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/'); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Returns the referer. |
|
| 594 | + * |
|
| 595 | + * @param string $default |
|
| 596 | + * |
|
| 597 | + * @return string |
|
| 598 | + */ |
|
| 599 | + public function referer(string $default = ''): string |
|
| 600 | + { |
|
| 601 | + return $this->server->get('HTTP_REFERER', $default); |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | - /** |
|
| 605 | - * Attempts to detect if the current connection is secure through |
|
| 606 | - * over HTTPS protocol. |
|
| 607 | - * |
|
| 608 | - * @return bool |
|
| 609 | - */ |
|
| 610 | - public function secure(): bool |
|
| 611 | - { |
|
| 612 | - if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') { |
|
| 613 | - return true; |
|
| 614 | - } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') { |
|
| 615 | - return true; |
|
| 616 | - } elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') { |
|
| 617 | - return true; |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - return false; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * Returns the user agent. |
|
| 625 | - * |
|
| 626 | - * @param string|null $default |
|
| 627 | - * |
|
| 628 | - * @return string |
|
| 629 | - */ |
|
| 630 | - public function userAgent(string $default = null): string |
|
| 631 | - { |
|
| 632 | - return $this->server->get('HTTP_USER_AGENT', $default); |
|
| 633 | - } |
|
| 604 | + /** |
|
| 605 | + * Attempts to detect if the current connection is secure through |
|
| 606 | + * over HTTPS protocol. |
|
| 607 | + * |
|
| 608 | + * @return bool |
|
| 609 | + */ |
|
| 610 | + public function secure(): bool |
|
| 611 | + { |
|
| 612 | + if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') { |
|
| 613 | + return true; |
|
| 614 | + } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') { |
|
| 615 | + return true; |
|
| 616 | + } elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') { |
|
| 617 | + return true; |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + return false; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + /** |
|
| 624 | + * Returns the user agent. |
|
| 625 | + * |
|
| 626 | + * @param string|null $default |
|
| 627 | + * |
|
| 628 | + * @return string |
|
| 629 | + */ |
|
| 630 | + public function userAgent(string $default = null): string |
|
| 631 | + { |
|
| 632 | + return $this->server->get('HTTP_USER_AGENT', $default); |
|
| 633 | + } |
|
| 634 | 634 | |
| 635 | - /** |
|
| 636 | - * Get the client IP address. |
|
| 637 | - * |
|
| 638 | - * @return string|null |
|
| 639 | - */ |
|
| 640 | - public function ip(): ?string |
|
| 641 | - { |
|
| 642 | - return $this->clientIp->getClientIp(); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * Get the route resolver callback. |
|
| 647 | - * |
|
| 648 | - * @return \Closure |
|
| 649 | - */ |
|
| 650 | - public function getRouteResolver(): Closure |
|
| 651 | - { |
|
| 652 | - return $this->routeResolver ?: function () { |
|
| 653 | - // |
|
| 654 | - }; |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Set the route resolver callback. |
|
| 659 | - * |
|
| 660 | - * @param \Closure $callback |
|
| 661 | - * |
|
| 662 | - * @return static |
|
| 663 | - */ |
|
| 664 | - public function setRouteResolver(Closure $callback): static |
|
| 665 | - { |
|
| 666 | - $this->routeResolver = $callback; |
|
| 667 | - |
|
| 668 | - return $this; |
|
| 669 | - } |
|
| 635 | + /** |
|
| 636 | + * Get the client IP address. |
|
| 637 | + * |
|
| 638 | + * @return string|null |
|
| 639 | + */ |
|
| 640 | + public function ip(): ?string |
|
| 641 | + { |
|
| 642 | + return $this->clientIp->getClientIp(); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Get the route resolver callback. |
|
| 647 | + * |
|
| 648 | + * @return \Closure |
|
| 649 | + */ |
|
| 650 | + public function getRouteResolver(): Closure |
|
| 651 | + { |
|
| 652 | + return $this->routeResolver ?: function () { |
|
| 653 | + // |
|
| 654 | + }; |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Set the route resolver callback. |
|
| 659 | + * |
|
| 660 | + * @param \Closure $callback |
|
| 661 | + * |
|
| 662 | + * @return static |
|
| 663 | + */ |
|
| 664 | + public function setRouteResolver(Closure $callback): static |
|
| 665 | + { |
|
| 666 | + $this->routeResolver = $callback; |
|
| 667 | + |
|
| 668 | + return $this; |
|
| 669 | + } |
|
| 670 | 670 | |
| 671 | - /** |
|
| 672 | - * Magic method. |
|
| 673 | - * |
|
| 674 | - * Check if an input element is set on the request. |
|
| 675 | - * |
|
| 676 | - * @param string $key |
|
| 677 | - * |
|
| 678 | - * @return bool |
|
| 679 | - */ |
|
| 680 | - public function __isset($key) |
|
| 681 | - { |
|
| 682 | - return ! is_null($this->__get($key)); |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Magic method. |
|
| 687 | - * |
|
| 688 | - * Get an element from the request. |
|
| 689 | - * |
|
| 690 | - * @return string[] |
|
| 691 | - */ |
|
| 692 | - public function __get($key) |
|
| 693 | - { |
|
| 694 | - return Arr::get($this->all(), $key, fn () => $this->route($key)); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * Magic method. |
|
| 699 | - * |
|
| 700 | - * Returns the Request as an HTTP string. |
|
| 701 | - * |
|
| 702 | - * @return string |
|
| 703 | - */ |
|
| 704 | - public function __toString(): string |
|
| 705 | - { |
|
| 706 | - $content = $this->getContent(); |
|
| 707 | - |
|
| 708 | - $cookieHeader = ''; |
|
| 709 | - $cookies = []; |
|
| 710 | - |
|
| 711 | - foreach ($this->cookies as $key => $value) { |
|
| 712 | - $cookies[]= is_array($value) ? http_build_query([$key => $value], '', '; ', PHP_QUERY_RFC3986) : "$key=$value"; |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - if ($cookies) { |
|
| 716 | - $cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n"; |
|
| 717 | - } |
|
| 671 | + /** |
|
| 672 | + * Magic method. |
|
| 673 | + * |
|
| 674 | + * Check if an input element is set on the request. |
|
| 675 | + * |
|
| 676 | + * @param string $key |
|
| 677 | + * |
|
| 678 | + * @return bool |
|
| 679 | + */ |
|
| 680 | + public function __isset($key) |
|
| 681 | + { |
|
| 682 | + return ! is_null($this->__get($key)); |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Magic method. |
|
| 687 | + * |
|
| 688 | + * Get an element from the request. |
|
| 689 | + * |
|
| 690 | + * @return string[] |
|
| 691 | + */ |
|
| 692 | + public function __get($key) |
|
| 693 | + { |
|
| 694 | + return Arr::get($this->all(), $key, fn () => $this->route($key)); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * Magic method. |
|
| 699 | + * |
|
| 700 | + * Returns the Request as an HTTP string. |
|
| 701 | + * |
|
| 702 | + * @return string |
|
| 703 | + */ |
|
| 704 | + public function __toString(): string |
|
| 705 | + { |
|
| 706 | + $content = $this->getContent(); |
|
| 707 | + |
|
| 708 | + $cookieHeader = ''; |
|
| 709 | + $cookies = []; |
|
| 710 | + |
|
| 711 | + foreach ($this->cookies as $key => $value) { |
|
| 712 | + $cookies[]= is_array($value) ? http_build_query([$key => $value], '', '; ', PHP_QUERY_RFC3986) : "$key=$value"; |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + if ($cookies) { |
|
| 716 | + $cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n"; |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | - return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n". |
|
| 720 | - $this->headers. |
|
| 721 | - $cookieHeader."\r\n". |
|
| 722 | - $content; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * Magic method. |
|
| 727 | - * |
|
| 728 | - * Clones the current request. |
|
| 729 | - * |
|
| 730 | - * @return void |
|
| 731 | - */ |
|
| 732 | - public function __clone() |
|
| 733 | - { |
|
| 734 | - $this->query = clone $this->query; |
|
| 735 | - $this->request = clone $this->request; |
|
| 736 | - $this->attributes = clone $this->attributes; |
|
| 737 | - $this->cookies = clone $this->cookies; |
|
| 738 | - $this->files = clone $this->files; |
|
| 739 | - $this->server = clone $this->server; |
|
| 740 | - $this->headers = clone $this->headers; |
|
| 741 | - } |
|
| 719 | + return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n". |
|
| 720 | + $this->headers. |
|
| 721 | + $cookieHeader."\r\n". |
|
| 722 | + $content; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + /** |
|
| 726 | + * Magic method. |
|
| 727 | + * |
|
| 728 | + * Clones the current request. |
|
| 729 | + * |
|
| 730 | + * @return void |
|
| 731 | + */ |
|
| 732 | + public function __clone() |
|
| 733 | + { |
|
| 734 | + $this->query = clone $this->query; |
|
| 735 | + $this->request = clone $this->request; |
|
| 736 | + $this->attributes = clone $this->attributes; |
|
| 737 | + $this->cookies = clone $this->cookies; |
|
| 738 | + $this->files = clone $this->files; |
|
| 739 | + $this->server = clone $this->server; |
|
| 740 | + $this->headers = clone $this->headers; |
|
| 741 | + } |
|
| 742 | 742 | } |
| 743 | 743 | \ No newline at end of file |
@@ -649,7 +649,7 @@ discard block |
||
| 649 | 649 | */ |
| 650 | 650 | public function getRouteResolver(): Closure |
| 651 | 651 | { |
| 652 | - return $this->routeResolver ?: function () { |
|
| 652 | + return $this->routeResolver ?: function() { |
|
| 653 | 653 | // |
| 654 | 654 | }; |
| 655 | 655 | } |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | $cookies = []; |
| 710 | 710 | |
| 711 | 711 | foreach ($this->cookies as $key => $value) { |
| 712 | - $cookies[]= is_array($value) ? http_build_query([$key => $value], '', '; ', PHP_QUERY_RFC3986) : "$key=$value"; |
|
| 712 | + $cookies[] = is_array($value) ? http_build_query([$key => $value], '', '; ', PHP_QUERY_RFC3986) : "$key=$value"; |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | if ($cookies) { |