Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
22 changes: 20 additions & 2 deletions docs/complex-route-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/purge-subscriptions-using-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
```
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
}
Loading