Sofascore Purgatory Bundle

Custom Route Providers

To create a custom route provider, implement the RouteProviderInterface. This interface defines two methods:

Example

Here’s an example of a custom route provider for handling Post entities:

use Sofascore\PurgatoryBundle\RouteProvider\PurgeRoute;
use Sofascore\PurgatoryBundle\Listener\Enum\Action;
use Sofascore\PurgatoryBundle\RouteProvider\RouteProviderInterface;

class MyPostRouteProvider implements RouteProviderInterface
{
    public function provideRoutesFor(Action $action, object $entity, array $entityChangeSet): iterable
    {
        // Custom logic to determine routes based on the action, entity, and changes

        yield new PurgeRoute(
            name: 'route_name',
            params: [
                // Route parameters go here
            ]
        );
    }

    public function supports(Action $action, object $entity): bool
    {
        // Define the conditions under which this provider should be used
        return $entity instanceof Post;
    }
}

Registering Your Custom Route Provider

If you’re not using Symfony’s autoconfigure feature, you need to manually tag the service:

# services.yaml
App\RouteProvider\MyPostRouteProvider:
    tags:
        - { name: 'purgatory.route_provider' }

By tagging it with purgatory.route_provider, the bundle will automatically recognize and use your custom route provider when processing purge requests.