vendor/api-platform/core/src/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php line 40

  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace ApiPlatform\Symfony\Bundle\DependencyInjection\Compiler;
  12. use ApiPlatform\State\SerializerAwareProviderInterface;
  13. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\Reference;
  16. /**
  17.  * Registers data providers.
  18.  *
  19.  * @internal
  20.  *
  21.  * @author Kévin Dunglas <dunglas@gmail.com>
  22.  * @author Vincent Chalamon <vincentchalamon@gmail.com>
  23.  */
  24. final class DataProviderPass implements CompilerPassInterface
  25. {
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     public function process(ContainerBuilder $container): void
  30.     {
  31.         $services $container->findTaggedServiceIds('api_platform.state_provider'true);
  32.         foreach ($services as $id => $tags) {
  33.             $definition $container->getDefinition((string) $id);
  34.             if (is_a($definition->getClass(), SerializerAwareProviderInterface::class, true)) {
  35.                 $definition->addMethodCall('setSerializerLocator', [new Reference('api_platform.serializer_locator')]);
  36.             }
  37.         }
  38.     }
  39. }