Debian Codegraph @

lib/3rdParty/composer/illuminate/support/UriQueryString.php

raw symbols SCIP
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 * Create a new URI query string instance.
16 */
17 public function __construct(protected Uri $uri)
18 {
19 //
20 }
21
22 /**
23 * Retrieve all data from the instance.
24 *
25 * @param mixed $keys
26 * @return array
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 * Retrieve data from the instance.
47 *
48 * @param string|null $key
49 * @param mixed $default
50 * @return mixed
51 */
52 protected function data($key = null, $default = null)
53 {
54 return $this->get($key, $default);
55 }
56
57 /**
58 * Get a query string parameter.
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 * Get the URL decoded version of the query string.
67 */
68 public function decode(): string
69 {
70 return rawurldecode((string) $this);
71 }
72
73 /**
74 * Get the string representation of the query string.
75 */
76 public function value(): string
77 {
78 return (string) $this;
79 }
80
81 /**
82 * Convert the query string into an array.
83 */
84 public function toArray()
85 {
86 return QueryString::extract($this->value());
87 }
88
89 /**
90 * Get the string representation of the query string.
91 */
92 public function __toString(): string
93 {
94 return (string) $this->uri->getUri()->getQuery();
95 }
96 }