@@ -43,7 +43,8 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function stream_eof(): bool |
| 45 | 45 | { |
| 46 | - if ($this->stream === null) { |
|
| 46 | + if ($this->stream === null) |
|
| 47 | + { |
|
| 47 | 48 | throw new WrapperException('Stream is not opened.'); |
| 48 | 49 | } |
| 49 | 50 | |
@@ -55,7 +56,8 @@ discard block |
||
| 55 | 56 | */ |
| 56 | 57 | public function stream_open(string $path, string $mode): bool |
| 57 | 58 | { |
| 58 | - if (!isset(self::$uris[$path])) { |
|
| 59 | + if (!isset(self::$uris[$path])) |
|
| 60 | + { |
|
| 59 | 61 | return false; |
| 60 | 62 | } |
| 61 | 63 | |
@@ -72,7 +74,8 @@ discard block |
||
| 72 | 74 | */ |
| 73 | 75 | public function stream_read(int $length): string|false |
| 74 | 76 | { |
| 75 | - if ($this->stream === null) { |
|
| 77 | + if ($this->stream === null) |
|
| 78 | + { |
|
| 76 | 79 | throw new WrapperException('Stream is not opened.'); |
| 77 | 80 | } |
| 78 | 81 | |
@@ -84,7 +87,8 @@ discard block |
||
| 84 | 87 | */ |
| 85 | 88 | public function stream_seek(int $offset, int $whence = SEEK_SET): bool |
| 86 | 89 | { |
| 87 | - if ($this->stream === null) { |
|
| 90 | + if ($this->stream === null) |
|
| 91 | + { |
|
| 88 | 92 | throw new WrapperException('Stream is not opened.'); |
| 89 | 93 | } |
| 90 | 94 | |
@@ -102,7 +106,8 @@ discard block |
||
| 102 | 106 | */ |
| 103 | 107 | public function stream_stat(): array |
| 104 | 108 | { |
| 105 | - if ($this->stream === null) { |
|
| 109 | + if ($this->stream === null) |
|
| 110 | + { |
|
| 106 | 111 | throw new WrapperException('Stream is not opened.'); |
| 107 | 112 | } |
| 108 | 113 | |
@@ -114,7 +119,8 @@ discard block |
||
| 114 | 119 | */ |
| 115 | 120 | public function stream_tell(): int |
| 116 | 121 | { |
| 117 | - if ($this->stream === null) { |
|
| 122 | + if ($this->stream === null) |
|
| 123 | + { |
|
| 118 | 124 | throw new WrapperException('Stream is not opened.'); |
| 119 | 125 | } |
| 120 | 126 | |
@@ -128,7 +134,8 @@ discard block |
||
| 128 | 134 | */ |
| 129 | 135 | public function stream_write(string $data): int |
| 130 | 136 | { |
| 131 | - if ($this->stream === null) { |
|
| 137 | + if ($this->stream === null) |
|
| 138 | + { |
|
| 132 | 139 | throw new WrapperException('Stream is not opened.'); |
| 133 | 140 | } |
| 134 | 141 | |
@@ -142,12 +149,17 @@ discard block |
||
| 142 | 149 | */ |
| 143 | 150 | public function url_stat(string $path, int $flag): array|false |
| 144 | 151 | { |
| 145 | - try { |
|
| 146 | - if (isset(self::$uris[$path])) { |
|
| 152 | + try |
|
| 153 | + { |
|
| 154 | + if (isset(self::$uris[$path])) |
|
| 155 | + { |
|
| 147 | 156 | return $this->getStreamStats(self::$uris[$path]); |
| 148 | 157 | } |
| 149 | - } catch (\Throwable $e) { |
|
| 150 | - if (($flag & \STREAM_URL_STAT_QUIET) === \STREAM_URL_STAT_QUIET) { |
|
| 158 | + } |
|
| 159 | + catch (\Throwable $e) |
|
| 160 | + { |
|
| 161 | + if (($flag & \STREAM_URL_STAT_QUIET) === \STREAM_URL_STAT_QUIET) |
|
| 162 | + { |
|
| 151 | 163 | return false; |
| 152 | 164 | } |
| 153 | 165 | \trigger_error($e->getMessage(), \E_USER_ERROR); |
@@ -161,7 +173,8 @@ discard block |
||
| 161 | 173 | */ |
| 162 | 174 | public static function register(): void |
| 163 | 175 | { |
| 164 | - if (self::$registered) { |
|
| 176 | + if (self::$registered) |
|
| 177 | + { |
|
| 165 | 178 | return; |
| 166 | 179 | } |
| 167 | 180 | |
@@ -175,7 +188,8 @@ discard block |
||
| 175 | 188 | */ |
| 176 | 189 | public static function has(StreamInterface|string $file): bool |
| 177 | 190 | { |
| 178 | - if ($file instanceof StreamInterface) { |
|
| 191 | + if ($file instanceof StreamInterface) |
|
| 192 | + { |
|
| 179 | 193 | $file = 'spiral://' . \spl_object_hash($file); |
| 180 | 194 | } |
| 181 | 195 | |
@@ -191,15 +205,18 @@ discard block |
||
| 191 | 205 | public static function getResource(StreamInterface $stream) |
| 192 | 206 | { |
| 193 | 207 | $mode = null; |
| 194 | - if ($stream->isReadable()) { |
|
| 208 | + if ($stream->isReadable()) |
|
| 209 | + { |
|
| 195 | 210 | $mode = 'r'; |
| 196 | 211 | } |
| 197 | 212 | |
| 198 | - if ($stream->isWritable()) { |
|
| 213 | + if ($stream->isWritable()) |
|
| 214 | + { |
|
| 199 | 215 | $mode = !empty($mode) ? 'r+' : 'w'; |
| 200 | 216 | } |
| 201 | 217 | |
| 202 | - if (empty($mode)) { |
|
| 218 | + if (empty($mode)) |
|
| 219 | + { |
|
| 203 | 220 | throw new WrapperException('Stream is not available in read or write modes'); |
| 204 | 221 | } |
| 205 | 222 | |
@@ -227,7 +244,8 @@ discard block |
||
| 227 | 244 | */ |
| 228 | 245 | public static function release(StreamInterface|string $file): void |
| 229 | 246 | { |
| 230 | - if ($file instanceof StreamInterface) { |
|
| 247 | + if ($file instanceof StreamInterface) |
|
| 248 | + { |
|
| 231 | 249 | $file = 'spiral://' . \spl_object_hash($file); |
| 232 | 250 | } |
| 233 | 251 | |
@@ -240,12 +258,15 @@ discard block |
||
| 240 | 258 | private function getStreamStats(StreamInterface $stream): array |
| 241 | 259 | { |
| 242 | 260 | $mode = $this->mode; |
| 243 | - if (empty($mode)) { |
|
| 244 | - if ($stream->isReadable()) { |
|
| 261 | + if (empty($mode)) |
|
| 262 | + { |
|
| 263 | + if ($stream->isReadable()) |
|
| 264 | + { |
|
| 245 | 265 | $mode = 'r'; |
| 246 | 266 | } |
| 247 | 267 | |
| 248 | - if ($stream->isWritable()) { |
|
| 268 | + if ($stream->isWritable()) |
|
| 269 | + { |
|
| 249 | 270 | $mode = !empty($mode) ? 'r+' : 'w'; |
| 250 | 271 | } |
| 251 | 272 | } |
@@ -40,54 +40,78 @@ discard block |
||
| 40 | 40 | $optionalFilters = []; |
| 41 | 41 | $class = new \ReflectionClass($filter); |
| 42 | 42 | |
| 43 | - foreach ($class->getProperties() as $property) { |
|
| 43 | + foreach ($class->getProperties() as $property) |
|
| 44 | + { |
|
| 44 | 45 | /** @var object $attribute */ |
| 45 | - foreach ($this->reader->getPropertyMetadata($property) as $attribute) { |
|
| 46 | - if ($attribute instanceof AbstractInput) { |
|
| 46 | + foreach ($this->reader->getPropertyMetadata($property) as $attribute) |
|
| 47 | + { |
|
| 48 | + if ($attribute instanceof AbstractInput) |
|
| 49 | + { |
|
| 47 | 50 | $value = $attribute->getValue($input, $property); |
| 48 | - try { |
|
| 51 | + try |
|
| 52 | + { |
|
| 49 | 53 | $this->setValue($filter, $property, $value); |
| 50 | - } catch (SetterException $e) { |
|
| 54 | + } |
|
| 55 | + catch (SetterException $e) |
|
| 56 | + { |
|
| 51 | 57 | $errors[$property->getName()] = $this->createErrorMessage($e, $property, $value); |
| 52 | 58 | } |
| 53 | 59 | $schema[$property->getName()] = $attribute->getSchema($property); |
| 54 | - } elseif ($attribute instanceof NestedFilter) { |
|
| 60 | + } |
|
| 61 | + elseif ($attribute instanceof NestedFilter) |
|
| 62 | + { |
|
| 55 | 63 | $prefix = $attribute->prefix ?? $property->name; |
| 56 | - try { |
|
| 64 | + try |
|
| 65 | + { |
|
| 57 | 66 | $value = $this->provider->createFilter( |
| 58 | 67 | $attribute->class, |
| 59 | 68 | $input->withPrefix($prefix) |
| 60 | 69 | ); |
| 61 | 70 | |
| 62 | - try { |
|
| 71 | + try |
|
| 72 | + { |
|
| 63 | 73 | $this->setValue($filter, $property, $value); |
| 64 | - } catch (SetterException $e) { |
|
| 74 | + } |
|
| 75 | + catch (SetterException $e) |
|
| 76 | + { |
|
| 65 | 77 | $errors[$property->getName()] = $this->createErrorMessage($e, $property, $value); |
| 66 | 78 | } |
| 67 | - } catch (ValidationException $e) { |
|
| 68 | - if ($this->allowsNull($property)) { |
|
| 79 | + } |
|
| 80 | + catch (ValidationException $e) |
|
| 81 | + { |
|
| 82 | + if ($this->allowsNull($property)) |
|
| 83 | + { |
|
| 69 | 84 | $this->setValue($filter, $property, null); |
| 70 | 85 | $optionalFilters[] = $property->getName(); |
| 71 | - } else { |
|
| 86 | + } |
|
| 87 | + else |
|
| 88 | + { |
|
| 72 | 89 | $errors[$prefix] = $e->errors; |
| 73 | 90 | } |
| 74 | 91 | } |
| 75 | 92 | |
| 76 | 93 | $schema[$property->getName()] = $attribute->getSchema(); |
| 77 | - } elseif ($attribute instanceof NestedArray) { |
|
| 94 | + } |
|
| 95 | + elseif ($attribute instanceof NestedArray) |
|
| 96 | + { |
|
| 78 | 97 | $values = $attribute->getValue($input, $property); |
| 79 | 98 | $propertyValues = []; |
| 80 | 99 | |
| 81 | 100 | $prefix = $attribute->input->key ?? $attribute->prefix ?? $property->getName(); |
| 82 | 101 | |
| 83 | - if (\is_array($values)) { |
|
| 84 | - foreach (\array_keys($values) as $key) { |
|
| 85 | - try { |
|
| 102 | + if (\is_array($values)) |
|
| 103 | + { |
|
| 104 | + foreach (\array_keys($values) as $key) |
|
| 105 | + { |
|
| 106 | + try |
|
| 107 | + { |
|
| 86 | 108 | $propertyValues[$key] = $this->provider->createFilter( |
| 87 | 109 | $attribute->class, |
| 88 | 110 | $input->withPrefix($prefix . '.' . $key) |
| 89 | 111 | ); |
| 90 | - } catch (ValidationException $e) { |
|
| 112 | + } |
|
| 113 | + catch (ValidationException $e) |
|
| 114 | + { |
|
| 91 | 115 | /** @psalm-suppress InvalidArrayOffset */ |
| 92 | 116 | $errors[$property->getName()][$key] = $e->errors; |
| 93 | 117 | } |
@@ -96,7 +120,9 @@ discard block |
||
| 96 | 120 | |
| 97 | 121 | $this->setValue($filter, $property, $propertyValues); |
| 98 | 122 | $schema[$property->getName()] = [$attribute->class, $prefix . '.*']; |
| 99 | - } elseif ($attribute instanceof Setter) { |
|
| 123 | + } |
|
| 124 | + elseif ($attribute instanceof Setter) |
|
| 125 | + { |
|
| 100 | 126 | $setters[$property->getName()][] = $attribute; |
| 101 | 127 | } |
| 102 | 128 | } |
@@ -107,13 +133,15 @@ discard block |
||
| 107 | 133 | |
| 108 | 134 | private function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void |
| 109 | 135 | { |
| 110 | - if ($value === null) { |
|
| 136 | + if ($value === null) |
|
| 137 | + { |
|
| 111 | 138 | return; |
| 112 | 139 | } |
| 113 | 140 | |
| 114 | 141 | $setters = $this->reader->getPropertyMetadata($property, Setter::class); |
| 115 | 142 | |
| 116 | - foreach ($setters as $setter) { |
|
| 143 | + foreach ($setters as $setter) |
|
| 144 | + { |
|
| 117 | 145 | $value = $setter->updateValue($value); |
| 118 | 146 | } |
| 119 | 147 | |
@@ -134,7 +162,8 @@ discard block |
||
| 134 | 162 | ): string { |
| 135 | 163 | $attribute = $this->reader->firstPropertyMetadata($property, CastingErrorMessage::class); |
| 136 | 164 | |
| 137 | - if ($attribute === null) { |
|
| 165 | + if ($attribute === null) |
|
| 166 | + { |
|
| 138 | 167 | return $exception->getMessage(); |
| 139 | 168 | } |
| 140 | 169 | |
@@ -34,7 +34,8 @@ |
||
| 34 | 34 | |
| 35 | 35 | public function getSchema(): string|array |
| 36 | 36 | { |
| 37 | - if ($this->prefix) { |
|
| 37 | + if ($this->prefix) |
|
| 38 | + { |
|
| 38 | 39 | return [$this->class, $this->prefix]; |
| 39 | 40 | } |
| 40 | 41 | |
@@ -46,7 +46,8 @@ |
||
| 46 | 46 | |
| 47 | 47 | public function getSchema(): array |
| 48 | 48 | { |
| 49 | - if ($this->prefix) { |
|
| 49 | + if ($this->prefix) |
|
| 50 | + { |
|
| 50 | 51 | return [$this->class, $this->prefix]; |
| 51 | 52 | } |
| 52 | 53 | |