@@ -22,9 +22,9 @@ discard block |
||
| 22 | 22 | private readonly bool $isLegacy; |
| 23 | 23 | |
| 24 | 24 | public function __construct( |
| 25 | - private readonly HandlerInterface|CoreInterface $core, |
|
| 25 | + private readonly HandlerInterface | CoreInterface $core, |
|
| 26 | 26 | private readonly TracerFactoryInterface $tracerFactory = new NullTracerFactory(new Container()), |
| 27 | - ) { |
|
| 27 | + ){ |
|
| 28 | 28 | $this->isLegacy = !$core instanceof HandlerInterface; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -49,16 +49,16 @@ discard block |
||
| 49 | 49 | return $tracer->trace( |
| 50 | 50 | name: \sprintf('Job handling [%s:%s]', $name, $id), |
| 51 | 51 | callback: $this->isLegacy |
| 52 | - ? fn (): mixed => $this->core->callAction($name, 'handle', $arguments) |
|
| 53 | - : fn (): mixed => $this->core->handle(new CallContext(Target::fromPair($name, 'handle'), $arguments)), |
|
| 54 | - attributes: [ |
|
| 52 | + ? fn () : mixed => $this->core->callAction($name, 'handle', $arguments) |
|
| 53 | + : fn () : mixed => $this->core->handle(new CallContext(Target::fromPair($name, 'handle'), $arguments)), |
|
| 54 | + attributes : [ |
|
| 55 | 55 | 'queue.driver' => $driver, |
| 56 | 56 | 'queue.name' => $queue, |
| 57 | 57 | 'queue.id' => $id, |
| 58 | 58 | 'queue.headers' => $headers, |
| 59 | 59 | ], |
| 60 | - scoped: true, |
|
| 61 | - traceKind: TraceKind::CONSUMER, |
|
| 60 | + scoped : true, |
|
| 61 | + traceKind : TraceKind::CONSUMER, |
|
| 62 | 62 | ); |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | public function __construct( |
| 12 | 12 | string $reason = '', |
| 13 | 13 | private readonly ?OptionsInterface $options = null |
| 14 | - ) { |
|
| 14 | + ){ |
|
| 15 | 15 | parent::__construct($reason); |
| 16 | 16 | } |
| 17 | 17 | |
@@ -42,18 +42,18 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function makeSchema(string $name, array $schema): array |
| 44 | 44 | { |
| 45 | - if (empty($schema)) { |
|
| 45 | + if (empty($schema)){ |
|
| 46 | 46 | throw new SchemaException(\sprintf('Filter `%s` does not define any schema', $name)); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $result = []; |
| 50 | - foreach ($schema as $field => $definition) { |
|
| 50 | + foreach ($schema as $field => $definition){ |
|
| 51 | 51 | $optional = false; |
| 52 | 52 | |
| 53 | 53 | // short definition |
| 54 | - if (\is_string($definition)) { |
|
| 54 | + if (\is_string($definition)){ |
|
| 55 | 55 | // simple scalar field definition |
| 56 | - if (!\class_exists($definition)) { |
|
| 56 | + if (!\class_exists($definition)){ |
|
| 57 | 57 | [$source, $origin] = $this->parseDefinition($field, $definition); |
| 58 | 58 | $result[$field] = [ |
| 59 | 59 | self::SCHEMA_SOURCE => $source, |
@@ -74,25 +74,25 @@ discard block |
||
| 74 | 74 | continue; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if (!\is_array($definition) || $definition === []) { |
|
| 77 | + if (!\is_array($definition) || $definition === []){ |
|
| 78 | 78 | throw new SchemaException( |
| 79 | 79 | \sprintf('Invalid schema definition at `%s`->`%s`', $name, $field) |
| 80 | 80 | ); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // complex definition |
| 84 | - if (!empty($definition[self::ORIGIN])) { |
|
| 84 | + if (!empty($definition[self::ORIGIN])){ |
|
| 85 | 85 | $origin = $definition[self::ORIGIN]; |
| 86 | 86 | |
| 87 | 87 | // [class, 'data:something.*'] vs [class, 'data:something'] |
| 88 | 88 | $iterate = \str_contains((string)$origin, '.*') || !empty($definition[self::ITERATE]); |
| 89 | - $origin = \rtrim((string) $origin, '.*'); |
|
| 90 | - } else { |
|
| 89 | + $origin = \rtrim((string)$origin, '.*'); |
|
| 90 | + }else{ |
|
| 91 | 91 | $origin = $field; |
| 92 | 92 | $iterate = true; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if (!empty($definition[self::OPTIONAL])) { |
|
| 95 | + if (!empty($definition[self::OPTIONAL])){ |
|
| 96 | 96 | $optional = true; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | self::SCHEMA_OPTIONAL => $optional, |
| 106 | 106 | ]; |
| 107 | 107 | |
| 108 | - if ($iterate) { |
|
| 108 | + if ($iterate){ |
|
| 109 | 109 | [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin); |
| 110 | 110 | |
| 111 | 111 | $map[self::SCHEMA_ITERATE_SOURCE] = $source; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | private function parseDefinition(string $field, string $definition): array |
| 130 | 130 | { |
| 131 | - if (!\str_contains($definition, ':')) { |
|
| 131 | + if (!\str_contains($definition, ':')){ |
|
| 132 | 132 | return ['data', empty($definition) ? $field : $definition]; |
| 133 | 133 | } |
| 134 | 134 | |
@@ -42,18 +42,22 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function makeSchema(string $name, array $schema): array |
| 44 | 44 | { |
| 45 | - if (empty($schema)) { |
|
| 45 | + if (empty($schema)) |
|
| 46 | + { |
|
| 46 | 47 | throw new SchemaException(\sprintf('Filter `%s` does not define any schema', $name)); |
| 47 | 48 | } |
| 48 | 49 | |
| 49 | 50 | $result = []; |
| 50 | - foreach ($schema as $field => $definition) { |
|
| 51 | + foreach ($schema as $field => $definition) |
|
| 52 | + { |
|
| 51 | 53 | $optional = false; |
| 52 | 54 | |
| 53 | 55 | // short definition |
| 54 | - if (\is_string($definition)) { |
|
| 56 | + if (\is_string($definition)) |
|
| 57 | + { |
|
| 55 | 58 | // simple scalar field definition |
| 56 | - if (!\class_exists($definition)) { |
|
| 59 | + if (!\class_exists($definition)) |
|
| 60 | + { |
|
| 57 | 61 | [$source, $origin] = $this->parseDefinition($field, $definition); |
| 58 | 62 | $result[$field] = [ |
| 59 | 63 | self::SCHEMA_SOURCE => $source, |
@@ -74,25 +78,30 @@ discard block |
||
| 74 | 78 | continue; |
| 75 | 79 | } |
| 76 | 80 | |
| 77 | - if (!\is_array($definition) || $definition === []) { |
|
| 81 | + if (!\is_array($definition) || $definition === []) |
|
| 82 | + { |
|
| 78 | 83 | throw new SchemaException( |
| 79 | 84 | \sprintf('Invalid schema definition at `%s`->`%s`', $name, $field) |
| 80 | 85 | ); |
| 81 | 86 | } |
| 82 | 87 | |
| 83 | 88 | // complex definition |
| 84 | - if (!empty($definition[self::ORIGIN])) { |
|
| 89 | + if (!empty($definition[self::ORIGIN])) |
|
| 90 | + { |
|
| 85 | 91 | $origin = $definition[self::ORIGIN]; |
| 86 | 92 | |
| 87 | 93 | // [class, 'data:something.*'] vs [class, 'data:something'] |
| 88 | 94 | $iterate = \str_contains((string)$origin, '.*') || !empty($definition[self::ITERATE]); |
| 89 | 95 | $origin = \rtrim((string) $origin, '.*'); |
| 90 | - } else { |
|
| 96 | + } |
|
| 97 | + else |
|
| 98 | + { |
|
| 91 | 99 | $origin = $field; |
| 92 | 100 | $iterate = true; |
| 93 | 101 | } |
| 94 | 102 | |
| 95 | - if (!empty($definition[self::OPTIONAL])) { |
|
| 103 | + if (!empty($definition[self::OPTIONAL])) |
|
| 104 | + { |
|
| 96 | 105 | $optional = true; |
| 97 | 106 | } |
| 98 | 107 | |
@@ -105,7 +114,8 @@ discard block |
||
| 105 | 114 | self::SCHEMA_OPTIONAL => $optional, |
| 106 | 115 | ]; |
| 107 | 116 | |
| 108 | - if ($iterate) { |
|
| 117 | + if ($iterate) |
|
| 118 | + { |
|
| 109 | 119 | [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin); |
| 110 | 120 | |
| 111 | 121 | $map[self::SCHEMA_ITERATE_SOURCE] = $source; |
@@ -128,7 +138,8 @@ discard block |
||
| 128 | 138 | */ |
| 129 | 139 | private function parseDefinition(string $field, string $definition): array |
| 130 | 140 | { |
| 131 | - if (!\str_contains($definition, ':')) { |
|
| 141 | + if (!\str_contains($definition, ':')) |
|
| 142 | + { |
|
| 132 | 143 | return ['data', empty($definition) ? $field : $definition]; |
| 133 | 144 | } |
| 134 | 145 | |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | public function __construct( |
| 26 | 26 | array $values = [], |
| 27 | 27 | private readonly bool $overwrite = false |
| 28 | - ) { |
|
| 28 | + ){ |
|
| 29 | 29 | $this->values = $values + $_ENV + $_SERVER; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function getID(): string |
| 33 | 33 | { |
| 34 | - if (empty($this->id)) { |
|
| 34 | + if (empty($this->id)){ |
|
| 35 | 35 | $this->id = \md5(\serialize($this->values)); |
| 36 | 36 | } |
| 37 | 37 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | public function set(string $name, mixed $value): self |
| 42 | 42 | { |
| 43 | - if (\array_key_exists($name, $this->values) && !$this->overwrite) { |
|
| 43 | + if (\array_key_exists($name, $this->values) && !$this->overwrite){ |
|
| 44 | 44 | return $this; |
| 45 | 45 | } |
| 46 | 46 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | public function get(string $name, mixed $default = null): mixed |
| 56 | 56 | { |
| 57 | - if (isset($this->values[$name])) { |
|
| 57 | + if (isset($this->values[$name])){ |
|
| 58 | 58 | return $this->normalize($this->values[$name]); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | $result = []; |
| 70 | 70 | |
| 71 | - foreach ($this->values as $key => $value) { |
|
| 71 | + foreach ($this->values as $key => $value){ |
|
| 72 | 72 | $result[$key] = $this->normalize($value); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | protected function normalize(mixed $value): mixed |
| 79 | 79 | { |
| 80 | - if (!\is_string($value)) { |
|
| 80 | + if (!\is_string($value)){ |
|
| 81 | 81 | return $value; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | $alias = \strtolower($value); |
| 85 | - if (isset(self::VALUE_MAP[$alias])) { |
|
| 85 | + if (isset(self::VALUE_MAP[$alias])){ |
|
| 86 | 86 | return self::VALUE_MAP[$alias]; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function __construct(array $items = []) |
| 28 | 28 | { |
| 29 | - foreach ($items as $item) { |
|
| 29 | + foreach ($items as $item){ |
|
| 30 | 30 | $this->addItem($item); |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | $header = new static(); |
| 42 | 42 | |
| 43 | 43 | $parts = \explode(',', $raw); |
| 44 | - foreach ($parts as $part) { |
|
| 44 | + foreach ($parts as $part){ |
|
| 45 | 45 | $part = \trim($part); |
| 46 | - if ($part !== '') { |
|
| 46 | + if ($part !== ''){ |
|
| 47 | 47 | $header->addItem($part); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | return $header; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public function add(AcceptHeaderItem|string $item): self |
|
| 54 | + public function add(AcceptHeaderItem | string $item): self |
|
| 55 | 55 | { |
| 56 | 56 | $header = clone $this; |
| 57 | 57 | $header->addItem($item); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function getAll(): array |
| 76 | 76 | { |
| 77 | - if (!$this->sorted) { |
|
| 77 | + if (!$this->sorted){ |
|
| 78 | 78 | /** |
| 79 | 79 | * Sort item in descending order. |
| 80 | 80 | */ |
@@ -89,14 +89,14 @@ discard block |
||
| 89 | 89 | /** |
| 90 | 90 | * Add new item to list. |
| 91 | 91 | */ |
| 92 | - private function addItem(AcceptHeaderItem|string $item): void |
|
| 92 | + private function addItem(AcceptHeaderItem | string $item): void |
|
| 93 | 93 | { |
| 94 | - if (\is_string($item)) { |
|
| 94 | + if (\is_string($item)){ |
|
| 95 | 95 | $item = AcceptHeaderItem::fromString($item); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - $value = \strtolower((string) $item->getValue()); |
|
| 99 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
| 98 | + $value = \strtolower((string)$item->getValue()); |
|
| 99 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)){ |
|
| 100 | 100 | $this->sorted = false; |
| 101 | 101 | $this->items[$value] = $item; |
| 102 | 102 | } |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | * Compare to header items, witch one is preferable. |
| 107 | 107 | * Return 1 if first value preferable or -1 if second, 0 in case of same weight. |
| 108 | 108 | */ |
| 109 | - private static function compare(AcceptHeaderItem|string $a, AcceptHeaderItem|string $b): int |
|
| 109 | + private static function compare(AcceptHeaderItem | string $a, AcceptHeaderItem | string $b): int |
|
| 110 | 110 | { |
| 111 | - if ($a->getQuality() === $b->getQuality()) { |
|
| 111 | + if ($a->getQuality() === $b->getQuality()){ |
|
| 112 | 112 | // If quality are same value with more params has more weight. |
| 113 | - if (\count($a->getParams()) === \count($b->getParams())) { |
|
| 113 | + if (\count($a->getParams()) === \count($b->getParams())){ |
|
| 114 | 114 | // If quality and params then check for specific type or subtype. |
| 115 | 115 | // Means */* or * has less weight. |
| 116 | 116 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -129,11 +129,11 @@ discard block |
||
| 129 | 129 | private static function compareValue(string $a, string $b): int |
| 130 | 130 | { |
| 131 | 131 | // Check "Accept" headers values with it is type and subtype. |
| 132 | - if (\str_contains($a, '/') && \str_contains($b, '/')) { |
|
| 132 | + if (\str_contains($a, '/') && \str_contains($b, '/')){ |
|
| 133 | 133 | [$typeA, $subtypeA] = \explode('/', $a, 2); |
| 134 | 134 | [$typeB, $subtypeB] = \explode('/', $b, 2); |
| 135 | 135 | |
| 136 | - if ($typeA === $typeB) { |
|
| 136 | + if ($typeA === $typeB){ |
|
| 137 | 137 | return static::compareAtomic($subtypeA, $subtypeB); |
| 138 | 138 | } |
| 139 | 139 | |
@@ -145,23 +145,23 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | private static function compareAtomic(string $a, string $b): int |
| 147 | 147 | { |
| 148 | - if (\mb_strpos($a, '*/') === 0) { |
|
| 148 | + if (\mb_strpos($a, '*/') === 0){ |
|
| 149 | 149 | $a = '*'; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - if (\mb_strpos($b, '*/') === 0) { |
|
| 152 | + if (\mb_strpos($b, '*/') === 0){ |
|
| 153 | 153 | $b = '*'; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - if (\strtolower($a) === \strtolower($b)) { |
|
| 156 | + if (\strtolower($a) === \strtolower($b)){ |
|
| 157 | 157 | return 0; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - if ($a === '*') { |
|
| 160 | + if ($a === '*'){ |
|
| 161 | 161 | return -1; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - if ($b === '*') { |
|
| 164 | + if ($b === '*'){ |
|
| 165 | 165 | return 1; |
| 166 | 166 | } |
| 167 | 167 | |
@@ -26,7 +26,8 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function __construct(array $items = []) |
| 28 | 28 | { |
| 29 | - foreach ($items as $item) { |
|
| 29 | + foreach ($items as $item) |
|
| 30 | + { |
|
| 30 | 31 | $this->addItem($item); |
| 31 | 32 | } |
| 32 | 33 | } |
@@ -41,9 +42,11 @@ discard block |
||
| 41 | 42 | $header = new static(); |
| 42 | 43 | |
| 43 | 44 | $parts = \explode(',', $raw); |
| 44 | - foreach ($parts as $part) { |
|
| 45 | + foreach ($parts as $part) |
|
| 46 | + { |
|
| 45 | 47 | $part = \trim($part); |
| 46 | - if ($part !== '') { |
|
| 48 | + if ($part !== '') |
|
| 49 | + { |
|
| 47 | 50 | $header->addItem($part); |
| 48 | 51 | } |
| 49 | 52 | } |
@@ -74,7 +77,8 @@ discard block |
||
| 74 | 77 | */ |
| 75 | 78 | public function getAll(): array |
| 76 | 79 | { |
| 77 | - if (!$this->sorted) { |
|
| 80 | + if (!$this->sorted) |
|
| 81 | + { |
|
| 78 | 82 | /** |
| 79 | 83 | * Sort item in descending order. |
| 80 | 84 | */ |
@@ -91,12 +95,14 @@ discard block |
||
| 91 | 95 | */ |
| 92 | 96 | private function addItem(AcceptHeaderItem|string $item): void |
| 93 | 97 | { |
| 94 | - if (\is_string($item)) { |
|
| 98 | + if (\is_string($item)) |
|
| 99 | + { |
|
| 95 | 100 | $item = AcceptHeaderItem::fromString($item); |
| 96 | 101 | } |
| 97 | 102 | |
| 98 | 103 | $value = \strtolower((string) $item->getValue()); |
| 99 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
| 104 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) |
|
| 105 | + { |
|
| 100 | 106 | $this->sorted = false; |
| 101 | 107 | $this->items[$value] = $item; |
| 102 | 108 | } |
@@ -108,9 +114,11 @@ discard block |
||
| 108 | 114 | */ |
| 109 | 115 | private static function compare(AcceptHeaderItem|string $a, AcceptHeaderItem|string $b): int |
| 110 | 116 | { |
| 111 | - if ($a->getQuality() === $b->getQuality()) { |
|
| 117 | + if ($a->getQuality() === $b->getQuality()) |
|
| 118 | + { |
|
| 112 | 119 | // If quality are same value with more params has more weight. |
| 113 | - if (\count($a->getParams()) === \count($b->getParams())) { |
|
| 120 | + if (\count($a->getParams()) === \count($b->getParams())) |
|
| 121 | + { |
|
| 114 | 122 | // If quality and params then check for specific type or subtype. |
| 115 | 123 | // Means */* or * has less weight. |
| 116 | 124 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -129,11 +137,13 @@ discard block |
||
| 129 | 137 | private static function compareValue(string $a, string $b): int |
| 130 | 138 | { |
| 131 | 139 | // Check "Accept" headers values with it is type and subtype. |
| 132 | - if (\str_contains($a, '/') && \str_contains($b, '/')) { |
|
| 140 | + if (\str_contains($a, '/') && \str_contains($b, '/')) |
|
| 141 | + { |
|
| 133 | 142 | [$typeA, $subtypeA] = \explode('/', $a, 2); |
| 134 | 143 | [$typeB, $subtypeB] = \explode('/', $b, 2); |
| 135 | 144 | |
| 136 | - if ($typeA === $typeB) { |
|
| 145 | + if ($typeA === $typeB) |
|
| 146 | + { |
|
| 137 | 147 | return static::compareAtomic($subtypeA, $subtypeB); |
| 138 | 148 | } |
| 139 | 149 | |
@@ -145,23 +155,28 @@ discard block |
||
| 145 | 155 | |
| 146 | 156 | private static function compareAtomic(string $a, string $b): int |
| 147 | 157 | { |
| 148 | - if (\mb_strpos($a, '*/') === 0) { |
|
| 158 | + if (\mb_strpos($a, '*/') === 0) |
|
| 159 | + { |
|
| 149 | 160 | $a = '*'; |
| 150 | 161 | } |
| 151 | 162 | |
| 152 | - if (\mb_strpos($b, '*/') === 0) { |
|
| 163 | + if (\mb_strpos($b, '*/') === 0) |
|
| 164 | + { |
|
| 153 | 165 | $b = '*'; |
| 154 | 166 | } |
| 155 | 167 | |
| 156 | - if (\strtolower($a) === \strtolower($b)) { |
|
| 168 | + if (\strtolower($a) === \strtolower($b)) |
|
| 169 | + { |
|
| 157 | 170 | return 0; |
| 158 | 171 | } |
| 159 | 172 | |
| 160 | - if ($a === '*') { |
|
| 173 | + if ($a === '*') |
|
| 174 | + { |
|
| 161 | 175 | return -1; |
| 162 | 176 | } |
| 163 | 177 | |
| 164 | - if ($b === '*') { |
|
| 178 | + if ($b === '*') |
|
| 179 | + { |
|
| 165 | 180 | return 1; |
| 166 | 181 | } |
| 167 | 182 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | #[Proxy] private readonly ContainerInterface $container, |
| 122 | 122 | /** @invisible */ |
| 123 | 123 | HttpConfig $config = new HttpConfig() |
| 124 | - ) { |
|
| 124 | + ){ |
|
| 125 | 125 | $this->bagAssociations = \array_merge($this->bagAssociations, $config->getInputBags()); |
| 126 | 126 | } |
| 127 | 127 | |
@@ -150,10 +150,10 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | $input = clone $this; |
| 152 | 152 | |
| 153 | - if ($add) { |
|
| 154 | - $input->prefix .= '.' . $prefix; |
|
| 153 | + if ($add){ |
|
| 154 | + $input->prefix .= '.'.$prefix; |
|
| 155 | 155 | $input->prefix = \trim($input->prefix, '.'); |
| 156 | - } else { |
|
| 156 | + }else{ |
|
| 157 | 157 | $input->prefix = $prefix; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | return match (true) { |
| 171 | 171 | empty($path) => '/', |
| 172 | - $path[0] !== '/' => '/' . $path, |
|
| 172 | + $path[0] !== '/' => '/'.$path, |
|
| 173 | 173 | default => $path |
| 174 | 174 | }; |
| 175 | 175 | } |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | public function request(): Request |
| 191 | 191 | { |
| 192 | - try { |
|
| 192 | + try{ |
|
| 193 | 193 | $request = $this->container->get(Request::class); |
| 194 | - } catch (ContainerExceptionInterface $e) { |
|
| 194 | + }catch (ContainerExceptionInterface $e){ |
|
| 195 | 195 | throw new ScopeException( |
| 196 | 196 | 'Unable to get `ServerRequestInterface` in active container scope', |
| 197 | 197 | $e->getCode(), |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // Flushing input state |
| 203 | - if ($this->request !== $request) { |
|
| 203 | + if ($this->request !== $request){ |
|
| 204 | 204 | $this->bags = []; |
| 205 | 205 | $this->request = $request; |
| 206 | 206 | } |
@@ -215,10 +215,10 @@ discard block |
||
| 215 | 215 | { |
| 216 | 216 | $header = $this->header('Authorization', ''); |
| 217 | 217 | |
| 218 | - $position = \strrpos((string) $header, 'Bearer '); |
|
| 218 | + $position = \strrpos((string)$header, 'Bearer '); |
|
| 219 | 219 | |
| 220 | - if ($position !== false) { |
|
| 221 | - $header = \substr((string) $header, $position + 7); |
|
| 220 | + if ($position !== false){ |
|
| 221 | + $header = \substr((string)$header, $position + 7); |
|
| 222 | 222 | |
| 223 | 223 | return \str_contains($header, ',') |
| 224 | 224 | ? \strstr($header, ',', true) |
@@ -271,16 +271,16 @@ discard block |
||
| 271 | 271 | public function isJsonExpected(bool $softMatch = false): bool |
| 272 | 272 | { |
| 273 | 273 | $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept')); |
| 274 | - foreach ($this->jsonTypes as $jsonType) { |
|
| 275 | - if ($acceptHeader->has($jsonType)) { |
|
| 274 | + foreach ($this->jsonTypes as $jsonType){ |
|
| 275 | + if ($acceptHeader->has($jsonType)){ |
|
| 276 | 276 | return true; |
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - if ($softMatch) { |
|
| 281 | - foreach ($acceptHeader->getAll() as $item) { |
|
| 282 | - $itemValue = \strtolower((string) $item->getValue()); |
|
| 283 | - if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) { |
|
| 280 | + if ($softMatch){ |
|
| 281 | + foreach ($acceptHeader->getAll() as $item){ |
|
| 282 | + $itemValue = \strtolower((string)$item->getValue()); |
|
| 283 | + if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')){ |
|
| 284 | 284 | return true; |
| 285 | 285 | } |
| 286 | 286 | } |
@@ -319,19 +319,19 @@ discard block |
||
| 319 | 319 | // ensure proper request association |
| 320 | 320 | $this->request(); |
| 321 | 321 | |
| 322 | - if (isset($this->bags[$name])) { |
|
| 322 | + if (isset($this->bags[$name])){ |
|
| 323 | 323 | return $this->bags[$name]; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | $definition = $this->findBagDefinition($name); |
| 327 | - if (!$definition) { |
|
| 327 | + if (!$definition){ |
|
| 328 | 328 | throw new InputException(\sprintf("Undefined input bag '%s'", $name)); |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | $class = $definition['class']; |
| 332 | 332 | $data = \call_user_func([$this->request(), $definition['source']]); |
| 333 | 333 | |
| 334 | - if (!\is_array($data)) { |
|
| 334 | + if (!\is_array($data)){ |
|
| 335 | 335 | $data = (array)$data; |
| 336 | 336 | } |
| 337 | 337 | |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | |
| 341 | 341 | public function hasBag(string $name): bool |
| 342 | 342 | { |
| 343 | - if (isset($this->bags[$name])) { |
|
| 343 | + if (isset($this->bags[$name])){ |
|
| 344 | 344 | return true; |
| 345 | 345 | } |
| 346 | 346 | |
@@ -360,12 +360,12 @@ discard block |
||
| 360 | 360 | */ |
| 361 | 361 | private function findBagDefinition(string $name): ?array |
| 362 | 362 | { |
| 363 | - if (isset($this->bagAssociations[$name])) { |
|
| 363 | + if (isset($this->bagAssociations[$name])){ |
|
| 364 | 364 | return $this->bagAssociations[$name]; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - foreach ($this->bagAssociations as $bag) { |
|
| 368 | - if (isset($bag['alias']) && $bag['alias'] === $name) { |
|
| 367 | + foreach ($this->bagAssociations as $bag){ |
|
| 368 | + if (isset($bag['alias']) && $bag['alias'] === $name){ |
|
| 369 | 369 | return $bag; |
| 370 | 370 | } |
| 371 | 371 | } |
@@ -150,10 +150,13 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | $input = clone $this; |
| 152 | 152 | |
| 153 | - if ($add) { |
|
| 153 | + if ($add) |
|
| 154 | + { |
|
| 154 | 155 | $input->prefix .= '.' . $prefix; |
| 155 | 156 | $input->prefix = \trim($input->prefix, '.'); |
| 156 | - } else { |
|
| 157 | + } |
|
| 158 | + else |
|
| 159 | + { |
|
| 157 | 160 | $input->prefix = $prefix; |
| 158 | 161 | } |
| 159 | 162 | |
@@ -189,9 +192,12 @@ discard block |
||
| 189 | 192 | */ |
| 190 | 193 | public function request(): Request |
| 191 | 194 | { |
| 192 | - try { |
|
| 195 | + try |
|
| 196 | + { |
|
| 193 | 197 | $request = $this->container->get(Request::class); |
| 194 | - } catch (ContainerExceptionInterface $e) { |
|
| 198 | + } |
|
| 199 | + catch (ContainerExceptionInterface $e) |
|
| 200 | + { |
|
| 195 | 201 | throw new ScopeException( |
| 196 | 202 | 'Unable to get `ServerRequestInterface` in active container scope', |
| 197 | 203 | $e->getCode(), |
@@ -200,7 +206,8 @@ discard block |
||
| 200 | 206 | } |
| 201 | 207 | |
| 202 | 208 | // Flushing input state |
| 203 | - if ($this->request !== $request) { |
|
| 209 | + if ($this->request !== $request) |
|
| 210 | + { |
|
| 204 | 211 | $this->bags = []; |
| 205 | 212 | $this->request = $request; |
| 206 | 213 | } |
@@ -217,7 +224,8 @@ discard block |
||
| 217 | 224 | |
| 218 | 225 | $position = \strrpos((string) $header, 'Bearer '); |
| 219 | 226 | |
| 220 | - if ($position !== false) { |
|
| 227 | + if ($position !== false) |
|
| 228 | + { |
|
| 221 | 229 | $header = \substr((string) $header, $position + 7); |
| 222 | 230 | |
| 223 | 231 | return \str_contains($header, ',') |
@@ -271,16 +279,21 @@ discard block |
||
| 271 | 279 | public function isJsonExpected(bool $softMatch = false): bool |
| 272 | 280 | { |
| 273 | 281 | $acceptHeader = AcceptHeader::fromString($this->request()->getHeaderLine('Accept')); |
| 274 | - foreach ($this->jsonTypes as $jsonType) { |
|
| 275 | - if ($acceptHeader->has($jsonType)) { |
|
| 282 | + foreach ($this->jsonTypes as $jsonType) |
|
| 283 | + { |
|
| 284 | + if ($acceptHeader->has($jsonType)) |
|
| 285 | + { |
|
| 276 | 286 | return true; |
| 277 | 287 | } |
| 278 | 288 | } |
| 279 | 289 | |
| 280 | - if ($softMatch) { |
|
| 281 | - foreach ($acceptHeader->getAll() as $item) { |
|
| 290 | + if ($softMatch) |
|
| 291 | + { |
|
| 292 | + foreach ($acceptHeader->getAll() as $item) |
|
| 293 | + { |
|
| 282 | 294 | $itemValue = \strtolower((string) $item->getValue()); |
| 283 | - if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) { |
|
| 295 | + if (\str_ends_with($itemValue, '/json') || \str_ends_with($itemValue, '+json')) |
|
| 296 | + { |
|
| 284 | 297 | return true; |
| 285 | 298 | } |
| 286 | 299 | } |
@@ -319,19 +332,22 @@ discard block |
||
| 319 | 332 | // ensure proper request association |
| 320 | 333 | $this->request(); |
| 321 | 334 | |
| 322 | - if (isset($this->bags[$name])) { |
|
| 335 | + if (isset($this->bags[$name])) |
|
| 336 | + { |
|
| 323 | 337 | return $this->bags[$name]; |
| 324 | 338 | } |
| 325 | 339 | |
| 326 | 340 | $definition = $this->findBagDefinition($name); |
| 327 | - if (!$definition) { |
|
| 341 | + if (!$definition) |
|
| 342 | + { |
|
| 328 | 343 | throw new InputException(\sprintf("Undefined input bag '%s'", $name)); |
| 329 | 344 | } |
| 330 | 345 | |
| 331 | 346 | $class = $definition['class']; |
| 332 | 347 | $data = \call_user_func([$this->request(), $definition['source']]); |
| 333 | 348 | |
| 334 | - if (!\is_array($data)) { |
|
| 349 | + if (!\is_array($data)) |
|
| 350 | + { |
|
| 335 | 351 | $data = (array)$data; |
| 336 | 352 | } |
| 337 | 353 | |
@@ -340,7 +356,8 @@ discard block |
||
| 340 | 356 | |
| 341 | 357 | public function hasBag(string $name): bool |
| 342 | 358 | { |
| 343 | - if (isset($this->bags[$name])) { |
|
| 359 | + if (isset($this->bags[$name])) |
|
| 360 | + { |
|
| 344 | 361 | return true; |
| 345 | 362 | } |
| 346 | 363 | |
@@ -360,12 +377,15 @@ discard block |
||
| 360 | 377 | */ |
| 361 | 378 | private function findBagDefinition(string $name): ?array |
| 362 | 379 | { |
| 363 | - if (isset($this->bagAssociations[$name])) { |
|
| 380 | + if (isset($this->bagAssociations[$name])) |
|
| 381 | + { |
|
| 364 | 382 | return $this->bagAssociations[$name]; |
| 365 | 383 | } |
| 366 | 384 | |
| 367 | - foreach ($this->bagAssociations as $bag) { |
|
| 368 | - if (isset($bag['alias']) && $bag['alias'] === $name) { |
|
| 385 | + foreach ($this->bagAssociations as $bag) |
|
| 386 | + { |
|
| 387 | + if (isset($bag['alias']) && $bag['alias'] === $name) |
|
| 388 | + { |
|
| 369 | 389 | return $bag; |
| 370 | 390 | } |
| 371 | 391 | } |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | { |
| 11 | 11 | public function __construct( |
| 12 | 12 | private readonly DebugMode $debugMode |
| 13 | - ) { |
|
| 13 | + ){ |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function suppressed(): bool |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | private readonly UriFactoryInterface $uriFactory, |
| 56 | 56 | SlugifyInterface $slugify = null, |
| 57 | 57 | private readonly RoutePatternRegistryInterface $patternRegistry = new DefaultPatternRegistry(), |
| 58 | - ) { |
|
| 58 | + ){ |
|
| 59 | 59 | $slugify ??= new Slugify(); |
| 60 | 60 | $this->pathSegmentEncoder = static fn (string $segment): string => $slugify->slugify($segment); |
| 61 | 61 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | public function withBasePath(string $basePath): self |
| 120 | 120 | { |
| 121 | - if (!\str_ends_with($basePath, '/')) { |
|
| 121 | + if (!\str_ends_with($basePath, '/')){ |
|
| 122 | 122 | $basePath .= '/'; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | public function match(UriInterface $uri, array $defaults): ?array |
| 170 | 170 | { |
| 171 | - if (!$this->isCompiled()) { |
|
| 171 | + if (!$this->isCompiled()){ |
|
| 172 | 172 | $this->compile(); |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | $matches = []; |
| 176 | - if (!\preg_match($this->compiled, $this->fetchTarget($uri), $matches)) { |
|
| 176 | + if (!\preg_match($this->compiled, $this->fetchTarget($uri), $matches)){ |
|
| 177 | 177 | return null; |
| 178 | 178 | } |
| 179 | 179 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | public function uri(iterable $parameters = [], array $defaults = []): UriInterface |
| 192 | 192 | { |
| 193 | - if (!$this->isCompiled()) { |
|
| 193 | + if (!$this->isCompiled()){ |
|
| 194 | 194 | $this->compile(); |
| 195 | 195 | } |
| 196 | 196 | |
@@ -200,8 +200,8 @@ discard block |
||
| 200 | 200 | $this->fetchOptions($parameters, $query) |
| 201 | 201 | ); |
| 202 | 202 | |
| 203 | - foreach ($this->constrains as $key => $_) { |
|
| 204 | - if (empty($parameters[$key])) { |
|
| 203 | + foreach ($this->constrains as $key => $_){ |
|
| 204 | + if (empty($parameters[$key])){ |
|
| 205 | 205 | throw new UriHandlerException(\sprintf('Unable to generate Uri, parameter `%s` is missing', $key)); |
| 206 | 206 | } |
| 207 | 207 | } |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | $path = $this->interpolate($this->template, $parameters); |
| 211 | 211 | |
| 212 | 212 | //Uri with added base path and prefix |
| 213 | - $uri = $this->uriFactory->createUri(($this->matchHost ? '' : $this->basePath) . \trim($path, '/')); |
|
| 213 | + $uri = $this->uriFactory->createUri(($this->matchHost ? '' : $this->basePath).\trim($path, '/')); |
|
| 214 | 214 | |
| 215 | 215 | return empty($query) ? $uri : $uri->withQuery(\http_build_query($query)); |
| 216 | 216 | } |
@@ -225,18 +225,18 @@ discard block |
||
| 225 | 225 | $allowed = \array_keys($this->options); |
| 226 | 226 | |
| 227 | 227 | $result = []; |
| 228 | - foreach ($parameters as $key => $parameter) { |
|
| 229 | - if (\is_int($key) && isset($allowed[$key])) { |
|
| 228 | + foreach ($parameters as $key => $parameter){ |
|
| 229 | + if (\is_int($key) && isset($allowed[$key])){ |
|
| 230 | 230 | // this segment fetched keys from given parameters either by name or by position |
| 231 | 231 | $key = $allowed[$key]; |
| 232 | - } elseif (!\array_key_exists($key, $this->options) && \is_array($parameters)) { |
|
| 232 | + } elseif (!\array_key_exists($key, $this->options) && \is_array($parameters)){ |
|
| 233 | 233 | // all additional parameters given in array form can be glued to query string |
| 234 | 234 | $query[$key] = $parameter; |
| 235 | 235 | continue; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // String must be normalized here |
| 239 | - if (\is_string($parameter) && !\preg_match('/^[a-z\-_0-9]+$/i', $parameter)) { |
|
| 239 | + if (\is_string($parameter) && !\preg_match('/^[a-z\-_0-9]+$/i', $parameter)){ |
|
| 240 | 240 | $result[$key] = ($this->pathSegmentEncoder)($parameter); |
| 241 | 241 | continue; |
| 242 | 242 | } |
@@ -254,15 +254,15 @@ discard block |
||
| 254 | 254 | { |
| 255 | 255 | $path = $uri->getPath(); |
| 256 | 256 | |
| 257 | - if (empty($path) || $path[0] !== '/') { |
|
| 258 | - $path = '/' . $path; |
|
| 257 | + if (empty($path) || $path[0] !== '/'){ |
|
| 258 | + $path = '/'.$path; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - if ($this->matchHost) { |
|
| 262 | - $uriString = $uri->getHost() . $path; |
|
| 263 | - } else { |
|
| 261 | + if ($this->matchHost){ |
|
| 262 | + $uriString = $uri->getHost().$path; |
|
| 263 | + }else{ |
|
| 264 | 264 | $uriString = \substr($path, \strlen($this->basePath)); |
| 265 | - if ($uriString === false) { |
|
| 265 | + if ($uriString === false){ |
|
| 266 | 266 | $uriString = ''; |
| 267 | 267 | } |
| 268 | 268 | } |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | */ |
| 279 | 279 | private function compile(): void |
| 280 | 280 | { |
| 281 | - if ($this->pattern === null) { |
|
| 281 | + if ($this->pattern === null){ |
|
| 282 | 282 | throw new UriHandlerException('Unable to compile UriHandler, pattern is not set'); |
| 283 | 283 | } |
| 284 | 284 | |
@@ -287,18 +287,18 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | $prefix = \rtrim($this->getPrefix(), '/ '); |
| 289 | 289 | $pattern = \ltrim($this->pattern, '/ '); |
| 290 | - $pattern = $prefix . '/' . $pattern; |
|
| 290 | + $pattern = $prefix.'/'.$pattern; |
|
| 291 | 291 | $pattern = \rtrim(\ltrim($pattern, ':/'), '/'); |
| 292 | 292 | |
| 293 | 293 | // correct [/ first occurrence] |
| 294 | - if (\str_starts_with($pattern, '[/')) { |
|
| 295 | - $pattern = '[' . \substr($pattern, 2); |
|
| 294 | + if (\str_starts_with($pattern, '[/')){ |
|
| 295 | + $pattern = '['.\substr($pattern, 2); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | - if (\preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)) { |
|
| 298 | + if (\preg_match_all('/<(\w+):?(.*?)?>/', $pattern, $matches)){ |
|
| 299 | 299 | $variables = \array_combine($matches[1], $matches[2]); |
| 300 | 300 | |
| 301 | - foreach ($variables as $key => $segment) { |
|
| 301 | + foreach ($variables as $key => $segment){ |
|
| 302 | 302 | $segment = $this->prepareSegment($key, $segment); |
| 303 | 303 | $replaces[\sprintf('<%s>', $key)] = \sprintf('(?P<%s>%s)', $key, $segment); |
| 304 | 304 | $options[] = $key; |
@@ -308,13 +308,13 @@ discard block |
||
| 308 | 308 | $template = \preg_replace('/<(\w+):?.*?>/', '<\1>', $pattern); |
| 309 | 309 | $options = \array_fill_keys($options, null); |
| 310 | 310 | |
| 311 | - foreach ($this->constrains as $key => $value) { |
|
| 312 | - if ($value instanceof Autofill) { |
|
| 311 | + foreach ($this->constrains as $key => $value){ |
|
| 312 | + if ($value instanceof Autofill){ |
|
| 313 | 313 | // only forces value replacement, not required to be presented as parameter |
| 314 | 314 | continue; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - if (!\array_key_exists($key, $options) && !isset($this->defaults[$key])) { |
|
| 317 | + if (!\array_key_exists($key, $options) && !isset($this->defaults[$key])){ |
|
| 318 | 318 | throw new ConstrainException( |
| 319 | 319 | \sprintf( |
| 320 | 320 | 'Route `%s` does not define routing parameter `<%s>`.', |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | } |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - $this->compiled = '/^' . \strtr($template, $replaces + self::PATTERN_REPLACES) . '$/iu'; |
|
| 328 | + $this->compiled = '/^'.\strtr($template, $replaces + self::PATTERN_REPLACES).'$/iu'; |
|
| 329 | 329 | $this->template = \stripslashes(\str_replace('?', '', $template)); |
| 330 | 330 | $this->options = $options; |
| 331 | 331 | } |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | private function interpolate(string $string, array $values): string |
| 337 | 337 | { |
| 338 | 338 | $replaces = []; |
| 339 | - foreach ($values as $key => $value) { |
|
| 339 | + foreach ($values as $key => $value){ |
|
| 340 | 340 | $replaces[\sprintf('<%s>', $key)] = match (true) { |
| 341 | 341 | $value instanceof \Stringable || \is_scalar($value) => (string)$value, |
| 342 | 342 | default => '', |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | private readonly ContainerInterface $container, |
| 52 | 52 | private readonly ?EventDispatcherInterface $eventDispatcher = null, |
| 53 | 53 | private readonly TracerInterface $tracer = new NullTracer(), |
| 54 | - ) { |
|
| 55 | - $this->basePath = '/' . \ltrim($basePath, '/'); |
|
| 54 | + ){ |
|
| 55 | + $this->basePath = '/'.\ltrim($basePath, '/'); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | return $this->tracer->trace( |
| 67 | 67 | name: 'Routing', |
| 68 | 68 | callback: function (SpanInterface $span) use ($request) { |
| 69 | - try { |
|
| 69 | + try{ |
|
| 70 | 70 | $route = $this->matchRoute($request, $routeName); |
| 71 | - } catch (RouteException $e) { |
|
| 71 | + }catch (RouteException $e){ |
|
| 72 | 72 | throw new RouterException('Invalid route definition', $e->getCode(), $e); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ($route === null) { |
|
| 75 | + if ($route === null){ |
|
| 76 | 76 | $this->eventDispatcher?->dispatch(new RouteNotFound($request)); |
| 77 | 77 | throw new RouteNotFoundException($request->getUri()); |
| 78 | 78 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | public function getRoute(string $name): RouteInterface |
| 109 | 109 | { |
| 110 | - if (isset($this->routes[$name])) { |
|
| 110 | + if (isset($this->routes[$name])){ |
|
| 111 | 111 | return $this->routes[$name]; |
| 112 | 112 | } |
| 113 | 113 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | public function getRoutes(): array |
| 118 | 118 | { |
| 119 | - if (!empty($this->default)) { |
|
| 119 | + if (!empty($this->default)){ |
|
| 120 | 120 | return $this->routes + [null => $this->default]; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | public function uri(string $route, iterable $parameters = []): UriInterface |
| 127 | 127 | { |
| 128 | - try { |
|
| 128 | + try{ |
|
| 129 | 129 | return $this->getRoute($route)->uri($parameters); |
| 130 | - } catch (UndefinedRouteException) { |
|
| 130 | + }catch (UndefinedRouteException){ |
|
| 131 | 131 | //In some cases route name can be provided as controller:action pair, we can try to |
| 132 | 132 | //generate such route automatically based on our default/fallback route |
| 133 | 133 | return $this->castRoute($route)->uri($parameters); |
@@ -139,9 +139,9 @@ discard block |
||
| 139 | 139 | /** @var GroupRegistry $groups */ |
| 140 | 140 | $groups = $this->container->get(GroupRegistry::class); |
| 141 | 141 | |
| 142 | - foreach ($routes->getCollection() as $name => $configurator) { |
|
| 142 | + foreach ($routes->getCollection() as $name => $configurator){ |
|
| 143 | 143 | $target = $configurator->target; |
| 144 | - if ($configurator->core !== null && $target instanceof AbstractTarget) { |
|
| 144 | + if ($configurator->core !== null && $target instanceof AbstractTarget){ |
|
| 145 | 145 | $target = $target->withCore($configurator->core); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -150,21 +150,21 @@ discard block |
||
| 150 | 150 | : \ltrim($configurator->pattern, '/'); |
| 151 | 151 | $route = new Route($pattern, $target, $configurator->defaults); |
| 152 | 152 | |
| 153 | - if ($configurator->middleware !== null) { |
|
| 153 | + if ($configurator->middleware !== null){ |
|
| 154 | 154 | $route = $route->withMiddleware(...$configurator->middleware); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - if ($configurator->methods !== null) { |
|
| 157 | + if ($configurator->methods !== null){ |
|
| 158 | 158 | $route = $route->withVerbs(...$configurator->methods); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
| 161 | + if (!isset($this->routes[$name]) && $name !== RoutingConfigurator::DEFAULT_ROUTE_NAME){ |
|
| 162 | 162 | $group = $groups->getGroup($configurator->group ?? $groups->getDefaultGroup()); |
| 163 | 163 | $group->setPrefix($configurator->prefix); |
| 164 | 164 | $group->addRoute($name, $route); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME) { |
|
| 167 | + if ($name === RoutingConfigurator::DEFAULT_ROUTE_NAME){ |
|
| 168 | 168 | $this->setDefault($route); |
| 169 | 169 | } |
| 170 | 170 | } |
@@ -175,17 +175,17 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | protected function matchRoute(ServerRequestInterface $request, string &$routeName = null): ?RouteInterface |
| 177 | 177 | { |
| 178 | - foreach ($this->routes as $name => $route) { |
|
| 178 | + foreach ($this->routes as $name => $route){ |
|
| 179 | 179 | // Matched route will return new route instance with matched parameters |
| 180 | 180 | $matched = $route->match($request); |
| 181 | 181 | |
| 182 | - if ($matched !== null) { |
|
| 182 | + if ($matched !== null){ |
|
| 183 | 183 | $routeName = $name; |
| 184 | 184 | return $matched; |
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - if ($this->default !== null) { |
|
| 188 | + if ($this->default !== null){ |
|
| 189 | 189 | return $this->default->match($request); |
| 190 | 190 | } |
| 191 | 191 | |
@@ -198,14 +198,14 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | protected function configure(RouteInterface $route): RouteInterface |
| 200 | 200 | { |
| 201 | - if ($route instanceof ContainerizedInterface && !$route->hasContainer()) { |
|
| 201 | + if ($route instanceof ContainerizedInterface && !$route->hasContainer()){ |
|
| 202 | 202 | // isolating route in a given container |
| 203 | 203 | $route = $route->withContainer($this->container); |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - try { |
|
| 206 | + try{ |
|
| 207 | 207 | $uriHandler = $route->getUriHandler(); |
| 208 | - } catch (\Throwable) { |
|
| 208 | + }catch (\Throwable){ |
|
| 209 | 209 | $uriHandler = $this->uriHandler; |
| 210 | 210 | } |
| 211 | 211 | |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | $route, |
| 229 | 229 | $matches |
| 230 | 230 | ) |
| 231 | - ) { |
|
| 231 | + ){ |
|
| 232 | 232 | throw new UndefinedRouteException( |
| 233 | 233 | "Unable to locate route or use default route with 'name/controller:action' pattern" |
| 234 | 234 | ); |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | /** |
| 238 | 238 | * @var Matches $matches |
| 239 | 239 | */ |
| 240 | - if (!empty($matches['name'])) { |
|
| 240 | + if (!empty($matches['name'])){ |
|
| 241 | 241 | $routeObject = $this->getRoute($matches['name']); |
| 242 | - } elseif ($this->default !== null) { |
|
| 242 | + } elseif ($this->default !== null){ |
|
| 243 | 243 | $routeObject = $this->default; |
| 244 | - } else { |
|
| 244 | + }else{ |
|
| 245 | 245 | throw new UndefinedRouteException(\sprintf('Unable to locate route candidate for `%s`', $route)); |
| 246 | 246 | } |
| 247 | 247 | |