From a21b3316aaddd5251be9a2ccb020183bd43b9239 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Mon, 15 Dec 2025 08:09:21 +0100 Subject: [PATCH] Improve docs --- docs/README.md | 2 +- docs/complex-route-params.md | 22 +++++++++++++++++-- docs/purge-subscriptions-using-yaml.md | 6 +++++ .../Controller/VehicleController.php | 2 +- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index da3aaf92..f69f602f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -362,7 +362,7 @@ class Post ### Adding Conditional Logic with Expression Language -[Symfony's Expression Language component](https://symfony.com/doc/current/components/expression_language.html) can be +[Symfony's ExpressionLanguage component](https://symfony.com/doc/current/components/expression_language.html) can be used to add conditions that must be met for the purge to occur. In these expressions, the entity is available as the `obj` variable: diff --git a/docs/complex-route-params.md b/docs/complex-route-params.md index d33d615d..ae15e887 100644 --- a/docs/complex-route-params.md +++ b/docs/complex-route-params.md @@ -7,7 +7,7 @@ values to create flexible and powerful purge rules. ## Using Nested Properties You can access nested properties of an entity to define route parameters by -using [Symfony's Property Access](https://symfony.com/doc/current/components/property_access.html) syntax: +using [Symfony's PropertyAccess](https://symfony.com/doc/current/components/property_access.html) syntax: ```php #[Route('/author/{id<\d+>}', name: 'author_details', methods: 'GET')] @@ -134,7 +134,25 @@ public function listAction(string $lang) } ``` -To make this work, ensure your service is tagged correctly in the service configuration: +By default, the entire entity being purged is passed to the route parameter service. +If your service only needs a specific part of the entity, you can limit what is passed by providing a second argument to +`DynamicValues`. + +This argument is a **Symfony PropertyAccess property path** and will be resolved against the entity before being passed +to the service: + +```php +use Sofascore\PurgatoryBundle\Attribute\RouteParamValue\DynamicValues; + +#[Route('/posts/{type}', name: 'posts_list', methods: 'GET')] +#[PurgeOn(Post::class, routeParams: ['type' => new DynamicValues('my_service', 'property')])] +public function listAction(string $lang) +{ +} +``` + +To make the service available for resolving route parameter values, ensure it is tagged correctly in the service +configuration: ```yaml # services.yaml diff --git a/docs/purge-subscriptions-using-yaml.md b/docs/purge-subscriptions-using-yaml.md index 2ff5e33c..5ca6974e 100644 --- a/docs/purge-subscriptions-using-yaml.md +++ b/docs/purge-subscriptions-using-yaml.md @@ -63,4 +63,10 @@ posts_list: class: App\Entity\Post route_params: type: !dynamic my_service + +# Limiting the value passed to the service using a property path +posts_list: + class: App\Entity\Post + route_params: + type: !dynamic [ my_service, prop ] ``` diff --git a/tests/Functional/TestApplication/Controller/VehicleController.php b/tests/Functional/TestApplication/Controller/VehicleController.php index 930761d8..a706c94b 100644 --- a/tests/Functional/TestApplication/Controller/VehicleController.php +++ b/tests/Functional/TestApplication/Controller/VehicleController.php @@ -18,7 +18,7 @@ class VehicleController #[Route('/{id}/number-of-engines', 'number_of_engines')] #[AnnotationRoute('/{id}/number-of-engines', name: 'number_of_engines')] #[PurgeOn(Vehicle::class, target: 'numberOfEngines')] - public function numberOfEnginesAction(Vehicle $animal) + public function numberOfEnginesAction(Vehicle $vehicle) { } }