PluginProbe ʕ •ᴥ•ʔ
10Web Booster – Website speed optimization, Cache & Page Speed optimizer / trunk
10Web Booster – Website speed optimization, Cache & Page Speed optimizer vtrunk
2.33.0 2.30.5 2.30.7 2.30.9 2.31.10 2.31.8 2.32.11 2.32.21 2.32.3 2.32.4 2.32.7 2.6.31 2.6.40 2.6.42 2.6.7 2.7.37 2.7.44 2.7.47 2.8.18 2.8.19 2.8.32 2.8.34 2.8.35 2.9.23 2.9.24 2.9.25 2.9.27 v2.27.4 trunk 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.17 2.0.18 2.0.21 2.0.22 2.0.25 2.0.26 2.0.27 2.0.3 2.0.7 2.0.9 2.10.46 2.10.65 2.10.66 2.10.68 2.11.41 2.11.42 2.11.43 2.12.15 2.12.21 2.12.22 2.12.23 2.12.26 2.13.37 2.13.40 2.13.41 2.13.42 2.13.44 2.13.45 2.13.47 2.14.49 2.14.50 2.15.18 2.17.21 2.17.23 2.18.17 2.19.44 2.19.45 2.19.46 2.19.49 2.2.12 2.2.15 2.2.16 2.2.18 2.2.8 2.20.31 2.20.32 2.20.33 2.21.11 2.21.12 2.21.16 2.21.25 2.22.32 2.23.13 2.23.15 2.23.16 2.23.18 2.24.12 2.24.14 2.24.18 2.25.14 2.26.6 2.28.10 2.28.13 2.28.14 2.28.7 2.29.1 2.29.2 2.29.3 2.3.0 2.3.1 2.3.2 2.3.3 2.30.18
tenweb-speed-optimizer / vendor / enqueue / dsn / QueryBag.php
tenweb-speed-optimizer / vendor / enqueue / dsn Last commit date
.github 2 years ago Dsn.php 4 years ago InvalidQueryParameterTypeException.php 4 years ago LICENSE 4 years ago QueryBag.php 4 years ago README.md 4 years ago composer.json 2 years ago
QueryBag.php
104 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Enqueue\Dsn;
6
7 class QueryBag
8 {
9 /**
10 * @var array
11 */
12 private $query;
13
14 public function __construct(array $query)
15 {
16 $this->query = $query;
17 }
18
19 public function toArray(): array
20 {
21 return $this->query;
22 }
23
24 public function getString(string $name, string $default = null): ?string
25 {
26 return array_key_exists($name, $this->query) ? $this->query[$name] : $default;
27 }
28
29 public function getDecimal(string $name, int $default = null): ?int
30 {
31 $value = $this->getString($name);
32 if (null === $value) {
33 return $default;
34 }
35
36 if (false == preg_match('/^[\+\-]?[0-9]*$/', $value)) {
37 throw InvalidQueryParameterTypeException::create($name, 'decimal');
38 }
39
40 return (int) $value;
41 }
42
43 public function getOctal(string $name, int $default = null): ?int
44 {
45 $value = $this->getString($name);
46 if (null === $value) {
47 return $default;
48 }
49
50 if (false == preg_match('/^0[\+\-]?[0-7]*$/', $value)) {
51 throw InvalidQueryParameterTypeException::create($name, 'octal');
52 }
53
54 return intval($value, 8);
55 }
56
57 public function getFloat(string $name, float $default = null): ?float
58 {
59 $value = $this->getString($name);
60 if (null === $value) {
61 return $default;
62 }
63
64 if (false == is_numeric($value)) {
65 throw InvalidQueryParameterTypeException::create($name, 'float');
66 }
67
68 return (float) $value;
69 }
70
71 public function getBool(string $name, bool $default = null): ?bool
72 {
73 $value = $this->getString($name);
74 if (null === $value) {
75 return $default;
76 }
77
78 if (in_array($value, ['', '0', 'false'], true)) {
79 return false;
80 }
81
82 if (in_array($value, ['1', 'true'], true)) {
83 return true;
84 }
85
86 throw InvalidQueryParameterTypeException::create($name, 'bool');
87 }
88
89 public function getArray(string $name, array $default = []): self
90 {
91 if (false == array_key_exists($name, $this->query)) {
92 return new self($default);
93 }
94
95 $value = $this->query[$name];
96
97 if (is_array($value)) {
98 return new self($value);
99 }
100
101 throw InvalidQueryParameterTypeException::create($name, 'array');
102 }
103 }
104