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

Open in your IDE?
  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\Core\Api\OperationType;
  13. use ApiPlatform\Core\DataProvider\SerializerAwareDataProviderInterface;
  14. use ApiPlatform\State\SerializerAwareProviderInterface;
  15. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. use Symfony\Component\DependencyInjection\Reference;
  18. /**
  19. * Registers data providers.
  20. *
  21. * @internal
  22. *
  23. * @author Kévin Dunglas <dunglas@gmail.com>
  24. * @author Vincent Chalamon <vincentchalamon@gmail.com>
  25. */
  26. final class DataProviderPass implements CompilerPassInterface
  27. {
  28. public function process(ContainerBuilder $container)
  29. {
  30. foreach (OperationType::TYPES as $type) {
  31. $this->addSerializerLocator($container, $type);
  32. }
  33. $services = $container->findTaggedServiceIds('api_platform.state_provider', true);
  34. foreach ($services as $id => $tags) {
  35. $definition = $container->getDefinition((string) $id);
  36. if (is_a($definition->getClass(), SerializerAwareProviderInterface::class, true)) {
  37. $definition->addMethodCall('setSerializerLocator', [new Reference('api_platform.serializer_locator')]);
  38. }
  39. }
  40. }
  41. private function addSerializerLocator(ContainerBuilder $container, string $type): void
  42. {
  43. $services = $container->findTaggedServiceIds("api_platform.{$type}_data_provider", true);
  44. foreach ($services as $id => $tags) {
  45. $definition = $container->getDefinition((string) $id);
  46. if (is_a($definition->getClass(), SerializerAwareDataProviderInterface::class, true)) {
  47. $definition->addMethodCall('setSerializerLocator', [new Reference('api_platform.serializer_locator')]);
  48. }
  49. }
  50. }
  51. }
  52. class_alias(DataProviderPass::class, \ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\DataProviderPass::class);