Providers

Providers retrieve data from your persistence layer.

Default providers

When your resource is a Doctrine entity, there's a default provider Sylius\Component\Resource\Symfony\Request\State\Provider which is already configured to your operations.

As it uses the Doctrine repository configured on your resource, some default repository methods are used.

Operation
Repository method

index

createPaginator

show

findOneBy

update

findOneBy

delete

findOneBy

bulk delete

findById

Custom repository method

You can customize the method to use.

Custom repository arguments

You can pass arguments to your repository method.

3 variables are available:

  • request: to retrieve data from the request via Symfony\Component\HttpFoundation\Request

  • token: to retrieve data from the authentication token via Symfony\Component\Security\Core\Authentication\Token\TokenInterface

  • user: to retrieve data from the logged-in user via Symfony\Component\Security\Core\User\UserInterface

It uses the Symfony expression language component.

Custom providers

Custom providers are useful to customize your logic to retrieve data and for an advanced usage such as an hexagonal architecture.

As an example, let's configure a BoardGameItemProvider on a BoardGameResource which is not a Doctrine entity.

Use this provider on your operation.

Disable providing data

In some cases, you may want not to read data.

For example, in a delete operation, you can implement your custom delete processor without reading it before.

Last updated