| 1 |
<?php |
| 2 |
|
| 3 |
namespace Illuminate\Support; |
| 4 |
|
| 5 |
use Illuminate\Contracts\Support\Arrayable; |
| 6 |
use Illuminate\Support\Traits\InteractsWithData; |
| 7 |
use League\Uri\QueryString; |
| 8 |
use Stringable; |
| 9 |
|
| 10 |
class UriQueryString implements Arrayable, Stringable |
| 11 |
{ |
| 12 |
use InteractsWithData; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
public function __construct(protected Uri $uri) |
| 18 |
{ |
| 19 |
|
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public function all($keys = null) |
| 29 |
{ |
| 30 |
$query = $this->toArray(); |
| 31 |
|
| 32 |
if (! $keys) { |
| 33 |
return $query; |
| 34 |
} |
| 35 |
|
| 36 |
$results = []; |
| 37 |
|
| 38 |
foreach (is_array($keys) ? $keys : func_get_args() as $key) { |
| 39 |
Arr::set($results, $key, Arr::get($query, $key)); |
| 40 |
} |
| 41 |
|
| 42 |
return $results; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
protected function data($key = null, $default = null) |
| 53 |
{ |
| 54 |
return $this->get($key, $default); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public function get(?string $key = null, mixed $default = null): mixed |
| 61 |
{ |
| 62 |
return data_get($this->toArray(), $key, $default); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public function decode(): string |
| 69 |
{ |
| 70 |
return rawurldecode((string) $this); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public function value(): string |
| 77 |
{ |
| 78 |
return (string) $this; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public function toArray() |
| 85 |
{ |
| 86 |
return QueryString::extract($this->value()); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public function __toString(): string |
| 93 |
{ |
| 94 |
return (string) $this->uri->getUri()->getQuery(); |
| 95 |
} |
| 96 |
} |