@@ -47,517 +47,517 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | class Request |
| 49 | 49 | { |
| 50 | - use CanBePrecognitive, |
|
| 51 | - HttpResources, |
|
| 52 | - InteractsWithInput, |
|
| 53 | - InteractsWithContentTypes; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Get the http method parameter. |
|
| 57 | - * |
|
| 58 | - * @var bool $httpMethodParameterOverride |
|
| 59 | - */ |
|
| 60 | - protected static $httpMethodParameterOverride = false; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Holds the global active request instance. |
|
| 64 | - * |
|
| 65 | - * @var bool $requestURI |
|
| 66 | - */ |
|
| 67 | - protected static $requestURI; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Get the acceptable of content types. |
|
| 71 | - * |
|
| 72 | - * @var string[] $acceptableContenTypes |
|
| 73 | - */ |
|
| 74 | - protected $acceptableContentTypes; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Get the custom parameters. |
|
| 78 | - * |
|
| 79 | - * \Syscodes\Components\Http\Utilities\Parameters $attributes |
|
| 80 | - */ |
|
| 81 | - public $attributes; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * The base URL. |
|
| 85 | - * |
|
| 86 | - * @var string $baseUrl |
|
| 87 | - */ |
|
| 88 | - protected $baseUrl; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Get the client ip. |
|
| 92 | - * |
|
| 93 | - * @var mixed $clientIp |
|
| 94 | - */ |
|
| 95 | - protected $clientIp; |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Gets cookies ($_COOKIE). |
|
| 99 | - * |
|
| 100 | - * @var \Syscodes\Components\Http\Utilities\Inputs $cookies |
|
| 101 | - */ |
|
| 102 | - public $cookies; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Gets the string with format JSON. |
|
| 106 | - * |
|
| 107 | - * @var string|resource|object|null $content |
|
| 108 | - */ |
|
| 109 | - protected $content; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * The default Locale this request. |
|
| 113 | - * |
|
| 114 | - * @var string $defaultLocale |
|
| 115 | - */ |
|
| 116 | - protected $defaultLocale = 'en'; |
|
| 50 | + use CanBePrecognitive, |
|
| 51 | + HttpResources, |
|
| 52 | + InteractsWithInput, |
|
| 53 | + InteractsWithContentTypes; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Get the http method parameter. |
|
| 57 | + * |
|
| 58 | + * @var bool $httpMethodParameterOverride |
|
| 59 | + */ |
|
| 60 | + protected static $httpMethodParameterOverride = false; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Holds the global active request instance. |
|
| 64 | + * |
|
| 65 | + * @var bool $requestURI |
|
| 66 | + */ |
|
| 67 | + protected static $requestURI; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Get the acceptable of content types. |
|
| 71 | + * |
|
| 72 | + * @var string[] $acceptableContenTypes |
|
| 73 | + */ |
|
| 74 | + protected $acceptableContentTypes; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Get the custom parameters. |
|
| 78 | + * |
|
| 79 | + * \Syscodes\Components\Http\Utilities\Parameters $attributes |
|
| 80 | + */ |
|
| 81 | + public $attributes; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * The base URL. |
|
| 85 | + * |
|
| 86 | + * @var string $baseUrl |
|
| 87 | + */ |
|
| 88 | + protected $baseUrl; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Get the client ip. |
|
| 92 | + * |
|
| 93 | + * @var mixed $clientIp |
|
| 94 | + */ |
|
| 95 | + protected $clientIp; |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Gets cookies ($_COOKIE). |
|
| 99 | + * |
|
| 100 | + * @var \Syscodes\Components\Http\Utilities\Inputs $cookies |
|
| 101 | + */ |
|
| 102 | + public $cookies; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Gets the string with format JSON. |
|
| 106 | + * |
|
| 107 | + * @var string|resource|object|null $content |
|
| 108 | + */ |
|
| 109 | + protected $content; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * The default Locale this request. |
|
| 113 | + * |
|
| 114 | + * @var string $defaultLocale |
|
| 115 | + */ |
|
| 116 | + protected $defaultLocale = 'en'; |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Gets files request ($_FILES). |
|
| 120 | - * |
|
| 121 | - * @var \Syscodes\Components\Http\Utilities\Files $files |
|
| 122 | - */ |
|
| 123 | - public $files; |
|
| 118 | + /** |
|
| 119 | + * Gets files request ($_FILES). |
|
| 120 | + * |
|
| 121 | + * @var \Syscodes\Components\Http\Utilities\Files $files |
|
| 122 | + */ |
|
| 123 | + public $files; |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Get the headers request ($_SERVER). |
|
| 127 | - * |
|
| 128 | - * @var \Syscodes\Components\Http\Utilities\Headers $headers |
|
| 129 | - */ |
|
| 130 | - public $headers; |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * The decoded JSON content for the request. |
|
| 134 | - * |
|
| 135 | - * @var \Syscodes\Components\Http\Utilities\Parameters|null $json |
|
| 136 | - */ |
|
| 137 | - protected $json; |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * The current language of the application. |
|
| 141 | - * |
|
| 142 | - * @var string $languages |
|
| 143 | - */ |
|
| 144 | - protected $languages; |
|
| 125 | + /** |
|
| 126 | + * Get the headers request ($_SERVER). |
|
| 127 | + * |
|
| 128 | + * @var \Syscodes\Components\Http\Utilities\Headers $headers |
|
| 129 | + */ |
|
| 130 | + public $headers; |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * The decoded JSON content for the request. |
|
| 134 | + * |
|
| 135 | + * @var \Syscodes\Components\Http\Utilities\Parameters|null $json |
|
| 136 | + */ |
|
| 137 | + protected $json; |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * The current language of the application. |
|
| 141 | + * |
|
| 142 | + * @var string $languages |
|
| 143 | + */ |
|
| 144 | + protected $languages; |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Get the locale. |
|
| 148 | - * |
|
| 149 | - * @var string $locale |
|
| 150 | - */ |
|
| 151 | - protected $locale; |
|
| 146 | + /** |
|
| 147 | + * Get the locale. |
|
| 148 | + * |
|
| 149 | + * @var string $locale |
|
| 150 | + */ |
|
| 151 | + protected $locale; |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * The method name. |
|
| 155 | - * |
|
| 156 | - * @var string $method |
|
| 157 | - */ |
|
| 158 | - protected $method; |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * The path info of URL. |
|
| 162 | - * |
|
| 163 | - * @var string $pathInfo |
|
| 164 | - */ |
|
| 165 | - protected $pathInfo; |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Query string parameters ($_GET). |
|
| 169 | - * |
|
| 170 | - * @var \Syscodes\Components\Http\Utilities\Parameters $query |
|
| 171 | - */ |
|
| 172 | - public $query; |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Request body parameters ($_POST). |
|
| 176 | - * |
|
| 177 | - * @var \Syscodes\Components\Http\Utilities\Parameters $request |
|
| 178 | - */ |
|
| 179 | - public $request; |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get request URI. |
|
| 183 | - * |
|
| 184 | - * @var string $requestToUri |
|
| 185 | - */ |
|
| 186 | - protected $requestToUri; |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Get the route resolver callback. |
|
| 190 | - * |
|
| 191 | - * @var \Closure $routeResolver |
|
| 192 | - */ |
|
| 193 | - protected $routeResolver; |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * The Session implementation. |
|
| 197 | - * |
|
| 198 | - * @var \Syscodes\Components\Contracts\Session\Session $session |
|
| 199 | - */ |
|
| 200 | - protected $session; |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * The detected uri and server variables ($_SERVER). |
|
| 204 | - * |
|
| 205 | - * @var \Syscodes\Components\Http\Utilities\Server $server |
|
| 206 | - */ |
|
| 207 | - public $server; |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * List of routes uri. |
|
| 211 | - * |
|
| 212 | - * @var string|array|object $uri |
|
| 213 | - */ |
|
| 214 | - public $uri; |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Stores the valid locale codes. |
|
| 218 | - * |
|
| 219 | - * @var array $validLocales |
|
| 220 | - */ |
|
| 221 | - protected $validLocales = []; |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Constructor: Create new the Request class. |
|
| 225 | - * |
|
| 226 | - * @param array $query |
|
| 227 | - * @param array $request |
|
| 228 | - * @param array $attributes |
|
| 229 | - * @param array $cookies |
|
| 230 | - * @param array $files |
|
| 231 | - * @param array $server |
|
| 232 | - * @param string|resource|null $content |
|
| 233 | - * |
|
| 234 | - * @return void |
|
| 235 | - */ |
|
| 236 | - public function __construct( |
|
| 237 | - array $query = [], |
|
| 238 | - array $request = [], |
|
| 239 | - array $attributes = [], |
|
| 240 | - array $cookies = [], |
|
| 241 | - array $files = [], |
|
| 242 | - array $server = [], |
|
| 243 | - $content = null |
|
| 244 | - ) { |
|
| 245 | - $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content); |
|
| 153 | + /** |
|
| 154 | + * The method name. |
|
| 155 | + * |
|
| 156 | + * @var string $method |
|
| 157 | + */ |
|
| 158 | + protected $method; |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * The path info of URL. |
|
| 162 | + * |
|
| 163 | + * @var string $pathInfo |
|
| 164 | + */ |
|
| 165 | + protected $pathInfo; |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Query string parameters ($_GET). |
|
| 169 | + * |
|
| 170 | + * @var \Syscodes\Components\Http\Utilities\Parameters $query |
|
| 171 | + */ |
|
| 172 | + public $query; |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Request body parameters ($_POST). |
|
| 176 | + * |
|
| 177 | + * @var \Syscodes\Components\Http\Utilities\Parameters $request |
|
| 178 | + */ |
|
| 179 | + public $request; |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get request URI. |
|
| 183 | + * |
|
| 184 | + * @var string $requestToUri |
|
| 185 | + */ |
|
| 186 | + protected $requestToUri; |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Get the route resolver callback. |
|
| 190 | + * |
|
| 191 | + * @var \Closure $routeResolver |
|
| 192 | + */ |
|
| 193 | + protected $routeResolver; |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * The Session implementation. |
|
| 197 | + * |
|
| 198 | + * @var \Syscodes\Components\Contracts\Session\Session $session |
|
| 199 | + */ |
|
| 200 | + protected $session; |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * The detected uri and server variables ($_SERVER). |
|
| 204 | + * |
|
| 205 | + * @var \Syscodes\Components\Http\Utilities\Server $server |
|
| 206 | + */ |
|
| 207 | + public $server; |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * List of routes uri. |
|
| 211 | + * |
|
| 212 | + * @var string|array|object $uri |
|
| 213 | + */ |
|
| 214 | + public $uri; |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Stores the valid locale codes. |
|
| 218 | + * |
|
| 219 | + * @var array $validLocales |
|
| 220 | + */ |
|
| 221 | + protected $validLocales = []; |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Constructor: Create new the Request class. |
|
| 225 | + * |
|
| 226 | + * @param array $query |
|
| 227 | + * @param array $request |
|
| 228 | + * @param array $attributes |
|
| 229 | + * @param array $cookies |
|
| 230 | + * @param array $files |
|
| 231 | + * @param array $server |
|
| 232 | + * @param string|resource|null $content |
|
| 233 | + * |
|
| 234 | + * @return void |
|
| 235 | + */ |
|
| 236 | + public function __construct( |
|
| 237 | + array $query = [], |
|
| 238 | + array $request = [], |
|
| 239 | + array $attributes = [], |
|
| 240 | + array $cookies = [], |
|
| 241 | + array $files = [], |
|
| 242 | + array $server = [], |
|
| 243 | + $content = null |
|
| 244 | + ) { |
|
| 245 | + $this->initialize($query, $request, $attributes, $cookies, $files, $server, $content); |
|
| 246 | 246 | |
| 247 | - $this->detectLocale(); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Sets the parameters for this request. |
|
| 252 | - * |
|
| 253 | - * @param array $query |
|
| 254 | - * @param array $request |
|
| 255 | - * @param array $attributes |
|
| 256 | - * @param array $cookies |
|
| 257 | - * @param array $files |
|
| 258 | - * @param array $server |
|
| 259 | - * |
|
| 260 | - * @return void |
|
| 261 | - */ |
|
| 262 | - public function initialize( |
|
| 263 | - array $query = [], |
|
| 264 | - array $request = [], |
|
| 265 | - array $attributes = [], |
|
| 266 | - array $cookies = [], |
|
| 267 | - array $files = [], |
|
| 268 | - array $server = [], |
|
| 269 | - $content = null |
|
| 270 | - ): void { |
|
| 271 | - $this->query = new Inputs($query); |
|
| 272 | - $this->request = new Inputs($request); |
|
| 273 | - $this->attributes = new Parameters($attributes); |
|
| 274 | - $this->cookies = new Inputs($cookies); |
|
| 275 | - $this->files = new Files($files); |
|
| 276 | - $this->server = new Server($server); |
|
| 277 | - $this->headers = new Headers($this->server->all()); |
|
| 278 | - |
|
| 279 | - // Variables initialized |
|
| 280 | - $this->uri = new URI; |
|
| 281 | - $this->method = null; |
|
| 282 | - $this->baseUrl = null; |
|
| 283 | - $this->content = $content; |
|
| 284 | - $this->pathInfo = null; |
|
| 285 | - $this->languages = null; |
|
| 286 | - $this->acceptableContentTypes = null; |
|
| 287 | - $this->validLocales = config('app.supportedLocales'); |
|
| 288 | - $this->clientIp = new RequestClientIP($this->server->all()); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Create a new Syscodes HTTP request from server variables. |
|
| 293 | - * |
|
| 294 | - * @return static |
|
| 295 | - */ |
|
| 296 | - public static function capture(): static |
|
| 297 | - { |
|
| 298 | - static::enabledHttpMethodParameterOverride(); |
|
| 247 | + $this->detectLocale(); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Sets the parameters for this request. |
|
| 252 | + * |
|
| 253 | + * @param array $query |
|
| 254 | + * @param array $request |
|
| 255 | + * @param array $attributes |
|
| 256 | + * @param array $cookies |
|
| 257 | + * @param array $files |
|
| 258 | + * @param array $server |
|
| 259 | + * |
|
| 260 | + * @return void |
|
| 261 | + */ |
|
| 262 | + public function initialize( |
|
| 263 | + array $query = [], |
|
| 264 | + array $request = [], |
|
| 265 | + array $attributes = [], |
|
| 266 | + array $cookies = [], |
|
| 267 | + array $files = [], |
|
| 268 | + array $server = [], |
|
| 269 | + $content = null |
|
| 270 | + ): void { |
|
| 271 | + $this->query = new Inputs($query); |
|
| 272 | + $this->request = new Inputs($request); |
|
| 273 | + $this->attributes = new Parameters($attributes); |
|
| 274 | + $this->cookies = new Inputs($cookies); |
|
| 275 | + $this->files = new Files($files); |
|
| 276 | + $this->server = new Server($server); |
|
| 277 | + $this->headers = new Headers($this->server->all()); |
|
| 278 | + |
|
| 279 | + // Variables initialized |
|
| 280 | + $this->uri = new URI; |
|
| 281 | + $this->method = null; |
|
| 282 | + $this->baseUrl = null; |
|
| 283 | + $this->content = $content; |
|
| 284 | + $this->pathInfo = null; |
|
| 285 | + $this->languages = null; |
|
| 286 | + $this->acceptableContentTypes = null; |
|
| 287 | + $this->validLocales = config('app.supportedLocales'); |
|
| 288 | + $this->clientIp = new RequestClientIP($this->server->all()); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Create a new Syscodes HTTP request from server variables. |
|
| 293 | + * |
|
| 294 | + * @return static |
|
| 295 | + */ |
|
| 296 | + public static function capture(): static |
|
| 297 | + { |
|
| 298 | + static::enabledHttpMethodParameterOverride(); |
|
| 299 | 299 | |
| 300 | - return static::createFromRequest(static::createFromRequestGlobals()); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Creates an Syscodes request from of the Request class instance. |
|
| 305 | - * |
|
| 306 | - * @param \Syscodes\Components\Http\Request $request |
|
| 307 | - * |
|
| 308 | - * @return static |
|
| 309 | - */ |
|
| 310 | - public static function createFromRequest(Request $request): static |
|
| 311 | - { |
|
| 312 | - $newRequest = (new static)->duplicate( |
|
| 313 | - $request->query->all(), $request->request->all(), $request->attributes->all(), |
|
| 314 | - $request->cookies->all(), $request->files->all(), $request->server->all() |
|
| 315 | - ); |
|
| 300 | + return static::createFromRequest(static::createFromRequestGlobals()); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Creates an Syscodes request from of the Request class instance. |
|
| 305 | + * |
|
| 306 | + * @param \Syscodes\Components\Http\Request $request |
|
| 307 | + * |
|
| 308 | + * @return static |
|
| 309 | + */ |
|
| 310 | + public static function createFromRequest(Request $request): static |
|
| 311 | + { |
|
| 312 | + $newRequest = (new static)->duplicate( |
|
| 313 | + $request->query->all(), $request->request->all(), $request->attributes->all(), |
|
| 314 | + $request->cookies->all(), $request->files->all(), $request->server->all() |
|
| 315 | + ); |
|
| 316 | 316 | |
| 317 | - $newRequest->headers->replace($request->headers->all()); |
|
| 317 | + $newRequest->headers->replace($request->headers->all()); |
|
| 318 | 318 | |
| 319 | - $newRequest->content = $request->content; |
|
| 319 | + $newRequest->content = $request->content; |
|
| 320 | 320 | |
| 321 | - if ($newRequest->isJson()) { |
|
| 322 | - $newRequest->request = $newRequest->json(); |
|
| 323 | - } |
|
| 321 | + if ($newRequest->isJson()) { |
|
| 322 | + $newRequest->request = $newRequest->json(); |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - return $newRequest; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Creates a new request with value from PHP's super global. |
|
| 330 | - * |
|
| 331 | - * @return static |
|
| 332 | - */ |
|
| 333 | - public static function createFromRequestGlobals(): static |
|
| 334 | - { |
|
| 335 | - $request = static::createFromRequestFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER); |
|
| 336 | - |
|
| 337 | - if (Str::startsWith($request->headers->get('CONTENT_TYPE', ''), 'application/x-www-form-urlencoded') |
|
| 338 | - && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])) { |
|
| 339 | - parse_str($request->getContent(), $data); |
|
| 340 | - $request->request = new Inputs($data); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return $request; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Creates a new request from a factory. |
|
| 348 | - * |
|
| 349 | - * @param array $query |
|
| 350 | - * @param array $request |
|
| 351 | - * @param array $attributes |
|
| 352 | - * @param array $cookies |
|
| 353 | - * @param array $files |
|
| 354 | - * @param array $server |
|
| 355 | - * |
|
| 356 | - * @return static |
|
| 357 | - */ |
|
| 358 | - private static function createFromRequestFactory( |
|
| 359 | - array $query = [], |
|
| 360 | - array $request = [], |
|
| 361 | - array $attributes = [] , |
|
| 362 | - array $cookies = [], |
|
| 363 | - array $files = [], |
|
| 364 | - array $server = [] |
|
| 365 | - ): static { |
|
| 366 | - if (self::$requestURI) { |
|
| 367 | - $request = (self::$requestURI)($query, $request, [], $cookies, $files, $server); |
|
| 368 | - |
|
| 369 | - if ( ! $request instanceof self) { |
|
| 370 | - throw new LogicException('The Request active must return an instance of Syscodes\Components\Http\Request'); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - return $request; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - return new static($query, $request, $attributes, $cookies, $files, $server); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Clones a request and overrides some of its parameters. |
|
| 381 | - * |
|
| 382 | - * @param array|null $query |
|
| 383 | - * @param array|null $request |
|
| 384 | - * @param array|null $attributes |
|
| 385 | - * @param array|null $cookies |
|
| 386 | - * @param array|null $files |
|
| 387 | - * @param array|null $server |
|
| 388 | - * |
|
| 389 | - * @return static |
|
| 390 | - */ |
|
| 391 | - public function duplicate( |
|
| 392 | - array $query = null, |
|
| 393 | - array $request = null, |
|
| 394 | - array $attributes = null, |
|
| 395 | - array $cookies = null, |
|
| 396 | - array $files = null, |
|
| 397 | - array $server = null |
|
| 398 | - ): static { |
|
| 399 | - $duplicate = clone $this; |
|
| 400 | - |
|
| 401 | - if (null !== $query) { |
|
| 402 | - $duplicate->query = new Inputs($query); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - if (null !== $request) { |
|
| 406 | - $duplicate->request = new Inputs($request); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - if (null !== $attributes) { |
|
| 410 | - $duplicate->attributes = new Parameters($attributes); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - if (null !== $cookies) { |
|
| 414 | - $duplicate->cookies = new Inputs($cookies); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - if (null !== $files) { |
|
| 418 | - $duplicate->files = new Files($files); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - if (null !== $server) { |
|
| 422 | - $duplicate->server = new Server($server); |
|
| 423 | - $duplicate->headers = new Headers($duplicate->server->all()); |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - $duplicate->uri = new URI; |
|
| 427 | - $duplicate->locale = null; |
|
| 428 | - $duplicate->method = null; |
|
| 429 | - $duplicate->baseUrl = null; |
|
| 430 | - $duplicate->pathInfo = null; |
|
| 431 | - $duplicate->validLocales = config('app.supportedLocales'); |
|
| 432 | - $duplicate->clientIp = new RequestClientIP($duplicate->server->all()); |
|
| 433 | - |
|
| 434 | - return $duplicate; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Returns the factory request currently being used. |
|
| 439 | - * |
|
| 440 | - * @param \Syscodes\Components\Http\Request|callable|null $request |
|
| 441 | - * |
|
| 442 | - * @return void |
|
| 443 | - */ |
|
| 444 | - public static function setFactory(?callable $request): void |
|
| 445 | - { |
|
| 446 | - self::$requestURI = $request; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Returns the desired segment, or $default if it does not exist. |
|
| 451 | - * |
|
| 452 | - * @param int $index The segment number (1-based index) |
|
| 453 | - * @param mixed $default Default value to return |
|
| 454 | - * |
|
| 455 | - * @return string |
|
| 456 | - */ |
|
| 457 | - public function segment($index, $default = null) |
|
| 458 | - { |
|
| 459 | - return $this->uri->getSegment($index, $default); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * Returns all segments in an array. For total of segments |
|
| 464 | - * used the function PHP count(). |
|
| 465 | - * |
|
| 466 | - * @return array|null |
|
| 467 | - */ |
|
| 468 | - public function segments() |
|
| 469 | - { |
|
| 470 | - return $this->uri->getSegments(); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Returns the total number of segment. |
|
| 475 | - * |
|
| 476 | - * @return int|null |
|
| 477 | - */ |
|
| 478 | - public function totalSegments() |
|
| 479 | - { |
|
| 480 | - return $this->uri->getTotalSegments(); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Handles setting up the locale, auto-detecting of language. |
|
| 485 | - * |
|
| 486 | - * @return void |
|
| 487 | - */ |
|
| 488 | - public function detectLocale(): void |
|
| 489 | - { |
|
| 490 | - $this->languages = $this->defaultLocale = config('app.locale'); |
|
| 491 | - |
|
| 492 | - $this->setLocale($this->validLocales[0]); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Returns the default locale as set. |
|
| 497 | - * |
|
| 498 | - * @return string |
|
| 499 | - */ |
|
| 500 | - public function getDefaultLocale(): string |
|
| 501 | - { |
|
| 502 | - return $this->defaultLocale; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Gets the current locale, with a fallback to the default. |
|
| 507 | - * |
|
| 508 | - * @return string |
|
| 509 | - */ |
|
| 510 | - public function getLocale(): string |
|
| 511 | - { |
|
| 512 | - return $this->languages ?? $this->defaultLocale; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Sets the locale string for this request. |
|
| 517 | - * |
|
| 518 | - * @param string $locale |
|
| 519 | - * |
|
| 520 | - * @return static |
|
| 521 | - */ |
|
| 522 | - public function setLocale(string $locale): static |
|
| 523 | - { |
|
| 524 | - if ( ! in_array($locale, $this->validLocales, true)) { |
|
| 525 | - $locale = $this->defaultLocale; |
|
| 526 | - } |
|
| 325 | + return $newRequest; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Creates a new request with value from PHP's super global. |
|
| 330 | + * |
|
| 331 | + * @return static |
|
| 332 | + */ |
|
| 333 | + public static function createFromRequestGlobals(): static |
|
| 334 | + { |
|
| 335 | + $request = static::createFromRequestFactory($_GET, $_POST, [], $_COOKIE, $_FILES, $_SERVER); |
|
| 336 | + |
|
| 337 | + if (Str::startsWith($request->headers->get('CONTENT_TYPE', ''), 'application/x-www-form-urlencoded') |
|
| 338 | + && in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])) { |
|
| 339 | + parse_str($request->getContent(), $data); |
|
| 340 | + $request->request = new Inputs($data); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return $request; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Creates a new request from a factory. |
|
| 348 | + * |
|
| 349 | + * @param array $query |
|
| 350 | + * @param array $request |
|
| 351 | + * @param array $attributes |
|
| 352 | + * @param array $cookies |
|
| 353 | + * @param array $files |
|
| 354 | + * @param array $server |
|
| 355 | + * |
|
| 356 | + * @return static |
|
| 357 | + */ |
|
| 358 | + private static function createFromRequestFactory( |
|
| 359 | + array $query = [], |
|
| 360 | + array $request = [], |
|
| 361 | + array $attributes = [] , |
|
| 362 | + array $cookies = [], |
|
| 363 | + array $files = [], |
|
| 364 | + array $server = [] |
|
| 365 | + ): static { |
|
| 366 | + if (self::$requestURI) { |
|
| 367 | + $request = (self::$requestURI)($query, $request, [], $cookies, $files, $server); |
|
| 368 | + |
|
| 369 | + if ( ! $request instanceof self) { |
|
| 370 | + throw new LogicException('The Request active must return an instance of Syscodes\Components\Http\Request'); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + return $request; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + return new static($query, $request, $attributes, $cookies, $files, $server); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Clones a request and overrides some of its parameters. |
|
| 381 | + * |
|
| 382 | + * @param array|null $query |
|
| 383 | + * @param array|null $request |
|
| 384 | + * @param array|null $attributes |
|
| 385 | + * @param array|null $cookies |
|
| 386 | + * @param array|null $files |
|
| 387 | + * @param array|null $server |
|
| 388 | + * |
|
| 389 | + * @return static |
|
| 390 | + */ |
|
| 391 | + public function duplicate( |
|
| 392 | + array $query = null, |
|
| 393 | + array $request = null, |
|
| 394 | + array $attributes = null, |
|
| 395 | + array $cookies = null, |
|
| 396 | + array $files = null, |
|
| 397 | + array $server = null |
|
| 398 | + ): static { |
|
| 399 | + $duplicate = clone $this; |
|
| 400 | + |
|
| 401 | + if (null !== $query) { |
|
| 402 | + $duplicate->query = new Inputs($query); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + if (null !== $request) { |
|
| 406 | + $duplicate->request = new Inputs($request); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + if (null !== $attributes) { |
|
| 410 | + $duplicate->attributes = new Parameters($attributes); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + if (null !== $cookies) { |
|
| 414 | + $duplicate->cookies = new Inputs($cookies); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + if (null !== $files) { |
|
| 418 | + $duplicate->files = new Files($files); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + if (null !== $server) { |
|
| 422 | + $duplicate->server = new Server($server); |
|
| 423 | + $duplicate->headers = new Headers($duplicate->server->all()); |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + $duplicate->uri = new URI; |
|
| 427 | + $duplicate->locale = null; |
|
| 428 | + $duplicate->method = null; |
|
| 429 | + $duplicate->baseUrl = null; |
|
| 430 | + $duplicate->pathInfo = null; |
|
| 431 | + $duplicate->validLocales = config('app.supportedLocales'); |
|
| 432 | + $duplicate->clientIp = new RequestClientIP($duplicate->server->all()); |
|
| 433 | + |
|
| 434 | + return $duplicate; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Returns the factory request currently being used. |
|
| 439 | + * |
|
| 440 | + * @param \Syscodes\Components\Http\Request|callable|null $request |
|
| 441 | + * |
|
| 442 | + * @return void |
|
| 443 | + */ |
|
| 444 | + public static function setFactory(?callable $request): void |
|
| 445 | + { |
|
| 446 | + self::$requestURI = $request; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * Returns the desired segment, or $default if it does not exist. |
|
| 451 | + * |
|
| 452 | + * @param int $index The segment number (1-based index) |
|
| 453 | + * @param mixed $default Default value to return |
|
| 454 | + * |
|
| 455 | + * @return string |
|
| 456 | + */ |
|
| 457 | + public function segment($index, $default = null) |
|
| 458 | + { |
|
| 459 | + return $this->uri->getSegment($index, $default); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Returns all segments in an array. For total of segments |
|
| 464 | + * used the function PHP count(). |
|
| 465 | + * |
|
| 466 | + * @return array|null |
|
| 467 | + */ |
|
| 468 | + public function segments() |
|
| 469 | + { |
|
| 470 | + return $this->uri->getSegments(); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Returns the total number of segment. |
|
| 475 | + * |
|
| 476 | + * @return int|null |
|
| 477 | + */ |
|
| 478 | + public function totalSegments() |
|
| 479 | + { |
|
| 480 | + return $this->uri->getTotalSegments(); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Handles setting up the locale, auto-detecting of language. |
|
| 485 | + * |
|
| 486 | + * @return void |
|
| 487 | + */ |
|
| 488 | + public function detectLocale(): void |
|
| 489 | + { |
|
| 490 | + $this->languages = $this->defaultLocale = config('app.locale'); |
|
| 491 | + |
|
| 492 | + $this->setLocale($this->validLocales[0]); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Returns the default locale as set. |
|
| 497 | + * |
|
| 498 | + * @return string |
|
| 499 | + */ |
|
| 500 | + public function getDefaultLocale(): string |
|
| 501 | + { |
|
| 502 | + return $this->defaultLocale; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Gets the current locale, with a fallback to the default. |
|
| 507 | + * |
|
| 508 | + * @return string |
|
| 509 | + */ |
|
| 510 | + public function getLocale(): string |
|
| 511 | + { |
|
| 512 | + return $this->languages ?? $this->defaultLocale; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Sets the locale string for this request. |
|
| 517 | + * |
|
| 518 | + * @param string $locale |
|
| 519 | + * |
|
| 520 | + * @return static |
|
| 521 | + */ |
|
| 522 | + public function setLocale(string $locale): static |
|
| 523 | + { |
|
| 524 | + if ( ! in_array($locale, $this->validLocales, true)) { |
|
| 525 | + $locale = $this->defaultLocale; |
|
| 526 | + } |
|
| 527 | 527 | |
| 528 | - $this->languages = $locale; |
|
| 528 | + $this->languages = $locale; |
|
| 529 | 529 | |
| 530 | - Locale::setDefault($locale); |
|
| 530 | + Locale::setDefault($locale); |
|
| 531 | 531 | |
| 532 | - return $this; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * Returns the full request string. |
|
| 537 | - * |
|
| 538 | - * @param string $key |
|
| 539 | - * @param mixed $default |
|
| 540 | - * |
|
| 541 | - * @return mixed |
|
| 542 | - */ |
|
| 543 | - public function get(string $key, $default = null) |
|
| 544 | - { |
|
| 545 | - if ($this !== $result = $this->attributes->get($key, $this)) { |
|
| 546 | - return $result; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - if ($this->query->has($key)) { |
|
| 550 | - return $this->query->all()[$key]; |
|
| 551 | - } |
|
| 532 | + return $this; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * Returns the full request string. |
|
| 537 | + * |
|
| 538 | + * @param string $key |
|
| 539 | + * @param mixed $default |
|
| 540 | + * |
|
| 541 | + * @return mixed |
|
| 542 | + */ |
|
| 543 | + public function get(string $key, $default = null) |
|
| 544 | + { |
|
| 545 | + if ($this !== $result = $this->attributes->get($key, $this)) { |
|
| 546 | + return $result; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + if ($this->query->has($key)) { |
|
| 550 | + return $this->query->all()[$key]; |
|
| 551 | + } |
|
| 552 | 552 | |
| 553 | - if ($this->request->has($key)) { |
|
| 554 | - return $this->request->all()[$key]; |
|
| 555 | - } |
|
| 553 | + if ($this->request->has($key)) { |
|
| 554 | + return $this->request->all()[$key]; |
|
| 555 | + } |
|
| 556 | 556 | |
| 557 | - return $default; |
|
| 558 | - } |
|
| 557 | + return $default; |
|
| 558 | + } |
|
| 559 | 559 | |
| 560 | - /** |
|
| 560 | + /** |
|
| 561 | 561 | * Enables support for the _method request parameter to determine the intended HTTP method. |
| 562 | 562 | * |
| 563 | 563 | * @return void |
@@ -567,675 +567,675 @@ discard block |
||
| 567 | 567 | self::$httpMethodParameterOverride = true; |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | - /** |
|
| 571 | - * Checks whether support for the _method request parameter is enabled. |
|
| 572 | - * |
|
| 573 | - * @return bool |
|
| 574 | - */ |
|
| 575 | - public static function getHttpMethodParameterOverride(): bool |
|
| 576 | - { |
|
| 577 | - return self::$httpMethodParameterOverride; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Gets the Session. |
|
| 582 | - * |
|
| 583 | - * @return \Syscodes\Components\Http\Session\SessionInterface |
|
| 584 | - * |
|
| 585 | - * @throws \Syscodes\Components\Http\Exceptions\SessionNotFoundException |
|
| 586 | - */ |
|
| 587 | - public function getSession() |
|
| 588 | - { |
|
| 589 | - $this->hasSession() |
|
| 590 | - ? new SessionDecorator($this->session()) |
|
| 591 | - : throw new SessionNotFoundException; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * Whether the request contains a Session object. |
|
| 596 | - * |
|
| 597 | - * @return bool |
|
| 598 | - */ |
|
| 599 | - public function hasSession(): bool |
|
| 600 | - { |
|
| 601 | - return ! is_null($this->session); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * Get the session associated with the request. |
|
| 606 | - * |
|
| 607 | - * @return \Syscodes\Components\Contracts\Session\Session |
|
| 608 | - * |
|
| 609 | - * @throws RuntimeException |
|
| 610 | - */ |
|
| 611 | - public function session() |
|
| 612 | - { |
|
| 613 | - if ( ! $this->hasSession()) { |
|
| 614 | - throw new RuntimeException('Session store not set on request'); |
|
| 615 | - } |
|
| 570 | + /** |
|
| 571 | + * Checks whether support for the _method request parameter is enabled. |
|
| 572 | + * |
|
| 573 | + * @return bool |
|
| 574 | + */ |
|
| 575 | + public static function getHttpMethodParameterOverride(): bool |
|
| 576 | + { |
|
| 577 | + return self::$httpMethodParameterOverride; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Gets the Session. |
|
| 582 | + * |
|
| 583 | + * @return \Syscodes\Components\Http\Session\SessionInterface |
|
| 584 | + * |
|
| 585 | + * @throws \Syscodes\Components\Http\Exceptions\SessionNotFoundException |
|
| 586 | + */ |
|
| 587 | + public function getSession() |
|
| 588 | + { |
|
| 589 | + $this->hasSession() |
|
| 590 | + ? new SessionDecorator($this->session()) |
|
| 591 | + : throw new SessionNotFoundException; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * Whether the request contains a Session object. |
|
| 596 | + * |
|
| 597 | + * @return bool |
|
| 598 | + */ |
|
| 599 | + public function hasSession(): bool |
|
| 600 | + { |
|
| 601 | + return ! is_null($this->session); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * Get the session associated with the request. |
|
| 606 | + * |
|
| 607 | + * @return \Syscodes\Components\Contracts\Session\Session |
|
| 608 | + * |
|
| 609 | + * @throws RuntimeException |
|
| 610 | + */ |
|
| 611 | + public function session() |
|
| 612 | + { |
|
| 613 | + if ( ! $this->hasSession()) { |
|
| 614 | + throw new RuntimeException('Session store not set on request'); |
|
| 615 | + } |
|
| 616 | 616 | |
| 617 | - return $this->session; |
|
| 618 | - } |
|
| 617 | + return $this->session; |
|
| 618 | + } |
|
| 619 | 619 | |
| 620 | - /** |
|
| 621 | - * Set the session instance on the request. |
|
| 622 | - * |
|
| 623 | - * @param \Syscodes\Components\Contracts\Session\Session $session |
|
| 624 | - * |
|
| 625 | - * @return void |
|
| 626 | - */ |
|
| 627 | - public function setSession($session): void |
|
| 628 | - { |
|
| 629 | - $this->session = $session; |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Get the JSON payload for the request. |
|
| 634 | - * |
|
| 635 | - * @param string|null $key |
|
| 636 | - * @param mixed $default |
|
| 637 | - * |
|
| 638 | - * @return \Syscodes\Components\Http\Utilities\Parameters|mixed |
|
| 639 | - */ |
|
| 640 | - public function json($key = null, $default = null) |
|
| 641 | - { |
|
| 642 | - if ( ! isset($this->json)) { |
|
| 643 | - $this->json = new Parameters((array) json_decode($this->getContent(), true)); |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - if (is_null($key)) { |
|
| 647 | - return $this->json; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - return Arr::get($this->json->all(), $key, $default); |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * Set the JSON payload for the request. |
|
| 655 | - * |
|
| 656 | - * @param \Syscodes\Components\Http\Utilities\Parameters $json |
|
| 657 | - * |
|
| 658 | - * @return static |
|
| 659 | - */ |
|
| 660 | - public function setJson($json): static |
|
| 661 | - { |
|
| 662 | - $this->json = $json; |
|
| 663 | - |
|
| 664 | - return $this; |
|
| 665 | - } |
|
| 620 | + /** |
|
| 621 | + * Set the session instance on the request. |
|
| 622 | + * |
|
| 623 | + * @param \Syscodes\Components\Contracts\Session\Session $session |
|
| 624 | + * |
|
| 625 | + * @return void |
|
| 626 | + */ |
|
| 627 | + public function setSession($session): void |
|
| 628 | + { |
|
| 629 | + $this->session = $session; |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Get the JSON payload for the request. |
|
| 634 | + * |
|
| 635 | + * @param string|null $key |
|
| 636 | + * @param mixed $default |
|
| 637 | + * |
|
| 638 | + * @return \Syscodes\Components\Http\Utilities\Parameters|mixed |
|
| 639 | + */ |
|
| 640 | + public function json($key = null, $default = null) |
|
| 641 | + { |
|
| 642 | + if ( ! isset($this->json)) { |
|
| 643 | + $this->json = new Parameters((array) json_decode($this->getContent(), true)); |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + if (is_null($key)) { |
|
| 647 | + return $this->json; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + return Arr::get($this->json->all(), $key, $default); |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * Set the JSON payload for the request. |
|
| 655 | + * |
|
| 656 | + * @param \Syscodes\Components\Http\Utilities\Parameters $json |
|
| 657 | + * |
|
| 658 | + * @return static |
|
| 659 | + */ |
|
| 660 | + public function setJson($json): static |
|
| 661 | + { |
|
| 662 | + $this->json = $json; |
|
| 663 | + |
|
| 664 | + return $this; |
|
| 665 | + } |
|
| 666 | 666 | |
| 667 | - /** |
|
| 668 | - * Gets a list of content types acceptable by the client browser in preferable order. |
|
| 669 | - * |
|
| 670 | - * @return string[] |
|
| 671 | - */ |
|
| 672 | - public function getAcceptableContentTypes(): array |
|
| 673 | - { |
|
| 674 | - if (null !== $this->acceptableContentTypes) { |
|
| 675 | - return $this->acceptableContentTypes; |
|
| 676 | - } |
|
| 667 | + /** |
|
| 668 | + * Gets a list of content types acceptable by the client browser in preferable order. |
|
| 669 | + * |
|
| 670 | + * @return string[] |
|
| 671 | + */ |
|
| 672 | + public function getAcceptableContentTypes(): array |
|
| 673 | + { |
|
| 674 | + if (null !== $this->acceptableContentTypes) { |
|
| 675 | + return $this->acceptableContentTypes; |
|
| 676 | + } |
|
| 677 | 677 | |
| 678 | - return $this->acceptableContentTypes = array_map('strval', [$this->headers->get('Accept')]); |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * Returns whether this is an AJAX request or not. |
|
| 683 | - * Alias of isXmlHttpRequest(). |
|
| 684 | - * |
|
| 685 | - * @return bool |
|
| 686 | - */ |
|
| 687 | - public function ajax(): bool |
|
| 688 | - { |
|
| 689 | - return $this->isXmlHttpRequest(); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - /** |
|
| 693 | - * Returns whether this is an AJAX request or not. |
|
| 694 | - * |
|
| 695 | - * @return bool |
|
| 696 | - */ |
|
| 697 | - public function isXmlHttpRequest(): bool |
|
| 698 | - { |
|
| 699 | - return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && |
|
| 700 | - strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest'; |
|
| 701 | - } |
|
| 678 | + return $this->acceptableContentTypes = array_map('strval', [$this->headers->get('Accept')]); |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * Returns whether this is an AJAX request or not. |
|
| 683 | + * Alias of isXmlHttpRequest(). |
|
| 684 | + * |
|
| 685 | + * @return bool |
|
| 686 | + */ |
|
| 687 | + public function ajax(): bool |
|
| 688 | + { |
|
| 689 | + return $this->isXmlHttpRequest(); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + /** |
|
| 693 | + * Returns whether this is an AJAX request or not. |
|
| 694 | + * |
|
| 695 | + * @return bool |
|
| 696 | + */ |
|
| 697 | + public function isXmlHttpRequest(): bool |
|
| 698 | + { |
|
| 699 | + return ! empty($this->server->get('HTTP_X_REQUESTED_WITH')) && |
|
| 700 | + strtolower($this->server->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest'; |
|
| 701 | + } |
|
| 702 | 702 | |
| 703 | - /** |
|
| 704 | - * Determine if the request is the result of a PJAX call. |
|
| 705 | - * |
|
| 706 | - * @return bool |
|
| 707 | - */ |
|
| 708 | - public function pjax(): bool |
|
| 709 | - { |
|
| 710 | - return $this->headers->get('X-PJAX') == true; |
|
| 711 | - } |
|
| 703 | + /** |
|
| 704 | + * Determine if the request is the result of a PJAX call. |
|
| 705 | + * |
|
| 706 | + * @return bool |
|
| 707 | + */ |
|
| 708 | + public function pjax(): bool |
|
| 709 | + { |
|
| 710 | + return $this->headers->get('X-PJAX') == true; |
|
| 711 | + } |
|
| 712 | 712 | |
| 713 | - /** |
|
| 714 | - * Determine if the request is the result of a prefetch call. |
|
| 715 | - * |
|
| 716 | - * @return bool |
|
| 717 | - */ |
|
| 718 | - public function prefetch(): bool |
|
| 719 | - { |
|
| 720 | - return strcasecmp($this->server->get('HTTP_X_MOZ') ?? '', 'prefetch') === 0 || |
|
| 721 | - strcasecmp($this->headers->get('Purpose') ?? '', 'prefetch') === 0; |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * Checks if the method request is of specified type. |
|
| 726 | - * |
|
| 727 | - * @param string $method |
|
| 728 | - * |
|
| 729 | - * @return bool |
|
| 730 | - */ |
|
| 731 | - public function isMethod(string $method): bool |
|
| 732 | - { |
|
| 733 | - return $this->getMethod() === strtoupper($method); |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - /** |
|
| 737 | - * Returns the input method used (GET, POST, DELETE, etc.). |
|
| 738 | - * |
|
| 739 | - * @return string |
|
| 740 | - * |
|
| 741 | - * @throws \LogicException |
|
| 742 | - */ |
|
| 743 | - public function getmethod(): string |
|
| 744 | - { |
|
| 745 | - if (null !== $this->method) { |
|
| 746 | - return $this->method; |
|
| 747 | - } |
|
| 713 | + /** |
|
| 714 | + * Determine if the request is the result of a prefetch call. |
|
| 715 | + * |
|
| 716 | + * @return bool |
|
| 717 | + */ |
|
| 718 | + public function prefetch(): bool |
|
| 719 | + { |
|
| 720 | + return strcasecmp($this->server->get('HTTP_X_MOZ') ?? '', 'prefetch') === 0 || |
|
| 721 | + strcasecmp($this->headers->get('Purpose') ?? '', 'prefetch') === 0; |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * Checks if the method request is of specified type. |
|
| 726 | + * |
|
| 727 | + * @param string $method |
|
| 728 | + * |
|
| 729 | + * @return bool |
|
| 730 | + */ |
|
| 731 | + public function isMethod(string $method): bool |
|
| 732 | + { |
|
| 733 | + return $this->getMethod() === strtoupper($method); |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + /** |
|
| 737 | + * Returns the input method used (GET, POST, DELETE, etc.). |
|
| 738 | + * |
|
| 739 | + * @return string |
|
| 740 | + * |
|
| 741 | + * @throws \LogicException |
|
| 742 | + */ |
|
| 743 | + public function getmethod(): string |
|
| 744 | + { |
|
| 745 | + if (null !== $this->method) { |
|
| 746 | + return $this->method; |
|
| 747 | + } |
|
| 748 | 748 | |
| 749 | - $this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET')); |
|
| 749 | + $this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET')); |
|
| 750 | 750 | |
| 751 | - if ('POST' !== $this->method) { |
|
| 752 | - return $this->method; |
|
| 753 | - } |
|
| 751 | + if ('POST' !== $this->method) { |
|
| 752 | + return $this->method; |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | - $method = $this->headers->get('X-HTTP-METHOD-OVERRIDE'); |
|
| 755 | + $method = $this->headers->get('X-HTTP-METHOD-OVERRIDE'); |
|
| 756 | 756 | |
| 757 | - if ( ! $method && self::$httpMethodParameterOverride) { |
|
| 758 | - $method = $this->request->get('_method', $this->query->get('_method', 'POST')); |
|
| 759 | - } |
|
| 757 | + if ( ! $method && self::$httpMethodParameterOverride) { |
|
| 758 | + $method = $this->request->get('_method', $this->query->get('_method', 'POST')); |
|
| 759 | + } |
|
| 760 | 760 | |
| 761 | - if ( ! is_string($method)) { |
|
| 762 | - return $this->method; |
|
| 763 | - } |
|
| 761 | + if ( ! is_string($method)) { |
|
| 762 | + return $this->method; |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | - $method = strtoupper($method); |
|
| 765 | + $method = strtoupper($method); |
|
| 766 | 766 | |
| 767 | - if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) { |
|
| 768 | - return $this->method = $method; |
|
| 769 | - } |
|
| 767 | + if (in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) { |
|
| 768 | + return $this->method = $method; |
|
| 769 | + } |
|
| 770 | 770 | |
| 771 | - if ( ! preg_match('/^[A-Z]++$/D', $method)) { |
|
| 772 | - throw new LogicException(sprintf('Invalid method override "%s".', $method)); |
|
| 773 | - } |
|
| 771 | + if ( ! preg_match('/^[A-Z]++$/D', $method)) { |
|
| 772 | + throw new LogicException(sprintf('Invalid method override "%s".', $method)); |
|
| 773 | + } |
|
| 774 | 774 | |
| 775 | - return $this->method = $method; |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * Sets the request method. |
|
| 780 | - * |
|
| 781 | - * @param string $method |
|
| 782 | - * |
|
| 783 | - * @return void |
|
| 784 | - */ |
|
| 785 | - public function setMethod(string $method): void |
|
| 786 | - { |
|
| 787 | - $this->method = null; |
|
| 788 | - |
|
| 789 | - $this->server->set('REQUEST_METHOD', $method); |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - /** |
|
| 793 | - * Get the input source for the request. |
|
| 794 | - * |
|
| 795 | - * @return \Syscodes\Components\Http\Utilities\Parameters |
|
| 796 | - */ |
|
| 797 | - public function getInputSource() |
|
| 798 | - { |
|
| 799 | - if ($this->isJson()) { |
|
| 800 | - return $this->json(); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - return in_array($this->getMethod(), ['GET', 'HEAD']) ? $this->query : $this->request; |
|
| 804 | - } |
|
| 775 | + return $this->method = $method; |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * Sets the request method. |
|
| 780 | + * |
|
| 781 | + * @param string $method |
|
| 782 | + * |
|
| 783 | + * @return void |
|
| 784 | + */ |
|
| 785 | + public function setMethod(string $method): void |
|
| 786 | + { |
|
| 787 | + $this->method = null; |
|
| 788 | + |
|
| 789 | + $this->server->set('REQUEST_METHOD', $method); |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + /** |
|
| 793 | + * Get the input source for the request. |
|
| 794 | + * |
|
| 795 | + * @return \Syscodes\Components\Http\Utilities\Parameters |
|
| 796 | + */ |
|
| 797 | + public function getInputSource() |
|
| 798 | + { |
|
| 799 | + if ($this->isJson()) { |
|
| 800 | + return $this->json(); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + return in_array($this->getMethod(), ['GET', 'HEAD']) ? $this->query : $this->request; |
|
| 804 | + } |
|
| 805 | 805 | |
| 806 | - /** |
|
| 807 | - * Determine if the current request URI matches a pattern. |
|
| 808 | - * |
|
| 809 | - * @param mixed ...$patterns |
|
| 810 | - * |
|
| 811 | - * @return bool |
|
| 812 | - */ |
|
| 813 | - public function is(...$patterns): bool |
|
| 814 | - { |
|
| 815 | - $path = $this->decodedPath(); |
|
| 806 | + /** |
|
| 807 | + * Determine if the current request URI matches a pattern. |
|
| 808 | + * |
|
| 809 | + * @param mixed ...$patterns |
|
| 810 | + * |
|
| 811 | + * @return bool |
|
| 812 | + */ |
|
| 813 | + public function is(...$patterns): bool |
|
| 814 | + { |
|
| 815 | + $path = $this->decodedPath(); |
|
| 816 | 816 | |
| 817 | - foreach ($patterns as $pattern) { |
|
| 818 | - if (Str::is($pattern, $path)) { |
|
| 819 | - return true; |
|
| 820 | - } |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - return false; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - /** |
|
| 827 | - * Determine if the route name matches a given pattern. |
|
| 828 | - * |
|
| 829 | - * @param mixed ...$patterns |
|
| 830 | - * |
|
| 831 | - * @return bool |
|
| 832 | - */ |
|
| 833 | - public function routeIs(...$patterns): bool |
|
| 834 | - { |
|
| 835 | - return $this->route() && $this->route()->is(...$patterns); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * Get the route handling the request. |
|
| 840 | - * |
|
| 841 | - * @param string|null $param |
|
| 842 | - * @param mixed $default |
|
| 843 | - * |
|
| 844 | - * @return \Syscodes\Components\Routing\Route|object|string|null |
|
| 845 | - */ |
|
| 846 | - public function route($param = null, $default = null) |
|
| 847 | - { |
|
| 848 | - $route = call_user_func($this->getRouteResolver()); |
|
| 849 | - |
|
| 850 | - if (is_null($route) || is_null($param)) { |
|
| 851 | - return $route; |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - return $route->parameter($param, $default); |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * Get the current decoded path info for the request. |
|
| 859 | - * |
|
| 860 | - * @return string |
|
| 861 | - */ |
|
| 862 | - public function decodedPath(): string |
|
| 863 | - { |
|
| 864 | - return rawurldecode($this->path()); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - /** |
|
| 868 | - * Get the current path info for the request. |
|
| 869 | - * |
|
| 870 | - * @return string |
|
| 871 | - */ |
|
| 872 | - public function path(): string |
|
| 873 | - { |
|
| 874 | - $path = trim($this->getPathInfo(), '/'); |
|
| 875 | - |
|
| 876 | - return $path == '' ? '/' : $path; |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - /** |
|
| 880 | - * Get the full URL for the request. |
|
| 881 | - * |
|
| 882 | - * @return string |
|
| 883 | - */ |
|
| 884 | - public function fullUrl(): string |
|
| 885 | - { |
|
| 886 | - $query = $this->getQueryString(); |
|
| 817 | + foreach ($patterns as $pattern) { |
|
| 818 | + if (Str::is($pattern, $path)) { |
|
| 819 | + return true; |
|
| 820 | + } |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + return false; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + /** |
|
| 827 | + * Determine if the route name matches a given pattern. |
|
| 828 | + * |
|
| 829 | + * @param mixed ...$patterns |
|
| 830 | + * |
|
| 831 | + * @return bool |
|
| 832 | + */ |
|
| 833 | + public function routeIs(...$patterns): bool |
|
| 834 | + { |
|
| 835 | + return $this->route() && $this->route()->is(...$patterns); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * Get the route handling the request. |
|
| 840 | + * |
|
| 841 | + * @param string|null $param |
|
| 842 | + * @param mixed $default |
|
| 843 | + * |
|
| 844 | + * @return \Syscodes\Components\Routing\Route|object|string|null |
|
| 845 | + */ |
|
| 846 | + public function route($param = null, $default = null) |
|
| 847 | + { |
|
| 848 | + $route = call_user_func($this->getRouteResolver()); |
|
| 849 | + |
|
| 850 | + if (is_null($route) || is_null($param)) { |
|
| 851 | + return $route; |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + return $route->parameter($param, $default); |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * Get the current decoded path info for the request. |
|
| 859 | + * |
|
| 860 | + * @return string |
|
| 861 | + */ |
|
| 862 | + public function decodedPath(): string |
|
| 863 | + { |
|
| 864 | + return rawurldecode($this->path()); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + /** |
|
| 868 | + * Get the current path info for the request. |
|
| 869 | + * |
|
| 870 | + * @return string |
|
| 871 | + */ |
|
| 872 | + public function path(): string |
|
| 873 | + { |
|
| 874 | + $path = trim($this->getPathInfo(), '/'); |
|
| 875 | + |
|
| 876 | + return $path == '' ? '/' : $path; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + /** |
|
| 880 | + * Get the full URL for the request. |
|
| 881 | + * |
|
| 882 | + * @return string |
|
| 883 | + */ |
|
| 884 | + public function fullUrl(): string |
|
| 885 | + { |
|
| 886 | + $query = $this->getQueryString(); |
|
| 887 | 887 | |
| 888 | - $question = $this->getBaseUrl().$this->getPathInfo() === '/' ? '/?' : '?'; |
|
| 888 | + $question = $this->getBaseUrl().$this->getPathInfo() === '/' ? '/?' : '?'; |
|
| 889 | 889 | |
| 890 | - return $query ? $this->url().$question.$query : $this->url(); |
|
| 891 | - } |
|
| 890 | + return $query ? $this->url().$question.$query : $this->url(); |
|
| 891 | + } |
|
| 892 | 892 | |
| 893 | - /** |
|
| 894 | - * Generates the normalized query string for the Request. |
|
| 895 | - * |
|
| 896 | - * @return string |
|
| 897 | - */ |
|
| 898 | - public function getQueryString(): ?string |
|
| 899 | - { |
|
| 900 | - $queryString = RequestUtils::normalizedQueryString($this->server->get('QUERY_STRING')); |
|
| 893 | + /** |
|
| 894 | + * Generates the normalized query string for the Request. |
|
| 895 | + * |
|
| 896 | + * @return string |
|
| 897 | + */ |
|
| 898 | + public function getQueryString(): ?string |
|
| 899 | + { |
|
| 900 | + $queryString = RequestUtils::normalizedQueryString($this->server->get('QUERY_STRING')); |
|
| 901 | 901 | |
| 902 | - return '' === $queryString ? null : $queryString; |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - /** |
|
| 906 | - * Retunrs the request body content. |
|
| 907 | - * |
|
| 908 | - * @return string |
|
| 909 | - */ |
|
| 910 | - public function getContent(): string |
|
| 911 | - { |
|
| 912 | - if (null === $this->content || false === $this->content) { |
|
| 913 | - $this->content = file_get_contents('php://input'); |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - return $this->content; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - /** |
|
| 920 | - * Returns the path being requested relative to the executed script. |
|
| 921 | - * |
|
| 922 | - * @return string |
|
| 923 | - */ |
|
| 924 | - public function getPathInfo(): string |
|
| 925 | - { |
|
| 926 | - if (null === $this->pathInfo) { |
|
| 927 | - $this->pathInfo = $this->parsePathInfo(); |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - return $this->pathInfo; |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - /** |
|
| 934 | - * Returns the root URL from which this request is executed. |
|
| 935 | - * |
|
| 936 | - * @return string |
|
| 937 | - */ |
|
| 938 | - public function getBaseUrl(): string |
|
| 939 | - { |
|
| 940 | - if (null === $this->baseUrl) { |
|
| 941 | - $this->baseUrl = $this->parseBaseUrl(); |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - return $this->baseUrl; |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - /** |
|
| 948 | - * Returns the requested URI. |
|
| 949 | - * |
|
| 950 | - * @return string |
|
| 951 | - */ |
|
| 952 | - public function getRequestUri(): string |
|
| 953 | - { |
|
| 954 | - if (null === $this->requestToUri) { |
|
| 955 | - $this->requestToUri = $this->parseRequestUri(); |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - return $this->requestToUri; |
|
| 959 | - } |
|
| 902 | + return '' === $queryString ? null : $queryString; |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + /** |
|
| 906 | + * Retunrs the request body content. |
|
| 907 | + * |
|
| 908 | + * @return string |
|
| 909 | + */ |
|
| 910 | + public function getContent(): string |
|
| 911 | + { |
|
| 912 | + if (null === $this->content || false === $this->content) { |
|
| 913 | + $this->content = file_get_contents('php://input'); |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + return $this->content; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + /** |
|
| 920 | + * Returns the path being requested relative to the executed script. |
|
| 921 | + * |
|
| 922 | + * @return string |
|
| 923 | + */ |
|
| 924 | + public function getPathInfo(): string |
|
| 925 | + { |
|
| 926 | + if (null === $this->pathInfo) { |
|
| 927 | + $this->pathInfo = $this->parsePathInfo(); |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + return $this->pathInfo; |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + /** |
|
| 934 | + * Returns the root URL from which this request is executed. |
|
| 935 | + * |
|
| 936 | + * @return string |
|
| 937 | + */ |
|
| 938 | + public function getBaseUrl(): string |
|
| 939 | + { |
|
| 940 | + if (null === $this->baseUrl) { |
|
| 941 | + $this->baseUrl = $this->parseBaseUrl(); |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + return $this->baseUrl; |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + /** |
|
| 948 | + * Returns the requested URI. |
|
| 949 | + * |
|
| 950 | + * @return string |
|
| 951 | + */ |
|
| 952 | + public function getRequestUri(): string |
|
| 953 | + { |
|
| 954 | + if (null === $this->requestToUri) { |
|
| 955 | + $this->requestToUri = $this->parseRequestUri(); |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + return $this->requestToUri; |
|
| 959 | + } |
|
| 960 | 960 | |
| 961 | - /** |
|
| 962 | - * Generates a normalized URI (URL) for the Request. |
|
| 963 | - * |
|
| 964 | - * @return string |
|
| 965 | - */ |
|
| 966 | - public function getUri(): string |
|
| 967 | - { |
|
| 968 | - if (null !== $query = $this->getQueryString()) { |
|
| 969 | - $query = '?'.$query; |
|
| 970 | - } |
|
| 961 | + /** |
|
| 962 | + * Generates a normalized URI (URL) for the Request. |
|
| 963 | + * |
|
| 964 | + * @return string |
|
| 965 | + */ |
|
| 966 | + public function getUri(): string |
|
| 967 | + { |
|
| 968 | + if (null !== $query = $this->getQueryString()) { |
|
| 969 | + $query = '?'.$query; |
|
| 970 | + } |
|
| 971 | 971 | |
| 972 | - return $this->getSchemeWithHttpHost().$this->getBaseUrl().$this->getPathInfo().$query; |
|
| 973 | - } |
|
| 972 | + return $this->getSchemeWithHttpHost().$this->getBaseUrl().$this->getPathInfo().$query; |
|
| 973 | + } |
|
| 974 | 974 | |
| 975 | - /** |
|
| 976 | - * Gets the request's scheme. |
|
| 977 | - * |
|
| 978 | - * @return string |
|
| 979 | - */ |
|
| 980 | - public function getScheme(): string |
|
| 981 | - { |
|
| 982 | - return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http'); |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - /** |
|
| 986 | - * Returns the host name. |
|
| 987 | - * |
|
| 988 | - * @return string |
|
| 989 | - */ |
|
| 990 | - public function getHost(): string |
|
| 991 | - { |
|
| 992 | - if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) { |
|
| 993 | - $host = $forwardedHost[0]; |
|
| 994 | - } elseif ( ! $host = $this->headers->get('HOST')) { |
|
| 995 | - if ( ! $host = $this->server->get('SERVER_NAME')) { |
|
| 996 | - $host = $this->server->get('REMOTE_ADDR', ''); |
|
| 997 | - } |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - $host = strtolower(preg_replace('/:\d+$/', '', trim(($host)))); |
|
| 975 | + /** |
|
| 976 | + * Gets the request's scheme. |
|
| 977 | + * |
|
| 978 | + * @return string |
|
| 979 | + */ |
|
| 980 | + public function getScheme(): string |
|
| 981 | + { |
|
| 982 | + return $this->secure() ? $this->uri->setScheme('https') : $this->uri->setScheme('http'); |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + /** |
|
| 986 | + * Returns the host name. |
|
| 987 | + * |
|
| 988 | + * @return string |
|
| 989 | + */ |
|
| 990 | + public function getHost(): string |
|
| 991 | + { |
|
| 992 | + if ($forwardedHost = $this->server->get('HTTP_X_FORWARDED_HOST')) { |
|
| 993 | + $host = $forwardedHost[0]; |
|
| 994 | + } elseif ( ! $host = $this->headers->get('HOST')) { |
|
| 995 | + if ( ! $host = $this->server->get('SERVER_NAME')) { |
|
| 996 | + $host = $this->server->get('REMOTE_ADDR', ''); |
|
| 997 | + } |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + $host = strtolower(preg_replace('/:\d+$/', '', trim(($host)))); |
|
| 1001 | 1001 | |
| 1002 | - return $this->uri->setHost($host); |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - /** |
|
| 1006 | - * Returns the port on which the request is made. |
|
| 1007 | - * |
|
| 1008 | - * @return int |
|
| 1009 | - */ |
|
| 1010 | - public function getPort(): int |
|
| 1011 | - { |
|
| 1012 | - if ( ! $this->server->get('HTTP_HOST')) { |
|
| 1013 | - return $this->server->get('SERVER_PORT'); |
|
| 1014 | - } |
|
| 1002 | + return $this->uri->setHost($host); |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + /** |
|
| 1006 | + * Returns the port on which the request is made. |
|
| 1007 | + * |
|
| 1008 | + * @return int |
|
| 1009 | + */ |
|
| 1010 | + public function getPort(): int |
|
| 1011 | + { |
|
| 1012 | + if ( ! $this->server->get('HTTP_HOST')) { |
|
| 1013 | + return $this->server->get('SERVER_PORT'); |
|
| 1014 | + } |
|
| 1015 | 1015 | |
| 1016 | - return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80); |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - /** |
|
| 1020 | - * Get the user. |
|
| 1021 | - * |
|
| 1022 | - * @return string|null |
|
| 1023 | - */ |
|
| 1024 | - public function getUser(): ?string |
|
| 1025 | - { |
|
| 1026 | - $user = $this->uri->setUser( |
|
| 1027 | - $this->headers->get('PHP_AUTH_USER') |
|
| 1028 | - ); |
|
| 1029 | - |
|
| 1030 | - return $user; |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - /** |
|
| 1034 | - * Get the password. |
|
| 1035 | - * |
|
| 1036 | - * @return string|null |
|
| 1037 | - */ |
|
| 1038 | - public function getPassword(): ?string |
|
| 1039 | - { |
|
| 1040 | - $password = $this->uri->setPassword( |
|
| 1041 | - $this->headers->get('PHP_AUTH_PW') |
|
| 1042 | - ); |
|
| 1043 | - |
|
| 1044 | - return $password; |
|
| 1045 | - } |
|
| 1046 | - |
|
| 1047 | - /** |
|
| 1048 | - * Gets the user info. |
|
| 1049 | - * |
|
| 1050 | - * @return string|null |
|
| 1051 | - */ |
|
| 1052 | - public function getUserInfo(): ?string |
|
| 1053 | - { |
|
| 1054 | - return $this->uri->getUserInfo(); |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - /** |
|
| 1058 | - * Returns the HTTP host being requested. |
|
| 1059 | - * |
|
| 1060 | - * @return string |
|
| 1061 | - */ |
|
| 1062 | - public function getHttpHost(): string |
|
| 1063 | - { |
|
| 1064 | - $scheme = $this->getScheme(); |
|
| 1065 | - $port = $this->getPort(); |
|
| 1066 | - |
|
| 1067 | - if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) { |
|
| 1068 | - return $this->getHost(); |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - return $this->getHost().':'.$port; |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - /** |
|
| 1075 | - * Gets the scheme and HTTP host. |
|
| 1076 | - * |
|
| 1077 | - * @return string |
|
| 1078 | - */ |
|
| 1079 | - public function getSchemeWithHttpHost(): string |
|
| 1080 | - { |
|
| 1081 | - return $this->getScheme().'://'.$this->getHttpHost(); |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - /** |
|
| 1085 | - * Get the root URL for the application. |
|
| 1086 | - * |
|
| 1087 | - * @return string |
|
| 1088 | - */ |
|
| 1089 | - public function root(): string |
|
| 1090 | - { |
|
| 1091 | - return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/'); |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - /** |
|
| 1095 | - * Get the URL for the request. |
|
| 1096 | - * |
|
| 1097 | - * @return string |
|
| 1098 | - */ |
|
| 1099 | - public function url(): string |
|
| 1100 | - { |
|
| 1101 | - // Changed $this->path() for $this->getUri() |
|
| 1102 | - return rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/'); |
|
| 1103 | - } |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * Returns the referer. |
|
| 1107 | - * |
|
| 1108 | - * @param string|null $default |
|
| 1109 | - * |
|
| 1110 | - * @return string|null |
|
| 1111 | - */ |
|
| 1112 | - public function referer(string $default = null): string|null |
|
| 1113 | - { |
|
| 1114 | - return $this->headers->get('HTTP_REFERER', $default); |
|
| 1115 | - } |
|
| 1016 | + return 'https' === $this->getScheme() ? $this->uri->setPort(443) : $this->uri->setPort(80); |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + /** |
|
| 1020 | + * Get the user. |
|
| 1021 | + * |
|
| 1022 | + * @return string|null |
|
| 1023 | + */ |
|
| 1024 | + public function getUser(): ?string |
|
| 1025 | + { |
|
| 1026 | + $user = $this->uri->setUser( |
|
| 1027 | + $this->headers->get('PHP_AUTH_USER') |
|
| 1028 | + ); |
|
| 1029 | + |
|
| 1030 | + return $user; |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + /** |
|
| 1034 | + * Get the password. |
|
| 1035 | + * |
|
| 1036 | + * @return string|null |
|
| 1037 | + */ |
|
| 1038 | + public function getPassword(): ?string |
|
| 1039 | + { |
|
| 1040 | + $password = $this->uri->setPassword( |
|
| 1041 | + $this->headers->get('PHP_AUTH_PW') |
|
| 1042 | + ); |
|
| 1043 | + |
|
| 1044 | + return $password; |
|
| 1045 | + } |
|
| 1046 | + |
|
| 1047 | + /** |
|
| 1048 | + * Gets the user info. |
|
| 1049 | + * |
|
| 1050 | + * @return string|null |
|
| 1051 | + */ |
|
| 1052 | + public function getUserInfo(): ?string |
|
| 1053 | + { |
|
| 1054 | + return $this->uri->getUserInfo(); |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + /** |
|
| 1058 | + * Returns the HTTP host being requested. |
|
| 1059 | + * |
|
| 1060 | + * @return string |
|
| 1061 | + */ |
|
| 1062 | + public function getHttpHost(): string |
|
| 1063 | + { |
|
| 1064 | + $scheme = $this->getScheme(); |
|
| 1065 | + $port = $this->getPort(); |
|
| 1066 | + |
|
| 1067 | + if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) { |
|
| 1068 | + return $this->getHost(); |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + return $this->getHost().':'.$port; |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + /** |
|
| 1075 | + * Gets the scheme and HTTP host. |
|
| 1076 | + * |
|
| 1077 | + * @return string |
|
| 1078 | + */ |
|
| 1079 | + public function getSchemeWithHttpHost(): string |
|
| 1080 | + { |
|
| 1081 | + return $this->getScheme().'://'.$this->getHttpHost(); |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + /** |
|
| 1085 | + * Get the root URL for the application. |
|
| 1086 | + * |
|
| 1087 | + * @return string |
|
| 1088 | + */ |
|
| 1089 | + public function root(): string |
|
| 1090 | + { |
|
| 1091 | + return rtrim($this->getSchemeWithHttpHost().$this->getBaseUrl(), '/'); |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + /** |
|
| 1095 | + * Get the URL for the request. |
|
| 1096 | + * |
|
| 1097 | + * @return string |
|
| 1098 | + */ |
|
| 1099 | + public function url(): string |
|
| 1100 | + { |
|
| 1101 | + // Changed $this->path() for $this->getUri() |
|
| 1102 | + return rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/'); |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * Returns the referer. |
|
| 1107 | + * |
|
| 1108 | + * @param string|null $default |
|
| 1109 | + * |
|
| 1110 | + * @return string|null |
|
| 1111 | + */ |
|
| 1112 | + public function referer(string $default = null): string|null |
|
| 1113 | + { |
|
| 1114 | + return $this->headers->get('HTTP_REFERER', $default); |
|
| 1115 | + } |
|
| 1116 | 1116 | |
| 1117 | - /** |
|
| 1118 | - * Attempts to detect if the current connection is secure through |
|
| 1119 | - * over HTTPS protocol. |
|
| 1120 | - * |
|
| 1121 | - * @return bool |
|
| 1122 | - */ |
|
| 1123 | - public function secure(): bool |
|
| 1124 | - { |
|
| 1125 | - if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') { |
|
| 1126 | - return true; |
|
| 1127 | - } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') { |
|
| 1128 | - return true; |
|
| 1129 | - } elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') { |
|
| 1130 | - return true; |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - return false; |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - /** |
|
| 1137 | - * Returns the user agent. |
|
| 1138 | - * |
|
| 1139 | - * @param string|null $default |
|
| 1140 | - * |
|
| 1141 | - * @return string|null |
|
| 1142 | - */ |
|
| 1143 | - public function userAgent(string $default = null): string|null |
|
| 1144 | - { |
|
| 1145 | - return $this->headers->get('HTTP_USER_AGENT', $default); |
|
| 1146 | - } |
|
| 1117 | + /** |
|
| 1118 | + * Attempts to detect if the current connection is secure through |
|
| 1119 | + * over HTTPS protocol. |
|
| 1120 | + * |
|
| 1121 | + * @return bool |
|
| 1122 | + */ |
|
| 1123 | + public function secure(): bool |
|
| 1124 | + { |
|
| 1125 | + if ( ! empty($this->server->get('HTTPS')) && strtolower($this->server->get('HTTPS')) !== 'off') { |
|
| 1126 | + return true; |
|
| 1127 | + } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $this->server->get('HTTP_X_FORWARDED_PROTO') === 'https') { |
|
| 1128 | + return true; |
|
| 1129 | + } elseif ( ! empty($this->server->get('HTTP_FRONT_END_HTTPS')) && strtolower($this->server->get('HTTP_FRONT_END_HTTPS')) !== 'off') { |
|
| 1130 | + return true; |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + return false; |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + /** |
|
| 1137 | + * Returns the user agent. |
|
| 1138 | + * |
|
| 1139 | + * @param string|null $default |
|
| 1140 | + * |
|
| 1141 | + * @return string|null |
|
| 1142 | + */ |
|
| 1143 | + public function userAgent(string $default = null): string|null |
|
| 1144 | + { |
|
| 1145 | + return $this->headers->get('HTTP_USER_AGENT', $default); |
|
| 1146 | + } |
|
| 1147 | 1147 | |
| 1148 | - /** |
|
| 1149 | - * Get the client IP address. |
|
| 1150 | - * |
|
| 1151 | - * @return string|null |
|
| 1152 | - */ |
|
| 1153 | - public function ip(): ?string |
|
| 1154 | - { |
|
| 1155 | - return $this->clientIp->getClientIp(); |
|
| 1156 | - } |
|
| 1157 | - |
|
| 1158 | - /** |
|
| 1159 | - * Get the route resolver callback. |
|
| 1160 | - * |
|
| 1161 | - * @return \Closure |
|
| 1162 | - */ |
|
| 1163 | - public function getRouteResolver(): Closure |
|
| 1164 | - { |
|
| 1165 | - return $this->routeResolver ?: function () { |
|
| 1166 | - // |
|
| 1167 | - }; |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - /** |
|
| 1171 | - * Set the route resolver callback. |
|
| 1172 | - * |
|
| 1173 | - * @param \Closure $callback |
|
| 1174 | - * |
|
| 1175 | - * @return static |
|
| 1176 | - */ |
|
| 1177 | - public function setRouteResolver(Closure $callback): static |
|
| 1178 | - { |
|
| 1179 | - $this->routeResolver = $callback; |
|
| 1180 | - |
|
| 1181 | - return $this; |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - /** |
|
| 1185 | - * Magic method. |
|
| 1186 | - * |
|
| 1187 | - * Get an element from the request. |
|
| 1188 | - * |
|
| 1189 | - * @return string[] |
|
| 1190 | - */ |
|
| 1191 | - public function __get($key) |
|
| 1192 | - { |
|
| 1193 | - return Arr::get($this->all(), $key, fn () => $this->route($key)); |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - /** |
|
| 1197 | - * Magic method. |
|
| 1198 | - * |
|
| 1199 | - * Returns the Request as an HTTP string. |
|
| 1200 | - * |
|
| 1201 | - * @return string |
|
| 1202 | - */ |
|
| 1203 | - public function __toString(): string |
|
| 1204 | - { |
|
| 1205 | - $content = $this->getContent(); |
|
| 1206 | - |
|
| 1207 | - $cookieHeader = ''; |
|
| 1208 | - $cookies = []; |
|
| 1209 | - |
|
| 1210 | - foreach ($this->cookies as $key => $value) { |
|
| 1211 | - $cookies[]= is_array($value) ? http_build_query([$key => $value], '', '; ', PHP_QUERY_RFC3986) : "$key=$value"; |
|
| 1212 | - } |
|
| 1213 | - |
|
| 1214 | - if ($cookies) { |
|
| 1215 | - $cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n"; |
|
| 1216 | - } |
|
| 1148 | + /** |
|
| 1149 | + * Get the client IP address. |
|
| 1150 | + * |
|
| 1151 | + * @return string|null |
|
| 1152 | + */ |
|
| 1153 | + public function ip(): ?string |
|
| 1154 | + { |
|
| 1155 | + return $this->clientIp->getClientIp(); |
|
| 1156 | + } |
|
| 1157 | + |
|
| 1158 | + /** |
|
| 1159 | + * Get the route resolver callback. |
|
| 1160 | + * |
|
| 1161 | + * @return \Closure |
|
| 1162 | + */ |
|
| 1163 | + public function getRouteResolver(): Closure |
|
| 1164 | + { |
|
| 1165 | + return $this->routeResolver ?: function () { |
|
| 1166 | + // |
|
| 1167 | + }; |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + /** |
|
| 1171 | + * Set the route resolver callback. |
|
| 1172 | + * |
|
| 1173 | + * @param \Closure $callback |
|
| 1174 | + * |
|
| 1175 | + * @return static |
|
| 1176 | + */ |
|
| 1177 | + public function setRouteResolver(Closure $callback): static |
|
| 1178 | + { |
|
| 1179 | + $this->routeResolver = $callback; |
|
| 1180 | + |
|
| 1181 | + return $this; |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + /** |
|
| 1185 | + * Magic method. |
|
| 1186 | + * |
|
| 1187 | + * Get an element from the request. |
|
| 1188 | + * |
|
| 1189 | + * @return string[] |
|
| 1190 | + */ |
|
| 1191 | + public function __get($key) |
|
| 1192 | + { |
|
| 1193 | + return Arr::get($this->all(), $key, fn () => $this->route($key)); |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + /** |
|
| 1197 | + * Magic method. |
|
| 1198 | + * |
|
| 1199 | + * Returns the Request as an HTTP string. |
|
| 1200 | + * |
|
| 1201 | + * @return string |
|
| 1202 | + */ |
|
| 1203 | + public function __toString(): string |
|
| 1204 | + { |
|
| 1205 | + $content = $this->getContent(); |
|
| 1206 | + |
|
| 1207 | + $cookieHeader = ''; |
|
| 1208 | + $cookies = []; |
|
| 1209 | + |
|
| 1210 | + foreach ($this->cookies as $key => $value) { |
|
| 1211 | + $cookies[]= is_array($value) ? http_build_query([$key => $value], '', '; ', PHP_QUERY_RFC3986) : "$key=$value"; |
|
| 1212 | + } |
|
| 1213 | + |
|
| 1214 | + if ($cookies) { |
|
| 1215 | + $cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n"; |
|
| 1216 | + } |
|
| 1217 | 1217 | |
| 1218 | - return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n". |
|
| 1219 | - $this->headers. |
|
| 1220 | - $cookieHeader."\r\n". |
|
| 1221 | - $content; |
|
| 1222 | - } |
|
| 1223 | - |
|
| 1224 | - /** |
|
| 1225 | - * Magic method. |
|
| 1226 | - * |
|
| 1227 | - * Clones the current request. |
|
| 1228 | - * |
|
| 1229 | - * @return void |
|
| 1230 | - */ |
|
| 1231 | - public function __clone() |
|
| 1232 | - { |
|
| 1233 | - $this->query = clone $this->query; |
|
| 1234 | - $this->request = clone $this->request; |
|
| 1235 | - $this->attributes = clone $this->attributes; |
|
| 1236 | - $this->cookies = clone $this->cookies; |
|
| 1237 | - $this->files = clone $this->files; |
|
| 1238 | - $this->server = clone $this->server; |
|
| 1239 | - $this->headers = clone $this->headers; |
|
| 1240 | - } |
|
| 1218 | + return sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n". |
|
| 1219 | + $this->headers. |
|
| 1220 | + $cookieHeader."\r\n". |
|
| 1221 | + $content; |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + /** |
|
| 1225 | + * Magic method. |
|
| 1226 | + * |
|
| 1227 | + * Clones the current request. |
|
| 1228 | + * |
|
| 1229 | + * @return void |
|
| 1230 | + */ |
|
| 1231 | + public function __clone() |
|
| 1232 | + { |
|
| 1233 | + $this->query = clone $this->query; |
|
| 1234 | + $this->request = clone $this->request; |
|
| 1235 | + $this->attributes = clone $this->attributes; |
|
| 1236 | + $this->cookies = clone $this->cookies; |
|
| 1237 | + $this->files = clone $this->files; |
|
| 1238 | + $this->server = clone $this->server; |
|
| 1239 | + $this->headers = clone $this->headers; |
|
| 1240 | + } |
|
| 1241 | 1241 | } |
| 1242 | 1242 | \ No newline at end of file |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | private static function createFromRequestFactory( |
| 359 | 359 | array $query = [], |
| 360 | 360 | array $request = [], |
| 361 | - array $attributes = [] , |
|
| 361 | + array $attributes = [], |
|
| 362 | 362 | array $cookies = [], |
| 363 | 363 | array $files = [], |
| 364 | 364 | array $server = [] |
@@ -1064,7 +1064,7 @@ discard block |
||
| 1064 | 1064 | $scheme = $this->getScheme(); |
| 1065 | 1065 | $port = $this->getPort(); |
| 1066 | 1066 | |
| 1067 | - if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) { |
|
| 1067 | + if (('http' === $scheme && 80 === $port) || ('https' === $scheme && 443 === $port)) { |
|
| 1068 | 1068 | return $this->getHost(); |
| 1069 | 1069 | } |
| 1070 | 1070 | |
@@ -1109,7 +1109,7 @@ discard block |
||
| 1109 | 1109 | * |
| 1110 | 1110 | * @return string|null |
| 1111 | 1111 | */ |
| 1112 | - public function referer(string $default = null): string|null |
|
| 1112 | + public function referer(string $default = null): string | null |
|
| 1113 | 1113 | { |
| 1114 | 1114 | return $this->headers->get('HTTP_REFERER', $default); |
| 1115 | 1115 | } |
@@ -1140,7 +1140,7 @@ discard block |
||
| 1140 | 1140 | * |
| 1141 | 1141 | * @return string|null |
| 1142 | 1142 | */ |
| 1143 | - public function userAgent(string $default = null): string|null |
|
| 1143 | + public function userAgent(string $default = null): string | null |
|
| 1144 | 1144 | { |
| 1145 | 1145 | return $this->headers->get('HTTP_USER_AGENT', $default); |
| 1146 | 1146 | } |
@@ -1162,7 +1162,7 @@ discard block |
||
| 1162 | 1162 | */ |
| 1163 | 1163 | public function getRouteResolver(): Closure |
| 1164 | 1164 | { |
| 1165 | - return $this->routeResolver ?: function () { |
|
| 1165 | + return $this->routeResolver ?: function() { |
|
| 1166 | 1166 | // |
| 1167 | 1167 | }; |
| 1168 | 1168 | } |
@@ -1208,7 +1208,7 @@ discard block |
||
| 1208 | 1208 | $cookies = []; |
| 1209 | 1209 | |
| 1210 | 1210 | foreach ($this->cookies as $key => $value) { |
| 1211 | - $cookies[]= is_array($value) ? http_build_query([$key => $value], '', '; ', PHP_QUERY_RFC3986) : "$key=$value"; |
|
| 1211 | + $cookies[] = is_array($value) ? http_build_query([$key => $value], '', '; ', PHP_QUERY_RFC3986) : "$key=$value"; |
|
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | 1214 | if ($cookies) { |
@@ -85,6 +85,6 @@ |
||
| 85 | 85 | public static function longVersion(): string |
| 86 | 86 | { |
| 87 | 87 | return self::COPY.' '.self::YEAR.' '.self::COPYRIGHT.' - '.self::NAME.' ' .self::RELEASE. ' '. |
| 88 | - self::STATUS.' [ '.self::CODENAME.' ] '.self::RELEASEDATE; |
|
| 88 | + self::STATUS.' [ '.self::CODENAME.' ] '.self::RELEASEDATE; |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | \ No newline at end of file |
@@ -84,7 +84,7 @@ |
||
| 84 | 84 | */ |
| 85 | 85 | public static function longVersion(): string |
| 86 | 86 | { |
| 87 | - return self::COPY.' '.self::YEAR.' '.self::COPYRIGHT.' - '.self::NAME.' ' .self::RELEASE. ' '. |
|
| 87 | + return self::COPY.' '.self::YEAR.' '.self::COPYRIGHT.' - '.self::NAME.' '.self::RELEASE.' '. |
|
| 88 | 88 | self::STATUS.' [ '.self::CODENAME.' ] '.self::RELEASEDATE; |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | \ No newline at end of file |
@@ -301,7 +301,7 @@ |
||
| 301 | 301 | */ |
| 302 | 302 | public function getDefaultDriver(): string |
| 303 | 303 | { |
| 304 | - return $this->app['config']['cache.default']; |
|
| 304 | + return $this->app['config']['cache.default']; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -472,7 +472,7 @@ |
||
| 472 | 472 | */ |
| 473 | 473 | public function offsetSet($offset, $value): void |
| 474 | 474 | { |
| 475 | - $this->put($offset, $value, $this->cacheTime); |
|
| 475 | + $this->put($offset, $value, $this->cacheTime); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /** |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * |
| 280 | 280 | * @return int|bool |
| 281 | 281 | */ |
| 282 | - public function increment(string $key, mixed $value = 1): int|bool |
|
| 282 | + public function increment(string $key, mixed $value = 1): int | bool |
|
| 283 | 283 | { |
| 284 | 284 | return $this->store->increment($key, $value); |
| 285 | 285 | } |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | * |
| 293 | 293 | * @return int|bool |
| 294 | 294 | */ |
| 295 | - public function decrement(string $key, mixed $value = 1): int|bool |
|
| 295 | + public function decrement(string $key, mixed $value = 1): int | bool |
|
| 296 | 296 | { |
| 297 | 297 | return $this->store->decrement($key, $value); |
| 298 | 298 | } |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | { |
| 39 | 39 | $return = []; |
| 40 | 40 | |
| 41 | - $keys = collect($keys)->mapKeys(function ($value, $key) { |
|
| 41 | + $keys = collect($keys)->mapKeys(function($value, $key) { |
|
| 42 | 42 | return [is_string($key) ? $key : $value => is_string($key) ? $value : null]; |
| 43 | 43 | })->all(); |
| 44 | 44 | |
@@ -111,10 +111,10 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @return int|bool |
| 113 | 113 | */ |
| 114 | - public function increment(string $key, mixed $value = 1): int|bool |
|
| 114 | + public function increment(string $key, mixed $value = 1): int | bool |
|
| 115 | 115 | { |
| 116 | 116 | if ( ! is_null($existing = $this->get($key))) { |
| 117 | - return take(((int) $existing) + $value, function ($incremented) use ($key) { |
|
| 117 | + return take(((int) $existing) + $value, function($incremented) use ($key) { |
|
| 118 | 118 | $value = $this->serialized ? serialize($incremented) : $incremented; |
| 119 | 119 | |
| 120 | 120 | $this->storage[$key]['value'] = $value; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * |
| 135 | 135 | * @return int|bool |
| 136 | 136 | */ |
| 137 | - public function decrement(string $key, mixed $value = 1): int|bool |
|
| 137 | + public function decrement(string $key, mixed $value = 1): int | bool |
|
| 138 | 138 | { |
| 139 | 139 | return $this->increment($key, $value * -1); |
| 140 | 140 | } |
@@ -69,7 +69,9 @@ |
||
| 69 | 69 | */ |
| 70 | 70 | public function get(string $key) |
| 71 | 71 | { |
| 72 | - if ( ! isset($this->storage[$key])) return; |
|
| 72 | + if ( ! isset($this->storage[$key])) { |
|
| 73 | + return; |
|
| 74 | + } |
|
| 73 | 75 | |
| 74 | 76 | $item = $this->storage[$key]; |
| 75 | 77 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | $this->memcached = $memcached; |
| 71 | 71 | $this->onVersion = (new ReflectionMethod('Memcached', 'getMulti')) |
| 72 | - ->getNumberOfParameters() == 2; |
|
| 72 | + ->getNumberOfParameters() == 2; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | return $this->memcached->decrement($this->prefix.$key, $value = 1); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * Deletes a specific item from the cache store. |
|
| 206 | - * |
|
| 207 | - * @param string $key |
|
| 208 | - * |
|
| 209 | - * @return mixed |
|
| 210 | - */ |
|
| 204 | + /** |
|
| 205 | + * Deletes a specific item from the cache store. |
|
| 206 | + * |
|
| 207 | + * @param string $key |
|
| 208 | + * |
|
| 209 | + * @return mixed |
|
| 210 | + */ |
|
| 211 | 211 | public function delete(string $key): mixed |
| 212 | 212 | { |
| 213 | 213 | return $this->memcached->delete($this->prefix.$key); |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function many(array $keys): array |
| 111 | 111 | { |
| 112 | - $prefixed = array_map(function ($key) { |
|
| 112 | + $prefixed = array_map(function($key) { |
|
| 113 | 113 | return $this->prefix.$key; |
| 114 | 114 | }, $keys); |
| 115 | 115 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @return int|bool |
| 185 | 185 | */ |
| 186 | - public function increment(string $key, mixed $value = 1): int|bool |
|
| 186 | + public function increment(string $key, mixed $value = 1): int | bool |
|
| 187 | 187 | { |
| 188 | 188 | return $this->memcached->increment($this->prefix.$key, $value); |
| 189 | 189 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * |
| 197 | 197 | * @return int|bool |
| 198 | 198 | */ |
| 199 | - public function decrement(string $key, mixed $value = 1): int|bool |
|
| 199 | + public function decrement(string $key, mixed $value = 1): int | bool |
|
| 200 | 200 | { |
| 201 | 201 | return $this->memcached->decrement($this->prefix.$key, $value = 1); |
| 202 | 202 | } |
@@ -297,11 +297,11 @@ |
||
| 297 | 297 | return $this->files; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * Gets the cache key prefix. |
|
| 302 | - * |
|
| 303 | - * @return string |
|
| 304 | - */ |
|
| 300 | + /** |
|
| 301 | + * Gets the cache key prefix. |
|
| 302 | + * |
|
| 303 | + * @return string |
|
| 304 | + */ |
|
| 305 | 305 | public function getPrefix(): string |
| 306 | 306 | { |
| 307 | 307 | return ''; |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * |
| 206 | 206 | * @return int|bool |
| 207 | 207 | */ |
| 208 | - public function increment(string $key, mixed $value = 1): int|bool |
|
| 208 | + public function increment(string $key, mixed $value = 1): int | bool |
|
| 209 | 209 | { |
| 210 | 210 | $raw = $this->getPayLoad($key); |
| 211 | 211 | $int = ((int) $raw['data']) + $value; |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * |
| 224 | 224 | * @return int|bool |
| 225 | 225 | */ |
| 226 | - public function decrement(string $key, mixed $value = 1): int|bool |
|
| 226 | + public function decrement(string $key, mixed $value = 1): int | bool |
|
| 227 | 227 | { |
| 228 | 228 | return $this->increment($key, $value * -1); |
| 229 | 229 | } |
@@ -163,9 +163,9 @@ discard block |
||
| 163 | 163 | * |
| 164 | 164 | * @return int|bool |
| 165 | 165 | */ |
| 166 | - public function increment(string $key, mixed $value = 1): int|bool |
|
| 166 | + public function increment(string $key, mixed $value = 1): int | bool |
|
| 167 | 167 | { |
| 168 | - return $this->incrementOrDecrement($key, $value, function ($current, $value) { |
|
| 168 | + return $this->incrementOrDecrement($key, $value, function($current, $value) { |
|
| 169 | 169 | return $current + $value; |
| 170 | 170 | }); |
| 171 | 171 | } |
@@ -178,9 +178,9 @@ discard block |
||
| 178 | 178 | * |
| 179 | 179 | * @return int|bool |
| 180 | 180 | */ |
| 181 | - public function decrement(string $key, mixed $value = 1): int|bool |
|
| 181 | + public function decrement(string $key, mixed $value = 1): int | bool |
|
| 182 | 182 | { |
| 183 | - return $this->incrementOrDecrement($key, $value, function ($current, $value) { |
|
| 183 | + return $this->incrementOrDecrement($key, $value, function($current, $value) { |
|
| 184 | 184 | return $current - $value; |
| 185 | 185 | }); |
| 186 | 186 | } |
@@ -194,9 +194,9 @@ discard block |
||
| 194 | 194 | * |
| 195 | 195 | * @return int|bool |
| 196 | 196 | */ |
| 197 | - protected function incrementOrDecrement(string $key, mixed $value, Closure $callback): int|bool |
|
| 197 | + protected function incrementOrDecrement(string $key, mixed $value, Closure $callback): int | bool |
|
| 198 | 198 | { |
| 199 | - return $this->connection->transaction(function () use ($key, $value, $callback) { |
|
| 199 | + return $this->connection->transaction(function() use ($key, $value, $callback) { |
|
| 200 | 200 | $prefixed = $this->prefix.$key; |
| 201 | 201 | $cache = $this->table()->where('key', $prefixed)->first(); |
| 202 | 202 | |
@@ -90,7 +90,9 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | $cache = $this->table()->where('key', '=', $prefixed)->first(); |
| 92 | 92 | |
| 93 | - if (is_null($cache)) return; |
|
| 93 | + if (is_null($cache)) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 94 | 96 | |
| 95 | 97 | $cache = is_array($cache) ? (object) $cache : $cache; |
| 96 | 98 | |
@@ -200,7 +202,9 @@ discard block |
||
| 200 | 202 | $prefixed = $this->prefix.$key; |
| 201 | 203 | $cache = $this->table()->where('key', $prefixed)->first(); |
| 202 | 204 | |
| 203 | - if (is_null($cache)) return false; |
|
| 205 | + if (is_null($cache)) { |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 204 | 208 | |
| 205 | 209 | $cache = is_array($cache) ? (object) $cache : $cache; |
| 206 | 210 | |
@@ -208,7 +212,9 @@ discard block |
||
| 208 | 212 | |
| 209 | 213 | $result = $callback((int) $current, $value); |
| 210 | 214 | |
| 211 | - if ( ! is_numeric($current)) return false; |
|
| 215 | + if ( ! is_numeric($current)) { |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 212 | 218 | |
| 213 | 219 | $this->table()->where('key', $prefixed)->update([ |
| 214 | 220 | 'value' => $this->serialize($result), |