@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | bool $useMicroSeconds = false |
21 | 21 | ): bool { |
22 | 22 | $compare = $this->compare($this->date($value), $this->date($threshold), $useMicroSeconds); |
23 | - if (is_bool($compare)) { |
|
23 | + if (is_bool($compare)){ |
|
24 | 24 | return $compare; |
25 | 25 | } |
26 | 26 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | bool $useMicroSeconds = false |
38 | 38 | ): bool { |
39 | 39 | $compare = $this->compare($this->date($value), $this->date($threshold), $useMicroSeconds); |
40 | - if (is_bool($compare)) { |
|
40 | + if (is_bool($compare)){ |
|
41 | 41 | return $compare; |
42 | 42 | } |
43 | 43 | |
@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | */ |
50 | 50 | private function date($value): ?DateTimeImmutable |
51 | 51 | { |
52 | - if ($value instanceof DateTimeImmutable) { |
|
52 | + if ($value instanceof DateTimeImmutable){ |
|
53 | 53 | return $value; |
54 | 54 | } |
55 | 55 | |
56 | - if ($value instanceof DateTime) { |
|
56 | + if ($value instanceof DateTime){ |
|
57 | 57 | return DateTimeImmutable::createFromMutable($value); |
58 | 58 | } |
59 | 59 | |
@@ -65,15 +65,15 @@ discard block |
||
65 | 65 | */ |
66 | 66 | private function compare(?DateTimeImmutable $date, ?DateTimeImmutable $threshold, bool $useMicroseconds) |
67 | 67 | { |
68 | - if ($date === null) { |
|
68 | + if ($date === null){ |
|
69 | 69 | return false; |
70 | 70 | } |
71 | 71 | |
72 | - if ($threshold === null) { |
|
72 | + if ($threshold === null){ |
|
73 | 73 | return true; |
74 | 74 | } |
75 | 75 | |
76 | - if (!$useMicroseconds) { |
|
76 | + if (!$useMicroseconds){ |
|
77 | 77 | $date = $this->dropMicroSeconds($date); |
78 | 78 | $threshold = $this->dropMicroSeconds($threshold); |
79 | 79 | } |
@@ -20,7 +20,8 @@ discard block |
||
20 | 20 | bool $useMicroSeconds = false |
21 | 21 | ): bool { |
22 | 22 | $compare = $this->compare($this->date($value), $this->date($threshold), $useMicroSeconds); |
23 | - if (is_bool($compare)) { |
|
23 | + if (is_bool($compare)) |
|
24 | + { |
|
24 | 25 | return $compare; |
25 | 26 | } |
26 | 27 | |
@@ -37,7 +38,8 @@ discard block |
||
37 | 38 | bool $useMicroSeconds = false |
38 | 39 | ): bool { |
39 | 40 | $compare = $this->compare($this->date($value), $this->date($threshold), $useMicroSeconds); |
40 | - if (is_bool($compare)) { |
|
41 | + if (is_bool($compare)) |
|
42 | + { |
|
41 | 43 | return $compare; |
42 | 44 | } |
43 | 45 | |
@@ -49,11 +51,13 @@ discard block |
||
49 | 51 | */ |
50 | 52 | private function date($value): ?DateTimeImmutable |
51 | 53 | { |
52 | - if ($value instanceof DateTimeImmutable) { |
|
54 | + if ($value instanceof DateTimeImmutable) |
|
55 | + { |
|
53 | 56 | return $value; |
54 | 57 | } |
55 | 58 | |
56 | - if ($value instanceof DateTime) { |
|
59 | + if ($value instanceof DateTime) |
|
60 | + { |
|
57 | 61 | return DateTimeImmutable::createFromMutable($value); |
58 | 62 | } |
59 | 63 | |
@@ -65,15 +69,18 @@ discard block |
||
65 | 69 | */ |
66 | 70 | private function compare(?DateTimeImmutable $date, ?DateTimeImmutable $threshold, bool $useMicroseconds) |
67 | 71 | { |
68 | - if ($date === null) { |
|
72 | + if ($date === null) |
|
73 | + { |
|
69 | 74 | return false; |
70 | 75 | } |
71 | 76 | |
72 | - if ($threshold === null) { |
|
77 | + if ($threshold === null) |
|
78 | + { |
|
73 | 79 | return true; |
74 | 80 | } |
75 | 81 | |
76 | - if (!$useMicroseconds) { |
|
82 | + if (!$useMicroseconds) |
|
83 | + { |
|
77 | 84 | $date = $this->dropMicroSeconds($date); |
78 | 85 | $threshold = $this->dropMicroSeconds($threshold); |
79 | 86 | } |
@@ -43,11 +43,11 @@ |
||
43 | 43 | */ |
44 | 44 | public function getConditions(): Generator |
45 | 45 | { |
46 | - if (empty($this->conditions)) { |
|
46 | + if (empty($this->conditions)){ |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - foreach ($this->conditions as $condition) { |
|
50 | + foreach ($this->conditions as $condition){ |
|
51 | 51 | yield $condition->withOptions($this->conditions->offsetGet($condition)); |
52 | 52 | } |
53 | 53 | } |
@@ -43,11 +43,13 @@ |
||
43 | 43 | */ |
44 | 44 | public function getConditions(): Generator |
45 | 45 | { |
46 | - if (empty($this->conditions)) { |
|
46 | + if (empty($this->conditions)) |
|
47 | + { |
|
47 | 48 | return; |
48 | 49 | } |
49 | 50 | |
50 | - foreach ($this->conditions as $condition) { |
|
51 | + foreach ($this->conditions as $condition) |
|
52 | + { |
|
51 | 53 | yield $condition->withOptions($this->conditions->offsetGet($condition)); |
52 | 54 | } |
53 | 55 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | public function __construct(array $config = []) |
35 | 35 | { |
36 | 36 | parent::__construct($config); |
37 | - if (!empty($this->config['aliases'])) { |
|
37 | + if (!empty($this->config['aliases'])){ |
|
38 | 38 | $this->config['aliases'] = $this->normalizeAliases($this->config['aliases']); |
39 | 39 | } |
40 | 40 | } |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function getChecker(string $name): Autowire |
52 | 52 | { |
53 | - if (!$this->hasChecker($name)) { |
|
53 | + if (!$this->hasChecker($name)){ |
|
54 | 54 | throw new ValidationException("Undefined checker `{$name}``."); |
55 | 55 | } |
56 | 56 | |
57 | 57 | $instance = $this->wire('checkers', $name); |
58 | - if ($instance !== null) { |
|
58 | + if ($instance !== null){ |
|
59 | 59 | return $instance; |
60 | 60 | } |
61 | 61 | |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | |
70 | 70 | public function getCondition(string $name): Autowire |
71 | 71 | { |
72 | - if (!$this->hasCondition($name)) { |
|
72 | + if (!$this->hasCondition($name)){ |
|
73 | 73 | throw new ValidationException("Undefined condition `{$name}`."); |
74 | 74 | } |
75 | 75 | |
76 | 76 | $instance = $this->wire('conditions', $name); |
77 | - if ($instance !== null) { |
|
77 | + if ($instance !== null){ |
|
78 | 78 | return $instance; |
79 | 79 | } |
80 | 80 | |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function mapFunction($function) |
92 | 92 | { |
93 | - if (is_string($function)) { |
|
93 | + if (is_string($function)){ |
|
94 | 94 | $function = $this->resolveAlias($function); |
95 | - if (strpos($function, ':') !== false) { |
|
95 | + if (strpos($function, ':') !== false){ |
|
96 | 96 | $function = explode(':', $function); |
97 | 97 | } |
98 | 98 | } |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | |
103 | 103 | private function wire(string $section, string $name): ?Autowire |
104 | 104 | { |
105 | - if (is_string($this->config[$section][$name])) { |
|
105 | + if (is_string($this->config[$section][$name])){ |
|
106 | 106 | return new Autowire($this->config[$section][$name]); |
107 | 107 | } |
108 | 108 | |
109 | - if (isset($this->config[$section][$name]['class'])) { |
|
109 | + if (isset($this->config[$section][$name]['class'])){ |
|
110 | 110 | return new Autowire( |
111 | 111 | $this->config[$section][$name]['class'], |
112 | 112 | $this->config[$section][$name]['options'] ?? [] |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | public function __construct(array $config = []) |
35 | 35 | { |
36 | 36 | parent::__construct($config); |
37 | - if (!empty($this->config['aliases'])) { |
|
37 | + if (!empty($this->config['aliases'])) |
|
38 | + { |
|
38 | 39 | $this->config['aliases'] = $this->normalizeAliases($this->config['aliases']); |
39 | 40 | } |
40 | 41 | } |
@@ -50,12 +51,14 @@ discard block |
||
50 | 51 | */ |
51 | 52 | public function getChecker(string $name): Autowire |
52 | 53 | { |
53 | - if (!$this->hasChecker($name)) { |
|
54 | + if (!$this->hasChecker($name)) |
|
55 | + { |
|
54 | 56 | throw new ValidationException("Undefined checker `{$name}``."); |
55 | 57 | } |
56 | 58 | |
57 | 59 | $instance = $this->wire('checkers', $name); |
58 | - if ($instance !== null) { |
|
60 | + if ($instance !== null) |
|
61 | + { |
|
59 | 62 | return $instance; |
60 | 63 | } |
61 | 64 | |
@@ -69,12 +72,14 @@ discard block |
||
69 | 72 | |
70 | 73 | public function getCondition(string $name): Autowire |
71 | 74 | { |
72 | - if (!$this->hasCondition($name)) { |
|
75 | + if (!$this->hasCondition($name)) |
|
76 | + { |
|
73 | 77 | throw new ValidationException("Undefined condition `{$name}`."); |
74 | 78 | } |
75 | 79 | |
76 | 80 | $instance = $this->wire('conditions', $name); |
77 | - if ($instance !== null) { |
|
81 | + if ($instance !== null) |
|
82 | + { |
|
78 | 83 | return $instance; |
79 | 84 | } |
80 | 85 | |
@@ -90,9 +95,11 @@ discard block |
||
90 | 95 | */ |
91 | 96 | public function mapFunction($function) |
92 | 97 | { |
93 | - if (is_string($function)) { |
|
98 | + if (is_string($function)) |
|
99 | + { |
|
94 | 100 | $function = $this->resolveAlias($function); |
95 | - if (strpos($function, ':') !== false) { |
|
101 | + if (strpos($function, ':') !== false) |
|
102 | + { |
|
96 | 103 | $function = explode(':', $function); |
97 | 104 | } |
98 | 105 | } |
@@ -102,11 +109,13 @@ discard block |
||
102 | 109 | |
103 | 110 | private function wire(string $section, string $name): ?Autowire |
104 | 111 | { |
105 | - if (is_string($this->config[$section][$name])) { |
|
112 | + if (is_string($this->config[$section][$name])) |
|
113 | + { |
|
106 | 114 | return new Autowire($this->config[$section][$name]); |
107 | 115 | } |
108 | 116 | |
109 | - if (isset($this->config[$section][$name]['class'])) { |
|
117 | + if (isset($this->config[$section][$name]['class'])) |
|
118 | + { |
|
110 | 119 | return new Autowire( |
111 | 120 | $this->config[$section][$name]['class'], |
112 | 121 | $this->config[$section][$name]['options'] ?? [] |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | |
59 | 59 | private function validateBoundaries(Boundary $from, Boundary $to): void |
60 | 60 | { |
61 | - if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)) { |
|
61 | + if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)){ |
|
62 | 62 | throw new ValueException('Range boundaries should be applicable via passed type.'); |
63 | 63 | } |
64 | 64 | |
65 | - if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)) { |
|
65 | + if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)){ |
|
66 | 66 | throw new ValueException('Range boundaries should be different.'); |
67 | 67 | } |
68 | 68 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | private function acceptsFrom($value): bool |
87 | 87 | { |
88 | - if ($this->from->empty) { |
|
88 | + if ($this->from->empty){ |
|
89 | 89 | return true; |
90 | 90 | } |
91 | 91 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | private function acceptsTo($value): bool |
101 | 101 | { |
102 | - if ($this->to->empty) { |
|
102 | + if ($this->to->empty){ |
|
103 | 103 | return true; |
104 | 104 | } |
105 | 105 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | private function setBoundaries(Boundary $from, Boundary $to): void |
112 | 112 | { |
113 | 113 | //Swap if from < to and both not empty |
114 | - if (!$from->empty && !$to->empty && $from->value > $to->value) { |
|
114 | + if (!$from->empty && !$to->empty && $from->value > $to->value){ |
|
115 | 115 | [$from, $to] = [$to, $from]; |
116 | 116 | } |
117 | 117 |
@@ -58,11 +58,13 @@ discard block |
||
58 | 58 | |
59 | 59 | private function validateBoundaries(Boundary $from, Boundary $to): void |
60 | 60 | { |
61 | - if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)) { |
|
61 | + if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)) |
|
62 | + { |
|
62 | 63 | throw new ValueException('Range boundaries should be applicable via passed type.'); |
63 | 64 | } |
64 | 65 | |
65 | - if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)) { |
|
66 | + if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)) |
|
67 | + { |
|
66 | 68 | throw new ValueException('Range boundaries should be different.'); |
67 | 69 | } |
68 | 70 | } |
@@ -85,7 +87,8 @@ discard block |
||
85 | 87 | */ |
86 | 88 | private function acceptsFrom($value): bool |
87 | 89 | { |
88 | - if ($this->from->empty) { |
|
90 | + if ($this->from->empty) |
|
91 | + { |
|
89 | 92 | return true; |
90 | 93 | } |
91 | 94 | |
@@ -99,7 +102,8 @@ discard block |
||
99 | 102 | */ |
100 | 103 | private function acceptsTo($value): bool |
101 | 104 | { |
102 | - if ($this->to->empty) { |
|
105 | + if ($this->to->empty) |
|
106 | + { |
|
103 | 107 | return true; |
104 | 108 | } |
105 | 109 | |
@@ -111,7 +115,8 @@ discard block |
||
111 | 115 | private function setBoundaries(Boundary $from, Boundary $to): void |
112 | 116 | { |
113 | 117 | //Swap if from < to and both not empty |
114 | - if (!$from->empty && !$to->empty && $from->value > $to->value) { |
|
118 | + if (!$from->empty && !$to->empty && $from->value > $to->value) |
|
119 | + { |
|
115 | 120 | [$from, $to] = [$to, $from]; |
116 | 121 | } |
117 | 122 |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function __construct(array $items = []) |
37 | 37 | { |
38 | - foreach ($items as $item) { |
|
38 | + foreach ($items as $item){ |
|
39 | 39 | $this->addItem($item); |
40 | 40 | } |
41 | 41 | } |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | $header = new static(); |
51 | 51 | |
52 | 52 | $parts = explode(',', $raw); |
53 | - foreach ($parts as $part) { |
|
53 | + foreach ($parts as $part){ |
|
54 | 54 | $part = trim($part); |
55 | - if ($part !== '') { |
|
55 | + if ($part !== ''){ |
|
56 | 56 | $header->addItem($part); |
57 | 57 | } |
58 | 58 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function getAll(): array |
88 | 88 | { |
89 | - if (!$this->sorted) { |
|
89 | + if (!$this->sorted){ |
|
90 | 90 | /** |
91 | 91 | * Sort item in descending order. |
92 | 92 | */ |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | */ |
106 | 106 | private function addItem($item): void |
107 | 107 | { |
108 | - if (is_scalar($item)) { |
|
108 | + if (is_scalar($item)){ |
|
109 | 109 | $item = AcceptHeaderItem::fromString((string)$item); |
110 | 110 | } |
111 | 111 | |
112 | 112 | /** @var AcceptHeaderItem|array $item */ |
113 | - if (!$item instanceof AcceptHeaderItem) { |
|
113 | + if (!$item instanceof AcceptHeaderItem){ |
|
114 | 114 | throw new AcceptHeaderException(sprintf( |
115 | 115 | 'Accept Header item expected to be an instance of `%s` or a string, got `%s`', |
116 | 116 | AcceptHeaderItem::class, |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | $value = strtolower($item->getValue()); |
122 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
122 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)){ |
|
123 | 123 | $this->sorted = false; |
124 | 124 | $this->items[$value] = $item; |
125 | 125 | } |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | */ |
135 | 135 | private static function compare(AcceptHeaderItem $a, AcceptHeaderItem $b): int |
136 | 136 | { |
137 | - if ($a->getQuality() === $b->getQuality()) { |
|
137 | + if ($a->getQuality() === $b->getQuality()){ |
|
138 | 138 | // If quality are same value with more params has more weight. |
139 | - if (count($a->getParams()) === count($b->getParams())) { |
|
139 | + if (count($a->getParams()) === count($b->getParams())){ |
|
140 | 140 | // If quality and params then check for specific type or subtype. |
141 | 141 | // Means */* or * has less weight. |
142 | 142 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -155,11 +155,11 @@ discard block |
||
155 | 155 | private static function compareValue(string $a, string $b): int |
156 | 156 | { |
157 | 157 | // Check "Accept" headers values with it is type and subtype. |
158 | - if (strpos($a, '/') !== false && strpos($b, '/') !== false) { |
|
158 | + if (strpos($a, '/') !== false && strpos($b, '/') !== false){ |
|
159 | 159 | [$typeA, $subtypeA] = explode('/', $a, 2); |
160 | 160 | [$typeB, $subtypeB] = explode('/', $b, 2); |
161 | 161 | |
162 | - if ($typeA === $typeB) { |
|
162 | + if ($typeA === $typeB){ |
|
163 | 163 | return static::compareAtomic($subtypeA, $subtypeB); |
164 | 164 | } |
165 | 165 | |
@@ -171,23 +171,23 @@ discard block |
||
171 | 171 | |
172 | 172 | private static function compareAtomic(string $a, string $b): int |
173 | 173 | { |
174 | - if (mb_strpos($a, '*/') === 0) { |
|
174 | + if (mb_strpos($a, '*/') === 0){ |
|
175 | 175 | $a = '*'; |
176 | 176 | } |
177 | 177 | |
178 | - if (mb_strpos($b, '*/') === 0) { |
|
178 | + if (mb_strpos($b, '*/') === 0){ |
|
179 | 179 | $b = '*'; |
180 | 180 | } |
181 | 181 | |
182 | - if (strtolower($a) === strtolower($b)) { |
|
182 | + if (strtolower($a) === strtolower($b)){ |
|
183 | 183 | return 0; |
184 | 184 | } |
185 | 185 | |
186 | - if ($a === '*') { |
|
186 | + if ($a === '*'){ |
|
187 | 187 | return -1; |
188 | 188 | } |
189 | 189 | |
190 | - if ($b === '*') { |
|
190 | + if ($b === '*'){ |
|
191 | 191 | return 1; |
192 | 192 | } |
193 | 193 |
@@ -35,7 +35,8 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function __construct(array $items = []) |
37 | 37 | { |
38 | - foreach ($items as $item) { |
|
38 | + foreach ($items as $item) |
|
39 | + { |
|
39 | 40 | $this->addItem($item); |
40 | 41 | } |
41 | 42 | } |
@@ -50,9 +51,11 @@ discard block |
||
50 | 51 | $header = new static(); |
51 | 52 | |
52 | 53 | $parts = explode(',', $raw); |
53 | - foreach ($parts as $part) { |
|
54 | + foreach ($parts as $part) |
|
55 | + { |
|
54 | 56 | $part = trim($part); |
55 | - if ($part !== '') { |
|
57 | + if ($part !== '') |
|
58 | + { |
|
56 | 59 | $header->addItem($part); |
57 | 60 | } |
58 | 61 | } |
@@ -86,7 +89,8 @@ discard block |
||
86 | 89 | */ |
87 | 90 | public function getAll(): array |
88 | 91 | { |
89 | - if (!$this->sorted) { |
|
92 | + if (!$this->sorted) |
|
93 | + { |
|
90 | 94 | /** |
91 | 95 | * Sort item in descending order. |
92 | 96 | */ |
@@ -105,12 +109,14 @@ discard block |
||
105 | 109 | */ |
106 | 110 | private function addItem($item): void |
107 | 111 | { |
108 | - if (is_scalar($item)) { |
|
112 | + if (is_scalar($item)) |
|
113 | + { |
|
109 | 114 | $item = AcceptHeaderItem::fromString((string)$item); |
110 | 115 | } |
111 | 116 | |
112 | 117 | /** @var AcceptHeaderItem|array $item */ |
113 | - if (!$item instanceof AcceptHeaderItem) { |
|
118 | + if (!$item instanceof AcceptHeaderItem) |
|
119 | + { |
|
114 | 120 | throw new AcceptHeaderException(sprintf( |
115 | 121 | 'Accept Header item expected to be an instance of `%s` or a string, got `%s`', |
116 | 122 | AcceptHeaderItem::class, |
@@ -119,7 +125,8 @@ discard block |
||
119 | 125 | } |
120 | 126 | |
121 | 127 | $value = strtolower($item->getValue()); |
122 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
128 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) |
|
129 | + { |
|
123 | 130 | $this->sorted = false; |
124 | 131 | $this->items[$value] = $item; |
125 | 132 | } |
@@ -134,9 +141,11 @@ discard block |
||
134 | 141 | */ |
135 | 142 | private static function compare(AcceptHeaderItem $a, AcceptHeaderItem $b): int |
136 | 143 | { |
137 | - if ($a->getQuality() === $b->getQuality()) { |
|
144 | + if ($a->getQuality() === $b->getQuality()) |
|
145 | + { |
|
138 | 146 | // If quality are same value with more params has more weight. |
139 | - if (count($a->getParams()) === count($b->getParams())) { |
|
147 | + if (count($a->getParams()) === count($b->getParams())) |
|
148 | + { |
|
140 | 149 | // If quality and params then check for specific type or subtype. |
141 | 150 | // Means */* or * has less weight. |
142 | 151 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -155,11 +164,13 @@ discard block |
||
155 | 164 | private static function compareValue(string $a, string $b): int |
156 | 165 | { |
157 | 166 | // Check "Accept" headers values with it is type and subtype. |
158 | - if (strpos($a, '/') !== false && strpos($b, '/') !== false) { |
|
167 | + if (strpos($a, '/') !== false && strpos($b, '/') !== false) |
|
168 | + { |
|
159 | 169 | [$typeA, $subtypeA] = explode('/', $a, 2); |
160 | 170 | [$typeB, $subtypeB] = explode('/', $b, 2); |
161 | 171 | |
162 | - if ($typeA === $typeB) { |
|
172 | + if ($typeA === $typeB) |
|
173 | + { |
|
163 | 174 | return static::compareAtomic($subtypeA, $subtypeB); |
164 | 175 | } |
165 | 176 | |
@@ -171,23 +182,28 @@ discard block |
||
171 | 182 | |
172 | 183 | private static function compareAtomic(string $a, string $b): int |
173 | 184 | { |
174 | - if (mb_strpos($a, '*/') === 0) { |
|
185 | + if (mb_strpos($a, '*/') === 0) |
|
186 | + { |
|
175 | 187 | $a = '*'; |
176 | 188 | } |
177 | 189 | |
178 | - if (mb_strpos($b, '*/') === 0) { |
|
190 | + if (mb_strpos($b, '*/') === 0) |
|
191 | + { |
|
179 | 192 | $b = '*'; |
180 | 193 | } |
181 | 194 | |
182 | - if (strtolower($a) === strtolower($b)) { |
|
195 | + if (strtolower($a) === strtolower($b)) |
|
196 | + { |
|
183 | 197 | return 0; |
184 | 198 | } |
185 | 199 | |
186 | - if ($a === '*') { |
|
200 | + if ($a === '*') |
|
201 | + { |
|
187 | 202 | return -1; |
188 | 203 | } |
189 | 204 | |
190 | - if ($b === '*') { |
|
205 | + if ($b === '*') |
|
206 | + { |
|
191 | 207 | return 1; |
192 | 208 | } |
193 | 209 |
@@ -65,12 +65,14 @@ |
||
65 | 65 | */ |
66 | 66 | public function handle(Request $request): Response |
67 | 67 | { |
68 | - if (empty($this->handler)) { |
|
68 | + if (empty($this->handler)) |
|
69 | + { |
|
69 | 70 | throw new PipelineException('Unable to run pipeline, no handler given.'); |
70 | 71 | } |
71 | 72 | |
72 | 73 | $position = $this->position++; |
73 | - if (isset($this->middleware[$position])) { |
|
74 | + if (isset($this->middleware[$position])) |
|
75 | + { |
|
74 | 76 | return $this->middleware[$position]->process($request, $this); |
75 | 77 | } |
76 | 78 |
@@ -34,11 +34,11 @@ |
||
34 | 34 | */ |
35 | 35 | public function __construct(?int $code = null, string $message = '', ?Throwable $previous = null) |
36 | 36 | { |
37 | - if (empty($code) && empty($this->code)) { |
|
37 | + if (empty($code) && empty($this->code)){ |
|
38 | 38 | $code = self::BAD_DATA; |
39 | 39 | } |
40 | 40 | |
41 | - if (empty($message)) { |
|
41 | + if (empty($message)){ |
|
42 | 42 | $message = "Http Error - {$code}"; |
43 | 43 | } |
44 | 44 |
@@ -34,11 +34,13 @@ |
||
34 | 34 | */ |
35 | 35 | public function __construct(?int $code = null, string $message = '', ?Throwable $previous = null) |
36 | 36 | { |
37 | - if (empty($code) && empty($this->code)) { |
|
37 | + if (empty($code) && empty($this->code)) |
|
38 | + { |
|
38 | 39 | $code = self::BAD_DATA; |
39 | 40 | } |
40 | 41 | |
41 | - if (empty($message)) { |
|
42 | + if (empty($message)) |
|
43 | + { |
|
42 | 44 | $message = "Http Error - {$code}"; |
43 | 45 | } |
44 | 46 |
@@ -49,21 +49,21 @@ discard block |
||
49 | 49 | $output = $result = null; |
50 | 50 | |
51 | 51 | $response = $this->responseFactory->createResponse(200); |
52 | - try { |
|
52 | + try{ |
|
53 | 53 | $result = ($this->callable)($request, $response); |
54 | - } catch (Throwable $e) { |
|
54 | + }catch (Throwable $e){ |
|
55 | 55 | ob_get_clean(); |
56 | 56 | throw $e; |
57 | - } finally { |
|
58 | - while (ob_get_level() > $outputLevel + 1) { |
|
59 | - $output = ob_get_clean() . $output; |
|
57 | + }finally{ |
|
58 | + while (ob_get_level() > $outputLevel + 1){ |
|
59 | + $output = ob_get_clean().$output; |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
63 | 63 | return $this->wrapResponse( |
64 | 64 | $response, |
65 | 65 | $result, |
66 | - ob_get_clean() . $output |
|
66 | + ob_get_clean().$output |
|
67 | 67 | ); |
68 | 68 | } |
69 | 69 | |
@@ -76,17 +76,17 @@ discard block |
||
76 | 76 | */ |
77 | 77 | private function wrapResponse(Response $response, $result = null, string $output = ''): Response |
78 | 78 | { |
79 | - if ($result instanceof Response) { |
|
80 | - if (!empty($output) && $result->getBody()->isWritable()) { |
|
79 | + if ($result instanceof Response){ |
|
80 | + if (!empty($output) && $result->getBody()->isWritable()){ |
|
81 | 81 | $result->getBody()->write($output); |
82 | 82 | } |
83 | 83 | |
84 | 84 | return $result; |
85 | 85 | } |
86 | 86 | |
87 | - if (is_array($result) || $result instanceof JsonSerializable) { |
|
87 | + if (is_array($result) || $result instanceof JsonSerializable){ |
|
88 | 88 | $response = $this->writeJson($response, $result); |
89 | - } else { |
|
89 | + }else{ |
|
90 | 90 | $response->getBody()->write((string)$result); |
91 | 91 | } |
92 | 92 |
@@ -49,13 +49,19 @@ discard block |
||
49 | 49 | $output = $result = null; |
50 | 50 | |
51 | 51 | $response = $this->responseFactory->createResponse(200); |
52 | - try { |
|
52 | + try |
|
53 | + { |
|
53 | 54 | $result = ($this->callable)($request, $response); |
54 | - } catch (Throwable $e) { |
|
55 | + } |
|
56 | + catch (Throwable $e) |
|
57 | + { |
|
55 | 58 | ob_get_clean(); |
56 | 59 | throw $e; |
57 | - } finally { |
|
58 | - while (ob_get_level() > $outputLevel + 1) { |
|
60 | + } |
|
61 | + finally |
|
62 | + { |
|
63 | + while (ob_get_level() > $outputLevel + 1) |
|
64 | + { |
|
59 | 65 | $output = ob_get_clean() . $output; |
60 | 66 | } |
61 | 67 | } |
@@ -76,17 +82,22 @@ discard block |
||
76 | 82 | */ |
77 | 83 | private function wrapResponse(Response $response, $result = null, string $output = ''): Response |
78 | 84 | { |
79 | - if ($result instanceof Response) { |
|
80 | - if (!empty($output) && $result->getBody()->isWritable()) { |
|
85 | + if ($result instanceof Response) |
|
86 | + { |
|
87 | + if (!empty($output) && $result->getBody()->isWritable()) |
|
88 | + { |
|
81 | 89 | $result->getBody()->write($output); |
82 | 90 | } |
83 | 91 | |
84 | 92 | return $result; |
85 | 93 | } |
86 | 94 | |
87 | - if (is_array($result) || $result instanceof JsonSerializable) { |
|
95 | + if (is_array($result) || $result instanceof JsonSerializable) |
|
96 | + { |
|
88 | 97 | $response = $this->writeJson($response, $result); |
89 | - } else { |
|
98 | + } |
|
99 | + else |
|
100 | + { |
|
90 | 101 | $response->getBody()->write((string)$result); |
91 | 102 | } |
92 | 103 |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | UriFactoryInterface $uriFactory, |
70 | 70 | StreamFactoryInterface $streamFactory, |
71 | 71 | UploadedFileFactoryInterface $uploadedFileFactory |
72 | - ) { |
|
72 | + ){ |
|
73 | 73 | $this->requestFactory = $requestFactory; |
74 | 74 | $this->uriFactory = $uriFactory; |
75 | 75 | $this->streamFactory = $streamFactory; |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | $uri = $this->getUri($server); |
107 | 107 | |
108 | 108 | $request = $this->requestFactory->createServerRequest($method, $uri, $server); |
109 | - foreach ($headers as $name => $value) { |
|
109 | + foreach ($headers as $name => $value){ |
|
110 | 110 | $request = $request->withAddedHeader($name, $value); |
111 | 111 | } |
112 | 112 | |
113 | 113 | $protocol = '1.1'; |
114 | - if (!empty($_SERVER['SERVER_PROTOCOL'])) { |
|
114 | + if (!empty($_SERVER['SERVER_PROTOCOL'])){ |
|
115 | 115 | $protocol = str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']); |
116 | 116 | } |
117 | 117 | |
@@ -122,15 +122,15 @@ discard block |
||
122 | 122 | ->withCookieParams($cookies) |
123 | 123 | ->withUploadedFiles($this->getUploadedFilesArray($files)); |
124 | 124 | |
125 | - if ($body === null) { |
|
125 | + if ($body === null){ |
|
126 | 126 | return $request; |
127 | 127 | } |
128 | 128 | |
129 | - if (\is_resource($body)) { |
|
129 | + if (\is_resource($body)){ |
|
130 | 130 | $body = $this->streamFactory->createStreamFromResource($body); |
131 | - } elseif (\is_string($body)) { |
|
131 | + } elseif (\is_string($body)){ |
|
132 | 132 | $body = $this->streamFactory->createStream($body); |
133 | - } elseif (!$body instanceof StreamInterface) { |
|
133 | + } elseif (!$body instanceof StreamInterface){ |
|
134 | 134 | throw new InvalidArgumentException( |
135 | 135 | 'Body parameter for ServerRequestFactory::createFromParameters() ' |
136 | 136 | . 'must be instance of StreamInterface, resource or null.' |
@@ -143,29 +143,29 @@ discard block |
||
143 | 143 | private function getUri(array $server): UriInterface |
144 | 144 | { |
145 | 145 | $uri = $this->uriFactory->createUri(); |
146 | - if (isset($server['HTTPS'])) { |
|
146 | + if (isset($server['HTTPS'])){ |
|
147 | 147 | $uri = $uri->withScheme($server['HTTPS'] === 'on' ? 'https' : 'http'); |
148 | 148 | } |
149 | 149 | |
150 | - if (isset($server['HTTP_HOST'])) { |
|
151 | - if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) { |
|
150 | + if (isset($server['HTTP_HOST'])){ |
|
151 | + if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)){ |
|
152 | 152 | $uri = $uri->withHost($matches[1])->withPort($matches[2]); |
153 | - } else { |
|
153 | + }else{ |
|
154 | 154 | $uri = $uri->withHost($server['HTTP_HOST']); |
155 | 155 | } |
156 | - } elseif (isset($server['SERVER_NAME'])) { |
|
156 | + } elseif (isset($server['SERVER_NAME'])){ |
|
157 | 157 | $uri = $uri->withHost($server['SERVER_NAME']); |
158 | 158 | } |
159 | 159 | |
160 | - if (isset($server['SERVER_PORT'])) { |
|
160 | + if (isset($server['SERVER_PORT'])){ |
|
161 | 161 | $uri = $uri->withPort($server['SERVER_PORT']); |
162 | 162 | } |
163 | 163 | |
164 | - if (isset($server['REQUEST_URI'])) { |
|
164 | + if (isset($server['REQUEST_URI'])){ |
|
165 | 165 | $uri = $uri->withPath(\explode('?', $server['REQUEST_URI'])[0]); |
166 | 166 | } |
167 | 167 | |
168 | - if (isset($server['QUERY_STRING'])) { |
|
168 | + if (isset($server['QUERY_STRING'])){ |
|
169 | 169 | $uri = $uri->withQuery($server['QUERY_STRING']); |
170 | 170 | } |
171 | 171 | |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | |
175 | 175 | private static function getHeadersFromGlobals(): array |
176 | 176 | { |
177 | - if (\function_exists('getallheaders')) { |
|
177 | + if (\function_exists('getallheaders')){ |
|
178 | 178 | $headers = getallheaders(); |
179 | - } else { |
|
179 | + }else{ |
|
180 | 180 | $headers = []; |
181 | - foreach ($_SERVER as $name => $value) { |
|
182 | - if (strncmp($name, 'HTTP_', 5) === 0) { |
|
181 | + foreach ($_SERVER as $name => $value){ |
|
182 | + if (strncmp($name, 'HTTP_', 5) === 0){ |
|
183 | 183 | $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); |
184 | 184 | $headers[$name] = $value; |
185 | 185 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | private function getUploadedFilesArray(array $filesArray): array |
193 | 193 | { |
194 | 194 | $files = []; |
195 | - foreach ($filesArray as $class => $info) { |
|
195 | + foreach ($filesArray as $class => $info){ |
|
196 | 196 | $files[$class] = []; |
197 | 197 | $this->populateUploadedFileRecursive( |
198 | 198 | $files[$class], |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | */ |
221 | 221 | private function populateUploadedFileRecursive(&$files, $names, $tempNames, $types, $sizes, $errors): void |
222 | 222 | { |
223 | - if (\is_array($names)) { |
|
224 | - foreach ($names as $i => $name) { |
|
223 | + if (\is_array($names)){ |
|
224 | + foreach ($names as $i => $name){ |
|
225 | 225 | $files[$i] = []; |
226 | 226 | $this->populateUploadedFileRecursive( |
227 | 227 | $files[$i], |
@@ -232,10 +232,10 @@ discard block |
||
232 | 232 | $errors[$i] |
233 | 233 | ); |
234 | 234 | } |
235 | - } else { |
|
236 | - try { |
|
235 | + }else{ |
|
236 | + try{ |
|
237 | 237 | $stream = $this->streamFactory->createStreamFromFile($tempNames); |
238 | - } catch (RuntimeException $e) { |
|
238 | + }catch (RuntimeException $e){ |
|
239 | 239 | $stream = $this->streamFactory->createStream(); |
240 | 240 | } |
241 | 241 |
@@ -106,12 +106,14 @@ discard block |
||
106 | 106 | $uri = $this->getUri($server); |
107 | 107 | |
108 | 108 | $request = $this->requestFactory->createServerRequest($method, $uri, $server); |
109 | - foreach ($headers as $name => $value) { |
|
109 | + foreach ($headers as $name => $value) |
|
110 | + { |
|
110 | 111 | $request = $request->withAddedHeader($name, $value); |
111 | 112 | } |
112 | 113 | |
113 | 114 | $protocol = '1.1'; |
114 | - if (!empty($_SERVER['SERVER_PROTOCOL'])) { |
|
115 | + if (!empty($_SERVER['SERVER_PROTOCOL'])) |
|
116 | + { |
|
115 | 117 | $protocol = str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']); |
116 | 118 | } |
117 | 119 | |
@@ -122,15 +124,21 @@ discard block |
||
122 | 124 | ->withCookieParams($cookies) |
123 | 125 | ->withUploadedFiles($this->getUploadedFilesArray($files)); |
124 | 126 | |
125 | - if ($body === null) { |
|
127 | + if ($body === null) |
|
128 | + { |
|
126 | 129 | return $request; |
127 | 130 | } |
128 | 131 | |
129 | - if (\is_resource($body)) { |
|
132 | + if (\is_resource($body)) |
|
133 | + { |
|
130 | 134 | $body = $this->streamFactory->createStreamFromResource($body); |
131 | - } elseif (\is_string($body)) { |
|
135 | + } |
|
136 | + elseif (\is_string($body)) |
|
137 | + { |
|
132 | 138 | $body = $this->streamFactory->createStream($body); |
133 | - } elseif (!$body instanceof StreamInterface) { |
|
139 | + } |
|
140 | + elseif (!$body instanceof StreamInterface) |
|
141 | + { |
|
134 | 142 | throw new InvalidArgumentException( |
135 | 143 | 'Body parameter for ServerRequestFactory::createFromParameters() ' |
136 | 144 | . 'must be instance of StreamInterface, resource or null.' |
@@ -143,29 +151,39 @@ discard block |
||
143 | 151 | private function getUri(array $server): UriInterface |
144 | 152 | { |
145 | 153 | $uri = $this->uriFactory->createUri(); |
146 | - if (isset($server['HTTPS'])) { |
|
154 | + if (isset($server['HTTPS'])) |
|
155 | + { |
|
147 | 156 | $uri = $uri->withScheme($server['HTTPS'] === 'on' ? 'https' : 'http'); |
148 | 157 | } |
149 | 158 | |
150 | - if (isset($server['HTTP_HOST'])) { |
|
151 | - if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) { |
|
159 | + if (isset($server['HTTP_HOST'])) |
|
160 | + { |
|
161 | + if (1 === \preg_match('/^(.+)\:(\d+)$/', $server['HTTP_HOST'], $matches)) |
|
162 | + { |
|
152 | 163 | $uri = $uri->withHost($matches[1])->withPort($matches[2]); |
153 | - } else { |
|
164 | + } |
|
165 | + else |
|
166 | + { |
|
154 | 167 | $uri = $uri->withHost($server['HTTP_HOST']); |
155 | 168 | } |
156 | - } elseif (isset($server['SERVER_NAME'])) { |
|
169 | + } |
|
170 | + elseif (isset($server['SERVER_NAME'])) |
|
171 | + { |
|
157 | 172 | $uri = $uri->withHost($server['SERVER_NAME']); |
158 | 173 | } |
159 | 174 | |
160 | - if (isset($server['SERVER_PORT'])) { |
|
175 | + if (isset($server['SERVER_PORT'])) |
|
176 | + { |
|
161 | 177 | $uri = $uri->withPort($server['SERVER_PORT']); |
162 | 178 | } |
163 | 179 | |
164 | - if (isset($server['REQUEST_URI'])) { |
|
180 | + if (isset($server['REQUEST_URI'])) |
|
181 | + { |
|
165 | 182 | $uri = $uri->withPath(\explode('?', $server['REQUEST_URI'])[0]); |
166 | 183 | } |
167 | 184 | |
168 | - if (isset($server['QUERY_STRING'])) { |
|
185 | + if (isset($server['QUERY_STRING'])) |
|
186 | + { |
|
169 | 187 | $uri = $uri->withQuery($server['QUERY_STRING']); |
170 | 188 | } |
171 | 189 | |
@@ -174,12 +192,17 @@ discard block |
||
174 | 192 | |
175 | 193 | private static function getHeadersFromGlobals(): array |
176 | 194 | { |
177 | - if (\function_exists('getallheaders')) { |
|
195 | + if (\function_exists('getallheaders')) |
|
196 | + { |
|
178 | 197 | $headers = getallheaders(); |
179 | - } else { |
|
198 | + } |
|
199 | + else |
|
200 | + { |
|
180 | 201 | $headers = []; |
181 | - foreach ($_SERVER as $name => $value) { |
|
182 | - if (strncmp($name, 'HTTP_', 5) === 0) { |
|
202 | + foreach ($_SERVER as $name => $value) |
|
203 | + { |
|
204 | + if (strncmp($name, 'HTTP_', 5) === 0) |
|
205 | + { |
|
183 | 206 | $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); |
184 | 207 | $headers[$name] = $value; |
185 | 208 | } |
@@ -192,7 +215,8 @@ discard block |
||
192 | 215 | private function getUploadedFilesArray(array $filesArray): array |
193 | 216 | { |
194 | 217 | $files = []; |
195 | - foreach ($filesArray as $class => $info) { |
|
218 | + foreach ($filesArray as $class => $info) |
|
219 | + { |
|
196 | 220 | $files[$class] = []; |
197 | 221 | $this->populateUploadedFileRecursive( |
198 | 222 | $files[$class], |
@@ -220,8 +244,10 @@ discard block |
||
220 | 244 | */ |
221 | 245 | private function populateUploadedFileRecursive(&$files, $names, $tempNames, $types, $sizes, $errors): void |
222 | 246 | { |
223 | - if (\is_array($names)) { |
|
224 | - foreach ($names as $i => $name) { |
|
247 | + if (\is_array($names)) |
|
248 | + { |
|
249 | + foreach ($names as $i => $name) |
|
250 | + { |
|
225 | 251 | $files[$i] = []; |
226 | 252 | $this->populateUploadedFileRecursive( |
227 | 253 | $files[$i], |
@@ -232,10 +258,15 @@ discard block |
||
232 | 258 | $errors[$i] |
233 | 259 | ); |
234 | 260 | } |
235 | - } else { |
|
236 | - try { |
|
261 | + } |
|
262 | + else |
|
263 | + { |
|
264 | + try |
|
265 | + { |
|
237 | 266 | $stream = $this->streamFactory->createStreamFromFile($tempNames); |
238 | - } catch (RuntimeException $e) { |
|
267 | + } |
|
268 | + catch (RuntimeException $e) |
|
269 | + { |
|
239 | 270 | $stream = $this->streamFactory->createStream(); |
240 | 271 | } |
241 | 272 |