@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | #[Proxy] private readonly ContainerInterface $container, |
| 124 | 124 | /** @invisible */ |
| 125 | 125 | HttpConfig $config = new HttpConfig(), |
| 126 | - ) { |
|
| 126 | + ){ |
|
| 127 | 127 | $this->bagAssociations = \array_merge($this->bagAssociations, $config->getInputBags()); |
| 128 | 128 | } |
| 129 | 129 | |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | { |
| 135 | 135 | $input = clone $this; |
| 136 | 136 | |
| 137 | - if ($add) { |
|
| 138 | - $input->prefix .= '.' . $prefix; |
|
| 137 | + if ($add){ |
|
| 138 | + $input->prefix .= '.'.$prefix; |
|
| 139 | 139 | $input->prefix = \trim($input->prefix, '.'); |
| 140 | - } else { |
|
| 140 | + }else{ |
|
| 141 | 141 | $input->prefix = $prefix; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | return match (true) { |
| 155 | 155 | empty($path) => '/', |
| 156 | - $path[0] !== '/' => '/' . $path, |
|
| 156 | + $path[0] !== '/' => '/'.$path, |
|
| 157 | 157 | default => $path, |
| 158 | 158 | }; |
| 159 | 159 | } |
@@ -173,9 +173,9 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | public function request(): Request |
| 175 | 175 | { |
| 176 | - try { |
|
| 176 | + try{ |
|
| 177 | 177 | $request = $this->container->get(Request::class); |
| 178 | - } catch (ContainerExceptionInterface $e) { |
|
| 178 | + }catch (ContainerExceptionInterface $e){ |
|
| 179 | 179 | $scope = \implode('.', \array_reverse(Introspector::scopeNames($this->container))); |
| 180 | 180 | throw new ScopeException( |
| 181 | 181 | "Unable to get `ServerRequestInterface` in the `$scope` container scope", |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Flushing input state |
| 188 | - if ($this->request !== $request) { |
|
| 188 | + if ($this->request !== $request){ |
|
| 189 | 189 | $this->bags = []; |
| 190 | 190 | $this->request = $request; |
| 191 | 191 | } |
@@ -198,11 +198,11 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | public function bearerToken(): ?string |
| 200 | 200 | { |
| 201 | - $header = (string) $this->header('Authorization', ''); |
|
| 201 | + $header = (string)$this->header('Authorization', ''); |
|
| 202 | 202 | |
| 203 | 203 | $position = \strrpos($header, 'Bearer '); |
| 204 | 204 | |
| 205 | - if ($position !== false) { |
|
| 205 | + if ($position !== false){ |
|
| 206 | 206 | $header = \substr($header, $position + 7); |
| 207 | 207 | |
| 208 | 208 | /** @psalm-suppress FalsableReturnStatement */ |
@@ -257,16 +257,16 @@ discard block |
||
| 257 | 257 | public function isJsonExpected(bool $softMatch = false): bool |
| 258 | 258 | { |
| 259 | 259 | $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept')); |
| 260 | - foreach ($this->jsonTypes as $jsonType) { |
|
| 261 | - if ($acceptHeader->has($jsonType)) { |
|
| 260 | + foreach ($this->jsonTypes as $jsonType){ |
|
| 261 | + if ($acceptHeader->has($jsonType)){ |
|
| 262 | 262 | return true; |
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if ($softMatch) { |
|
| 267 | - foreach ($acceptHeader->getAll() as $item) { |
|
| 268 | - $itemValue = \strtolower((string) $item->getValue()); |
|
| 269 | - if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) { |
|
| 266 | + if ($softMatch){ |
|
| 267 | + foreach ($acceptHeader->getAll() as $item){ |
|
| 268 | + $itemValue = \strtolower((string)$item->getValue()); |
|
| 269 | + if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')){ |
|
| 270 | 270 | return true; |
| 271 | 271 | } |
| 272 | 272 | } |
@@ -305,20 +305,20 @@ discard block |
||
| 305 | 305 | // ensure proper request association |
| 306 | 306 | $this->request(); |
| 307 | 307 | |
| 308 | - if (isset($this->bags[$name])) { |
|
| 308 | + if (isset($this->bags[$name])){ |
|
| 309 | 309 | return $this->bags[$name]; |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | $definition = $this->findBagDefinition($name); |
| 313 | - if (!$definition) { |
|
| 313 | + if (!$definition){ |
|
| 314 | 314 | throw new InputException(\sprintf("Undefined input bag '%s'", $name)); |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | $class = $definition['class']; |
| 318 | 318 | $data = \call_user_func([$this->request(), $definition['source']]); |
| 319 | 319 | |
| 320 | - if (!\is_array($data)) { |
|
| 321 | - $data = (array) $data; |
|
| 320 | + if (!\is_array($data)){ |
|
| 321 | + $data = (array)$data; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | return $this->bags[$name] = new $class($data, $this->prefix); |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | public function hasBag(string $name): bool |
| 328 | 328 | { |
| 329 | - if (isset($this->bags[$name])) { |
|
| 329 | + if (isset($this->bags[$name])){ |
|
| 330 | 330 | return true; |
| 331 | 331 | } |
| 332 | 332 | |
@@ -364,12 +364,12 @@ discard block |
||
| 364 | 364 | */ |
| 365 | 365 | private function findBagDefinition(string $name): ?array |
| 366 | 366 | { |
| 367 | - if (isset($this->bagAssociations[$name])) { |
|
| 367 | + if (isset($this->bagAssociations[$name])){ |
|
| 368 | 368 | return $this->bagAssociations[$name]; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - foreach ($this->bagAssociations as $bag) { |
|
| 372 | - if (isset($bag['alias']) && $bag['alias'] === $name) { |
|
| 371 | + foreach ($this->bagAssociations as $bag){ |
|
| 372 | + if (isset($bag['alias']) && $bag['alias'] === $name){ |
|
| 373 | 373 | return $bag; |
| 374 | 374 | } |
| 375 | 375 | } |
@@ -134,10 +134,13 @@ discard block |
||
| 134 | 134 | { |
| 135 | 135 | $input = clone $this; |
| 136 | 136 | |
| 137 | - if ($add) { |
|
| 137 | + if ($add) |
|
| 138 | + { |
|
| 138 | 139 | $input->prefix .= '.' . $prefix; |
| 139 | 140 | $input->prefix = \trim($input->prefix, '.'); |
| 140 | - } else { |
|
| 141 | + } |
|
| 142 | + else |
|
| 143 | + { |
|
| 141 | 144 | $input->prefix = $prefix; |
| 142 | 145 | } |
| 143 | 146 | |
@@ -173,9 +176,12 @@ discard block |
||
| 173 | 176 | */ |
| 174 | 177 | public function request(): Request |
| 175 | 178 | { |
| 176 | - try { |
|
| 179 | + try |
|
| 180 | + { |
|
| 177 | 181 | $request = $this->container->get(Request::class); |
| 178 | - } catch (ContainerExceptionInterface $e) { |
|
| 182 | + } |
|
| 183 | + catch (ContainerExceptionInterface $e) |
|
| 184 | + { |
|
| 179 | 185 | $scope = \implode('.', \array_reverse(Introspector::scopeNames($this->container))); |
| 180 | 186 | throw new ScopeException( |
| 181 | 187 | "Unable to get `ServerRequestInterface` in the `$scope` container scope", |
@@ -185,7 +191,8 @@ discard block |
||
| 185 | 191 | } |
| 186 | 192 | |
| 187 | 193 | // Flushing input state |
| 188 | - if ($this->request !== $request) { |
|
| 194 | + if ($this->request !== $request) |
|
| 195 | + { |
|
| 189 | 196 | $this->bags = []; |
| 190 | 197 | $this->request = $request; |
| 191 | 198 | } |
@@ -202,7 +209,8 @@ discard block |
||
| 202 | 209 | |
| 203 | 210 | $position = \strrpos($header, 'Bearer '); |
| 204 | 211 | |
| 205 | - if ($position !== false) { |
|
| 212 | + if ($position !== false) |
|
| 213 | + { |
|
| 206 | 214 | $header = \substr($header, $position + 7); |
| 207 | 215 | |
| 208 | 216 | /** @psalm-suppress FalsableReturnStatement */ |
@@ -257,16 +265,21 @@ discard block |
||
| 257 | 265 | public function isJsonExpected(bool $softMatch = false): bool |
| 258 | 266 | { |
| 259 | 267 | $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept')); |
| 260 | - foreach ($this->jsonTypes as $jsonType) { |
|
| 261 | - if ($acceptHeader->has($jsonType)) { |
|
| 268 | + foreach ($this->jsonTypes as $jsonType) |
|
| 269 | + { |
|
| 270 | + if ($acceptHeader->has($jsonType)) |
|
| 271 | + { |
|
| 262 | 272 | return true; |
| 263 | 273 | } |
| 264 | 274 | } |
| 265 | 275 | |
| 266 | - if ($softMatch) { |
|
| 267 | - foreach ($acceptHeader->getAll() as $item) { |
|
| 276 | + if ($softMatch) |
|
| 277 | + { |
|
| 278 | + foreach ($acceptHeader->getAll() as $item) |
|
| 279 | + { |
|
| 268 | 280 | $itemValue = \strtolower((string) $item->getValue()); |
| 269 | - if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) { |
|
| 281 | + if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) |
|
| 282 | + { |
|
| 270 | 283 | return true; |
| 271 | 284 | } |
| 272 | 285 | } |
@@ -305,19 +318,22 @@ discard block |
||
| 305 | 318 | // ensure proper request association |
| 306 | 319 | $this->request(); |
| 307 | 320 | |
| 308 | - if (isset($this->bags[$name])) { |
|
| 321 | + if (isset($this->bags[$name])) |
|
| 322 | + { |
|
| 309 | 323 | return $this->bags[$name]; |
| 310 | 324 | } |
| 311 | 325 | |
| 312 | 326 | $definition = $this->findBagDefinition($name); |
| 313 | - if (!$definition) { |
|
| 327 | + if (!$definition) |
|
| 328 | + { |
|
| 314 | 329 | throw new InputException(\sprintf("Undefined input bag '%s'", $name)); |
| 315 | 330 | } |
| 316 | 331 | |
| 317 | 332 | $class = $definition['class']; |
| 318 | 333 | $data = \call_user_func([$this->request(), $definition['source']]); |
| 319 | 334 | |
| 320 | - if (!\is_array($data)) { |
|
| 335 | + if (!\is_array($data)) |
|
| 336 | + { |
|
| 321 | 337 | $data = (array) $data; |
| 322 | 338 | } |
| 323 | 339 | |
@@ -326,7 +342,8 @@ discard block |
||
| 326 | 342 | |
| 327 | 343 | public function hasBag(string $name): bool |
| 328 | 344 | { |
| 329 | - if (isset($this->bags[$name])) { |
|
| 345 | + if (isset($this->bags[$name])) |
|
| 346 | + { |
|
| 330 | 347 | return true; |
| 331 | 348 | } |
| 332 | 349 | |
@@ -364,12 +381,15 @@ discard block |
||
| 364 | 381 | */ |
| 365 | 382 | private function findBagDefinition(string $name): ?array |
| 366 | 383 | { |
| 367 | - if (isset($this->bagAssociations[$name])) { |
|
| 384 | + if (isset($this->bagAssociations[$name])) |
|
| 385 | + { |
|
| 368 | 386 | return $this->bagAssociations[$name]; |
| 369 | 387 | } |
| 370 | 388 | |
| 371 | - foreach ($this->bagAssociations as $bag) { |
|
| 372 | - if (isset($bag['alias']) && $bag['alias'] === $name) { |
|
| 389 | + foreach ($this->bagAssociations as $bag) |
|
| 390 | + { |
|
| 391 | + if (isset($bag['alias']) && $bag['alias'] === $name) |
|
| 392 | + { |
|
| 373 | 393 | return $bag; |
| 374 | 394 | } |
| 375 | 395 | } |
@@ -39,30 +39,30 @@ discard block |
||
| 39 | 39 | ?int $mode = null, |
| 40 | 40 | bool $recursivePermissions = true, |
| 41 | 41 | ): bool { |
| 42 | - if (empty($mode)) { |
|
| 42 | + if (empty($mode)){ |
|
| 43 | 43 | $mode = self::DEFAULT_FILE_MODE; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | //Directories always executable |
| 47 | 47 | $mode |= 0o111; |
| 48 | - if (\is_dir($directory)) { |
|
| 48 | + if (\is_dir($directory)){ |
|
| 49 | 49 | //Exists :( |
| 50 | 50 | return $this->setPermissions($directory, $mode); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - if (!$recursivePermissions) { |
|
| 53 | + if (!$recursivePermissions){ |
|
| 54 | 54 | return \mkdir($directory, $mode, true); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | $directoryChain = [\basename($directory)]; |
| 58 | 58 | |
| 59 | 59 | $baseDirectory = $directory; |
| 60 | - while (!\is_dir($baseDirectory = \dirname($baseDirectory))) { |
|
| 60 | + while (!\is_dir($baseDirectory = \dirname($baseDirectory))){ |
|
| 61 | 61 | $directoryChain[] = \basename($baseDirectory); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - foreach (\array_reverse($directoryChain) as $dir) { |
|
| 65 | - if (!\mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) { |
|
| 64 | + foreach (\array_reverse($directoryChain) as $dir){ |
|
| 65 | + if (!\mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))){ |
|
| 66 | 66 | return false; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | public function read(string $filename): string |
| 76 | 76 | { |
| 77 | - if (!$this->exists($filename)) { |
|
| 77 | + if (!$this->exists($filename)){ |
|
| 78 | 78 | throw new FileNotFoundException($filename); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -96,12 +96,12 @@ discard block |
||
| 96 | 96 | ): bool { |
| 97 | 97 | $mode ??= self::DEFAULT_FILE_MODE; |
| 98 | 98 | |
| 99 | - try { |
|
| 100 | - if ($ensureDirectory) { |
|
| 99 | + try{ |
|
| 100 | + if ($ensureDirectory){ |
|
| 101 | 101 | $this->ensureDirectory(\dirname($filename), $mode); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - if ($this->exists($filename)) { |
|
| 104 | + if ($this->exists($filename)){ |
|
| 105 | 105 | //Forcing mode for existed file |
| 106 | 106 | $this->setPermissions($filename, $mode); |
| 107 | 107 | } |
@@ -112,12 +112,12 @@ discard block |
||
| 112 | 112 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX, |
| 113 | 113 | ); |
| 114 | 114 | |
| 115 | - if ($result !== false) { |
|
| 115 | + if ($result !== false){ |
|
| 116 | 116 | //Forcing mode after file creation |
| 117 | 117 | $this->setPermissions($filename, $mode); |
| 118 | 118 | } |
| 119 | - } catch (\Exception $e) { |
|
| 120 | - throw new WriteErrorException($e->getMessage(), (int) $e->getCode(), $e); |
|
| 119 | + }catch (\Exception $e){ |
|
| 120 | + throw new WriteErrorException($e->getMessage(), (int)$e->getCode(), $e); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | return $result !== false; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | public function delete(string $filename): bool |
| 136 | 136 | { |
| 137 | - if ($this->exists($filename)) { |
|
| 137 | + if ($this->exists($filename)){ |
|
| 138 | 138 | $result = \unlink($filename); |
| 139 | 139 | |
| 140 | 140 | //Wiping out changes in local file cache |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | public function deleteDirectory(string $directory, bool $contentOnly = false): bool |
| 155 | 155 | { |
| 156 | - if (!$this->isDirectory($directory)) { |
|
| 156 | + if (!$this->isDirectory($directory)){ |
|
| 157 | 157 | throw new FilesException(\sprintf('Undefined or invalid directory %s', $directory)); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -162,15 +162,15 @@ discard block |
||
| 162 | 162 | \RecursiveIteratorIterator::CHILD_FIRST, |
| 163 | 163 | ); |
| 164 | 164 | |
| 165 | - foreach ($files as $file) { |
|
| 166 | - if ($file->isDir()) { |
|
| 165 | + foreach ($files as $file){ |
|
| 166 | + if ($file->isDir()){ |
|
| 167 | 167 | \rmdir($file->getRealPath()); |
| 168 | - } else { |
|
| 168 | + }else{ |
|
| 169 | 169 | $this->delete($file->getRealPath()); |
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - if (!$contentOnly) { |
|
| 173 | + if (!$contentOnly){ |
|
| 174 | 174 | return \rmdir($directory); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | public function move(string $filename, string $destination): bool |
| 181 | 181 | { |
| 182 | - if (!$this->exists($filename)) { |
|
| 182 | + if (!$this->exists($filename)){ |
|
| 183 | 183 | throw new FileNotFoundException($filename); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | public function copy(string $filename, string $destination): bool |
| 190 | 190 | { |
| 191 | - if (!$this->exists($filename)) { |
|
| 191 | + if (!$this->exists($filename)){ |
|
| 192 | 192 | throw new FileNotFoundException($filename); |
| 193 | 193 | } |
| 194 | 194 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | public function touch(string $filename, ?int $mode = null): bool |
| 199 | 199 | { |
| 200 | - if (!\touch($filename)) { |
|
| 200 | + if (!\touch($filename)){ |
|
| 201 | 201 | return false; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | { |
| 214 | 214 | $this->exists($filename) or throw new FileNotFoundException($filename); |
| 215 | 215 | |
| 216 | - return (int) \filesize($filename); |
|
| 216 | + return (int)\filesize($filename); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | public function extension(string $filename): string |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | public function md5(string $filename): string |
| 225 | 225 | { |
| 226 | - if (!$this->exists($filename)) { |
|
| 226 | + if (!$this->exists($filename)){ |
|
| 227 | 227 | throw new FileNotFoundException($filename); |
| 228 | 228 | } |
| 229 | 229 | |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | |
| 238 | 238 | public function time(string $filename): int |
| 239 | 239 | { |
| 240 | - if (!$this->exists($filename)) { |
|
| 240 | + if (!$this->exists($filename)){ |
|
| 241 | 241 | throw new FileNotFoundException($filename); |
| 242 | 242 | } |
| 243 | 243 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | |
| 269 | 269 | public function setPermissions(string $filename, int $mode): bool |
| 270 | 270 | { |
| 271 | - if (\is_dir($filename)) { |
|
| 271 | + if (\is_dir($filename)){ |
|
| 272 | 272 | //Directories must always be executable (i.e. 664 for dir => 775) |
| 273 | 273 | $mode |= 0111; |
| 274 | 274 | } |
@@ -279,14 +279,14 @@ discard block |
||
| 279 | 279 | public function getFiles(string $location, ?string $pattern = null): array |
| 280 | 280 | { |
| 281 | 281 | $result = []; |
| 282 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
| 283 | - if ($this->isDirectory($filename->getPathname())) { |
|
| 284 | - $result = \array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR)); |
|
| 282 | + foreach ($this->filesIterator($location, $pattern) as $filename){ |
|
| 283 | + if ($this->isDirectory($filename->getPathname())){ |
|
| 284 | + $result = \array_merge($result, $this->getFiles($filename.DIRECTORY_SEPARATOR)); |
|
| 285 | 285 | |
| 286 | 286 | continue; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - $result[] = $this->normalizePath((string) $filename); |
|
| 289 | + $result[] = $this->normalizePath((string)$filename); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | return $result; |
@@ -294,14 +294,14 @@ discard block |
||
| 294 | 294 | |
| 295 | 295 | public function tempFilename(string $extension = '', ?string $location = null): string |
| 296 | 296 | { |
| 297 | - if (empty($location)) { |
|
| 297 | + if (empty($location)){ |
|
| 298 | 298 | $location = \sys_get_temp_dir(); |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | $filename = \tempnam($location, 'spiral'); |
| 302 | 302 | $filename === false and throw new FilesException('Unable to create temporary file.'); |
| 303 | 303 | |
| 304 | - if (!empty($extension)) { |
|
| 304 | + if (!empty($extension)){ |
|
| 305 | 305 | $old = $filename; |
| 306 | 306 | $filename = \sprintf('%s.%s', $filename, $extension); |
| 307 | 307 | \rename($old, $filename); |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | public function normalizePath(string $path, bool $asDirectory = false): string |
| 315 | 315 | { |
| 316 | 316 | $isUnc = \str_starts_with($path, '\\\\') || \str_starts_with($path, '//'); |
| 317 | - if ($isUnc) { |
|
| 317 | + if ($isUnc){ |
|
| 318 | 318 | $leadingSlashes = \substr($path, 0, 2); |
| 319 | 319 | $path = \substr($path, 2); |
| 320 | 320 | } |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | $path = \str_replace(['//', '\\'], '/', $path); |
| 323 | 323 | |
| 324 | 324 | //Potentially open links and ../ type directories? |
| 325 | - return ($isUnc ? $leadingSlashes : '') . \rtrim($path, '/') . ($asDirectory ? '/' : ''); |
|
| 325 | + return ($isUnc ? $leadingSlashes : '').\rtrim($path, '/').($asDirectory ? '/' : ''); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -337,21 +337,21 @@ discard block |
||
| 337 | 337 | $path = \explode('/', $path); |
| 338 | 338 | $relative = $path; |
| 339 | 339 | |
| 340 | - foreach ($from as $depth => $dir) { |
|
| 340 | + foreach ($from as $depth => $dir){ |
|
| 341 | 341 | //Find first non-matching dir |
| 342 | - if ($dir === $path[$depth]) { |
|
| 342 | + if ($dir === $path[$depth]){ |
|
| 343 | 343 | //Ignore this directory |
| 344 | 344 | \array_shift($relative); |
| 345 | - } else { |
|
| 345 | + }else{ |
|
| 346 | 346 | //Get number of remaining dirs to $from |
| 347 | 347 | $remaining = \count($from) - $depth; |
| 348 | - if ($remaining > 1) { |
|
| 348 | + if ($remaining > 1){ |
|
| 349 | 349 | //Add traversals up to first matching directory |
| 350 | 350 | $padLength = (\count($relative) + $remaining - 1) * -1; |
| 351 | 351 | $relative = \array_pad($relative, $padLength, '..'); |
| 352 | 352 | break; |
| 353 | 353 | } |
| 354 | - $relative[0] = './' . $relative[0]; |
|
| 354 | + $relative[0] = './'.$relative[0]; |
|
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | */ |
| 364 | 364 | public function __destruct() |
| 365 | 365 | { |
| 366 | - foreach ($this->destructFiles as $filename) { |
|
| 366 | + foreach ($this->destructFiles as $filename){ |
|
| 367 | 367 | $this->delete($filename); |
| 368 | 368 | } |
| 369 | 369 | } |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | private function filesIterator(string $location, ?string $pattern = null): \GlobIterator |
| 372 | 372 | { |
| 373 | 373 | $pattern ??= '*'; |
| 374 | - $regexp = \rtrim($location, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . \ltrim($pattern, DIRECTORY_SEPARATOR); |
|
| 374 | + $regexp = \rtrim($location, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.\ltrim($pattern, DIRECTORY_SEPARATOR); |
|
| 375 | 375 | |
| 376 | 376 | return new \GlobIterator($regexp); |
| 377 | 377 | } |
@@ -39,30 +39,36 @@ discard block |
||
| 39 | 39 | ?int $mode = null, |
| 40 | 40 | bool $recursivePermissions = true, |
| 41 | 41 | ): bool { |
| 42 | - if (empty($mode)) { |
|
| 42 | + if (empty($mode)) |
|
| 43 | + { |
|
| 43 | 44 | $mode = self::DEFAULT_FILE_MODE; |
| 44 | 45 | } |
| 45 | 46 | |
| 46 | 47 | //Directories always executable |
| 47 | 48 | $mode |= 0o111; |
| 48 | - if (\is_dir($directory)) { |
|
| 49 | + if (\is_dir($directory)) |
|
| 50 | + { |
|
| 49 | 51 | //Exists :( |
| 50 | 52 | return $this->setPermissions($directory, $mode); |
| 51 | 53 | } |
| 52 | 54 | |
| 53 | - if (!$recursivePermissions) { |
|
| 55 | + if (!$recursivePermissions) |
|
| 56 | + { |
|
| 54 | 57 | return \mkdir($directory, $mode, true); |
| 55 | 58 | } |
| 56 | 59 | |
| 57 | 60 | $directoryChain = [\basename($directory)]; |
| 58 | 61 | |
| 59 | 62 | $baseDirectory = $directory; |
| 60 | - while (!\is_dir($baseDirectory = \dirname($baseDirectory))) { |
|
| 63 | + while (!\is_dir($baseDirectory = \dirname($baseDirectory))) |
|
| 64 | + { |
|
| 61 | 65 | $directoryChain[] = \basename($baseDirectory); |
| 62 | 66 | } |
| 63 | 67 | |
| 64 | - foreach (\array_reverse($directoryChain) as $dir) { |
|
| 65 | - if (!\mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) { |
|
| 68 | + foreach (\array_reverse($directoryChain) as $dir) |
|
| 69 | + { |
|
| 70 | + if (!\mkdir($baseDirectory = \sprintf('%s/%s', $baseDirectory, $dir))) |
|
| 71 | + { |
|
| 66 | 72 | return false; |
| 67 | 73 | } |
| 68 | 74 | |
@@ -74,7 +80,8 @@ discard block |
||
| 74 | 80 | |
| 75 | 81 | public function read(string $filename): string |
| 76 | 82 | { |
| 77 | - if (!$this->exists($filename)) { |
|
| 83 | + if (!$this->exists($filename)) |
|
| 84 | + { |
|
| 78 | 85 | throw new FileNotFoundException($filename); |
| 79 | 86 | } |
| 80 | 87 | |
@@ -96,12 +103,15 @@ discard block |
||
| 96 | 103 | ): bool { |
| 97 | 104 | $mode ??= self::DEFAULT_FILE_MODE; |
| 98 | 105 | |
| 99 | - try { |
|
| 100 | - if ($ensureDirectory) { |
|
| 106 | + try |
|
| 107 | + { |
|
| 108 | + if ($ensureDirectory) |
|
| 109 | + { |
|
| 101 | 110 | $this->ensureDirectory(\dirname($filename), $mode); |
| 102 | 111 | } |
| 103 | 112 | |
| 104 | - if ($this->exists($filename)) { |
|
| 113 | + if ($this->exists($filename)) |
|
| 114 | + { |
|
| 105 | 115 | //Forcing mode for existed file |
| 106 | 116 | $this->setPermissions($filename, $mode); |
| 107 | 117 | } |
@@ -112,11 +122,14 @@ discard block |
||
| 112 | 122 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX, |
| 113 | 123 | ); |
| 114 | 124 | |
| 115 | - if ($result !== false) { |
|
| 125 | + if ($result !== false) |
|
| 126 | + { |
|
| 116 | 127 | //Forcing mode after file creation |
| 117 | 128 | $this->setPermissions($filename, $mode); |
| 118 | 129 | } |
| 119 | - } catch (\Exception $e) { |
|
| 130 | + } |
|
| 131 | + catch (\Exception $e) |
|
| 132 | + { |
|
| 120 | 133 | throw new WriteErrorException($e->getMessage(), (int) $e->getCode(), $e); |
| 121 | 134 | } |
| 122 | 135 | |
@@ -134,7 +147,8 @@ discard block |
||
| 134 | 147 | |
| 135 | 148 | public function delete(string $filename): bool |
| 136 | 149 | { |
| 137 | - if ($this->exists($filename)) { |
|
| 150 | + if ($this->exists($filename)) |
|
| 151 | + { |
|
| 138 | 152 | $result = \unlink($filename); |
| 139 | 153 | |
| 140 | 154 | //Wiping out changes in local file cache |
@@ -153,7 +167,8 @@ discard block |
||
| 153 | 167 | */ |
| 154 | 168 | public function deleteDirectory(string $directory, bool $contentOnly = false): bool |
| 155 | 169 | { |
| 156 | - if (!$this->isDirectory($directory)) { |
|
| 170 | + if (!$this->isDirectory($directory)) |
|
| 171 | + { |
|
| 157 | 172 | throw new FilesException(\sprintf('Undefined or invalid directory %s', $directory)); |
| 158 | 173 | } |
| 159 | 174 | |
@@ -162,15 +177,20 @@ discard block |
||
| 162 | 177 | \RecursiveIteratorIterator::CHILD_FIRST, |
| 163 | 178 | ); |
| 164 | 179 | |
| 165 | - foreach ($files as $file) { |
|
| 166 | - if ($file->isDir()) { |
|
| 180 | + foreach ($files as $file) |
|
| 181 | + { |
|
| 182 | + if ($file->isDir()) |
|
| 183 | + { |
|
| 167 | 184 | \rmdir($file->getRealPath()); |
| 168 | - } else { |
|
| 185 | + } |
|
| 186 | + else |
|
| 187 | + { |
|
| 169 | 188 | $this->delete($file->getRealPath()); |
| 170 | 189 | } |
| 171 | 190 | } |
| 172 | 191 | |
| 173 | - if (!$contentOnly) { |
|
| 192 | + if (!$contentOnly) |
|
| 193 | + { |
|
| 174 | 194 | return \rmdir($directory); |
| 175 | 195 | } |
| 176 | 196 | |
@@ -179,7 +199,8 @@ discard block |
||
| 179 | 199 | |
| 180 | 200 | public function move(string $filename, string $destination): bool |
| 181 | 201 | { |
| 182 | - if (!$this->exists($filename)) { |
|
| 202 | + if (!$this->exists($filename)) |
|
| 203 | + { |
|
| 183 | 204 | throw new FileNotFoundException($filename); |
| 184 | 205 | } |
| 185 | 206 | |
@@ -188,7 +209,8 @@ discard block |
||
| 188 | 209 | |
| 189 | 210 | public function copy(string $filename, string $destination): bool |
| 190 | 211 | { |
| 191 | - if (!$this->exists($filename)) { |
|
| 212 | + if (!$this->exists($filename)) |
|
| 213 | + { |
|
| 192 | 214 | throw new FileNotFoundException($filename); |
| 193 | 215 | } |
| 194 | 216 | |
@@ -197,7 +219,8 @@ discard block |
||
| 197 | 219 | |
| 198 | 220 | public function touch(string $filename, ?int $mode = null): bool |
| 199 | 221 | { |
| 200 | - if (!\touch($filename)) { |
|
| 222 | + if (!\touch($filename)) |
|
| 223 | + { |
|
| 201 | 224 | return false; |
| 202 | 225 | } |
| 203 | 226 | |
@@ -223,7 +246,8 @@ discard block |
||
| 223 | 246 | |
| 224 | 247 | public function md5(string $filename): string |
| 225 | 248 | { |
| 226 | - if (!$this->exists($filename)) { |
|
| 249 | + if (!$this->exists($filename)) |
|
| 250 | + { |
|
| 227 | 251 | throw new FileNotFoundException($filename); |
| 228 | 252 | } |
| 229 | 253 | |
@@ -237,7 +261,8 @@ discard block |
||
| 237 | 261 | |
| 238 | 262 | public function time(string $filename): int |
| 239 | 263 | { |
| 240 | - if (!$this->exists($filename)) { |
|
| 264 | + if (!$this->exists($filename)) |
|
| 265 | + { |
|
| 241 | 266 | throw new FileNotFoundException($filename); |
| 242 | 267 | } |
| 243 | 268 | |
@@ -268,7 +293,8 @@ discard block |
||
| 268 | 293 | |
| 269 | 294 | public function setPermissions(string $filename, int $mode): bool |
| 270 | 295 | { |
| 271 | - if (\is_dir($filename)) { |
|
| 296 | + if (\is_dir($filename)) |
|
| 297 | + { |
|
| 272 | 298 | //Directories must always be executable (i.e. 664 for dir => 775) |
| 273 | 299 | $mode |= 0111; |
| 274 | 300 | } |
@@ -279,8 +305,10 @@ discard block |
||
| 279 | 305 | public function getFiles(string $location, ?string $pattern = null): array |
| 280 | 306 | { |
| 281 | 307 | $result = []; |
| 282 | - foreach ($this->filesIterator($location, $pattern) as $filename) { |
|
| 283 | - if ($this->isDirectory($filename->getPathname())) { |
|
| 308 | + foreach ($this->filesIterator($location, $pattern) as $filename) |
|
| 309 | + { |
|
| 310 | + if ($this->isDirectory($filename->getPathname())) |
|
| 311 | + { |
|
| 284 | 312 | $result = \array_merge($result, $this->getFiles($filename . DIRECTORY_SEPARATOR)); |
| 285 | 313 | |
| 286 | 314 | continue; |
@@ -294,14 +322,16 @@ discard block |
||
| 294 | 322 | |
| 295 | 323 | public function tempFilename(string $extension = '', ?string $location = null): string |
| 296 | 324 | { |
| 297 | - if (empty($location)) { |
|
| 325 | + if (empty($location)) |
|
| 326 | + { |
|
| 298 | 327 | $location = \sys_get_temp_dir(); |
| 299 | 328 | } |
| 300 | 329 | |
| 301 | 330 | $filename = \tempnam($location, 'spiral'); |
| 302 | 331 | $filename === false and throw new FilesException('Unable to create temporary file.'); |
| 303 | 332 | |
| 304 | - if (!empty($extension)) { |
|
| 333 | + if (!empty($extension)) |
|
| 334 | + { |
|
| 305 | 335 | $old = $filename; |
| 306 | 336 | $filename = \sprintf('%s.%s', $filename, $extension); |
| 307 | 337 | \rename($old, $filename); |
@@ -314,7 +344,8 @@ discard block |
||
| 314 | 344 | public function normalizePath(string $path, bool $asDirectory = false): string |
| 315 | 345 | { |
| 316 | 346 | $isUnc = \str_starts_with($path, '\\\\') || \str_starts_with($path, '//'); |
| 317 | - if ($isUnc) { |
|
| 347 | + if ($isUnc) |
|
| 348 | + { |
|
| 318 | 349 | $leadingSlashes = \substr($path, 0, 2); |
| 319 | 350 | $path = \substr($path, 2); |
| 320 | 351 | } |
@@ -337,15 +368,20 @@ discard block |
||
| 337 | 368 | $path = \explode('/', $path); |
| 338 | 369 | $relative = $path; |
| 339 | 370 | |
| 340 | - foreach ($from as $depth => $dir) { |
|
| 371 | + foreach ($from as $depth => $dir) |
|
| 372 | + { |
|
| 341 | 373 | //Find first non-matching dir |
| 342 | - if ($dir === $path[$depth]) { |
|
| 374 | + if ($dir === $path[$depth]) |
|
| 375 | + { |
|
| 343 | 376 | //Ignore this directory |
| 344 | 377 | \array_shift($relative); |
| 345 | - } else { |
|
| 378 | + } |
|
| 379 | + else |
|
| 380 | + { |
|
| 346 | 381 | //Get number of remaining dirs to $from |
| 347 | 382 | $remaining = \count($from) - $depth; |
| 348 | - if ($remaining > 1) { |
|
| 383 | + if ($remaining > 1) |
|
| 384 | + { |
|
| 349 | 385 | //Add traversals up to first matching directory |
| 350 | 386 | $padLength = (\count($relative) + $remaining - 1) * -1; |
| 351 | 387 | $relative = \array_pad($relative, $padLength, '..'); |
@@ -363,7 +399,8 @@ discard block |
||
| 363 | 399 | */ |
| 364 | 400 | public function __destruct() |
| 365 | 401 | { |
| 366 | - foreach ($this->destructFiles as $filename) { |
|
| 402 | + foreach ($this->destructFiles as $filename) |
|
| 403 | + { |
|
| 367 | 404 | $this->delete($filename); |
| 368 | 405 | } |
| 369 | 406 | } |
@@ -13,11 +13,11 @@ discard block |
||
| 13 | 13 | { |
| 14 | 14 | private array $vars = []; |
| 15 | 15 | |
| 16 | - public function enterNode(Node $node): int|Node\Stmt\ClassMethod|null |
|
| 16 | + public function enterNode(Node $node): int | Node\Stmt\ClassMethod | null |
|
| 17 | 17 | { |
| 18 | - if ($node instanceof Node\Stmt\Class_) { |
|
| 19 | - foreach ($node->stmts as $stmt) { |
|
| 20 | - if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name->toLowerString() === '__construct') { |
|
| 18 | + if ($node instanceof Node\Stmt\Class_){ |
|
| 19 | + foreach ($node->stmts as $stmt){ |
|
| 20 | + if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name->toLowerString() === '__construct'){ |
|
| 21 | 21 | return $stmt; |
| 22 | 22 | } |
| 23 | 23 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | return NodeVisitor::DONT_TRAVERSE_CHILDREN; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - if ($node instanceof Node\Expr\Variable) { |
|
| 28 | + if ($node instanceof Node\Expr\Variable){ |
|
| 29 | 29 | $this->vars[] = $node->name; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -15,9 +15,12 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | public function enterNode(Node $node): int|Node\Stmt\ClassMethod|null |
| 17 | 17 | { |
| 18 | - if ($node instanceof Node\Stmt\Class_) { |
|
| 19 | - foreach ($node->stmts as $stmt) { |
|
| 20 | - if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name->toLowerString() === '__construct') { |
|
| 18 | + if ($node instanceof Node\Stmt\Class_) |
|
| 19 | + { |
|
| 20 | + foreach ($node->stmts as $stmt) |
|
| 21 | + { |
|
| 22 | + if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name->toLowerString() === '__construct') |
|
| 23 | + { |
|
| 21 | 24 | return $stmt; |
| 22 | 25 | } |
| 23 | 26 | } |
@@ -25,7 +28,8 @@ discard block |
||
| 25 | 28 | return NodeVisitor::DONT_TRAVERSE_CHILDREN; |
| 26 | 29 | } |
| 27 | 30 | |
| 28 | - if ($node instanceof Node\Expr\Variable) { |
|
| 31 | + if ($node instanceof Node\Expr\Variable) |
|
| 32 | + { |
|
| 29 | 33 | $this->vars[] = $node->name; |
| 30 | 34 | } |
| 31 | 35 | |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | public function __construct( |
| 42 | 42 | #[Proxy] private readonly ContainerInterface $container, |
| 43 | 43 | private readonly ?EventDispatcherInterface $dispatcher = null, |
| 44 | - ) {} |
|
| 44 | + ){} |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * Add middleware to the pipeline. |
| 48 | 48 | * |
| 49 | 49 | * @param MiddlewareInterface|Autowire|non-empty-string ...$middleware List of middleware or its definition. |
| 50 | 50 | */ |
| 51 | - public function withAddedMiddleware(MiddlewareInterface|Autowire|string ...$middleware): self |
|
| 51 | + public function withAddedMiddleware(MiddlewareInterface | Autowire | string ...$middleware): self |
|
| 52 | 52 | { |
| 53 | 53 | $pipeline = clone $this; |
| 54 | 54 | $pipeline->middleware = \array_merge($pipeline->middleware, $middleware); |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @param MiddlewareInterface ...$middleware List of middleware or its definition. |
| 62 | 62 | */ |
| 63 | - public function withMiddleware(MiddlewareInterface|Autowire|string ...$middleware): self |
|
| 63 | + public function withMiddleware(MiddlewareInterface | Autowire | string ...$middleware): self |
|
| 64 | 64 | { |
| 65 | 65 | $pipeline = clone $this; |
| 66 | 66 | $pipeline->middleware = $middleware; |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | $previousRequest = $currentRequest->get(); |
| 95 | 95 | $currentRequest->set($request); |
| 96 | - try { |
|
| 96 | + try{ |
|
| 97 | 97 | // There is no middleware to process, let's pass the request to the handler |
| 98 | - if (!\array_key_exists($this->position, $this->middleware)) { |
|
| 98 | + if (!\array_key_exists($this->position, $this->middleware)){ |
|
| 99 | 99 | return $this->handler->handle($request); |
| 100 | 100 | } |
| 101 | 101 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | ? \sprintf('%s=%s', $this->middleware[$this->position], $middleware::class) |
| 110 | 110 | : $middleware::class; |
| 111 | 111 | // Init a tracing span when the pipeline starts |
| 112 | - if ($span === null) { |
|
| 112 | + if ($span === null){ |
|
| 113 | 113 | /** @var TracerInterface $tracer */ |
| 114 | 114 | $tracer = $this->container->get(TracerInterface::class); |
| 115 | 115 | return $tracer->trace( |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $span->setAttribute('http.middleware', $middlewares); |
| 128 | 128 | |
| 129 | 129 | return $middleware->process($request, $this->next($span)); |
| 130 | - } finally { |
|
| 130 | + }finally{ |
|
| 131 | 131 | $currentRequest->set($previousRequest); |
| 132 | 132 | } |
| 133 | 133 | } |