vendor/api-platform/core/src/Symfony/Bundle/DependencyInjection/Compiler/TestClientPass.php line 29

  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\Symfony\Bundle\Test\Client;
  13. use Symfony\Component\BrowserKit\AbstractBrowser;
  14. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  15. use Symfony\Component\DependencyInjection\ContainerBuilder;
  16. use Symfony\Component\DependencyInjection\Definition;
  17. use Symfony\Component\DependencyInjection\Reference;
  18. use Symfony\Component\HttpClient\HttpClientTrait;
  19. final class TestClientPass implements CompilerPassInterface
  20. {
  21.     public function process(ContainerBuilder $container): void
  22.     {
  23.         if (
  24.             !class_exists(AbstractBrowser::class)
  25.             || !trait_exists(HttpClientTrait::class)
  26.             || !$container->hasParameter('test.client.parameters')
  27.         ) {
  28.             return;
  29.         }
  30.         $container->setDefinition(
  31.             'test.api_platform.client',
  32.             (new Definition(Client::class, [new Reference('test.client')]))
  33.                 ->setShared(false)
  34.                 ->setPublic(true)
  35.         );
  36.     }
  37. }