Skip to content

Commit 058a118

Browse files
committed
Update Symfony dependencies to 7.4+, refactor route loader to use attribute class
1 parent d501969 commit 058a118

6 files changed

Lines changed: 32 additions & 13 deletions

File tree

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
],
1515
"require": {
1616
"php": ">=8.2",
17-
"symfony/framework-bundle": "^7.0|^8.0",
18-
"symfony/property-access": "^7.0|^8.0",
19-
"symfony/serializer": "^7.0|^8.0",
20-
"symfony/validator": "^7.0|^8.0",
17+
"symfony/framework-bundle": "^7.4|^8.0",
18+
"symfony/property-access": "^7.4|^8.0",
19+
"symfony/serializer": "^7.4|^8.0",
20+
"symfony/validator": "^7.4|^8.0",
2121
"zircote/swagger-php": "^4.7",
22-
"symfony/expression-language": "^7.0|^8.0"
22+
"symfony/expression-language": "^7.4|^8.0"
2323
},
2424
"require-dev": {
2525
"roave/security-advisories": "dev-latest",

config/services/routing.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@
1313
->set('routing.loader.attribute.post')
1414
->class(OpenApiRouteControllerLoader::class)
1515
->args(['%kernel.environment%'])
16-
->call('setRouteAnnotationClass', [Post::class])
16+
->call('setRouteAttributeClass', [Post::class])
1717
->tag('routing.loader', ['priority' => -5])
1818

1919
->set('routing.loader.attribute.get')
2020
->class(OpenApiRouteControllerLoader::class)
2121
->args(['%kernel.environment%'])
22-
->call('setRouteAnnotationClass', [Get::class])
22+
->call('setRouteAttributeClass', [Get::class])
2323
->tag('routing.loader', ['priority' => -5])
2424

2525
->set('routing.loader.attribute.put')
2626
->class(OpenApiRouteControllerLoader::class)
2727
->args(['%kernel.environment%'])
28-
->call('setRouteAnnotationClass', [Put::class])
28+
->call('setRouteAttributeClass', [Put::class])
2929
->tag('routing.loader', ['priority' => -5])
3030

3131
->set('routing.loader.attribute.patch')
3232
->class(OpenApiRouteControllerLoader::class)
3333
->args(['%kernel.environment%'])
34-
->call('setRouteAnnotationClass', [Patch::class])
34+
->call('setRouteAttributeClass', [Patch::class])
3535
->tag('routing.loader', ['priority' => -5])
3636

3737
->set('routing.loader.attribute.delete')
3838
->class(OpenApiRouteControllerLoader::class)
3939
->args(['%kernel.environment%'])
40-
->call('setRouteAnnotationClass', [Delete::class])
40+
->call('setRouteAttributeClass', [Delete::class])
4141
->tag('routing.loader', ['priority' => -5])
4242
;
4343
};

src/Routing/Attribute/ApiRouteTrait.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,16 @@ public function __call(string $name, array $arguments): mixed
105105
return $this->route->{$name}(...$arguments);
106106
}
107107

108+
public function __get(string $name): mixed
109+
{
110+
if (property_exists($this->route, $name)) {
111+
return $this->route->{$name};
112+
}
113+
114+
parent::__get($name);
115+
116+
return null;
117+
}
118+
108119
abstract public function getMethod(): string;
109120
}

src/Routing/Loader/OpenApiRouteControllerLoader.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,26 @@
1717

1818
class OpenApiRouteControllerLoader extends AttributeRouteControllerLoader
1919
{
20+
private string $routeAttributeClass;
21+
2022
public function supports(mixed $resource, ?string $type = null): bool
2123
{
2224
return parent::supports($resource, $type) && $this->isOpenApiController($resource);
2325
}
2426

27+
public function setRouteAttributeClass(string $class): void
28+
{
29+
$this->routeAttributeClass = $class;
30+
31+
parent::setRouteAttributeClass($class);
32+
}
33+
2534
private function isOpenApiController(mixed $resource): bool
2635
{
2736
$reflection = new \ReflectionClass($resource);
2837

2938
foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
30-
if ($reflectionMethod->getAttributes($this->routeAnnotationClass, \ReflectionAttribute::IS_INSTANCEOF)) {
39+
if ($reflectionMethod->getAttributes($this->routeAttributeClass, \ReflectionAttribute::IS_INSTANCEOF)) {
3140
return true;
3241
}
3342
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"type":"https:\/\/symfony.com\/errors\/validation","title":"Validation Failed","status":422,"detail":"name: This value is too short. It should have 3 characters or more.\nstatus: The value you selected is not a valid choice.","violations":[{"propertyPath":"name","title":"This value is too short. It should have 3 characters or more.","template":"This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.","parameters":{"{{ value }}":"\"fo\"","{{ limit }}":"3","{{ value_length }}":"2"},"type":"urn:uuid:9ff3fdc4-b214-49db-8718-39c315e33d45"},{"propertyPath":"status","title":"The value you selected is not a valid choice.","template":"The value you selected is not a valid choice.","parameters":{"{{ value }}":"\"dra\"","{{ choices }}":"\"draft\", \"published\""},"type":"urn:uuid:8e179f1b-97aa-4560-a02f-2a8b42e49df7"}]}
1+
{"type":"https:\/\/symfony.com\/errors\/validation","title":"Validation Failed","status":422,"detail":"name: This value is too short. It should have 3 characters or more.\nstatus: The value you selected is not a valid choice.","violations":[{"propertyPath":"name","title":"This value is too short. It should have 3 characters or more.","template":"This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.","parameters":{"{{ value }}":"\"fo\"","{{ limit }}":"3","{{ min }}":"3","{{ value_length }}":"2"},"type":"urn:uuid:9ff3fdc4-b214-49db-8718-39c315e33d45"},{"propertyPath":"status","title":"The value you selected is not a valid choice.","template":"The value you selected is not a valid choice.","parameters":{"{{ value }}":"\"dra\"","{{ choices }}":"\"draft\", \"published\""},"type":"urn:uuid:8e179f1b-97aa-4560-a02f-2a8b42e49df7"}]}

tests/Functional/App/config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
framework:
2-
annotations: false
32
http_method_override: false
43
handle_all_throwables: true
54
secret: test

0 commit comments

Comments
 (0)