vendor/ajgarlag/psr-http-message-bundle/src/DependencyInjection/AjgarlagPsrHttpMessageExtension.php line 28

Open in your IDE?
  1. <?php
  2. /*
  3. * PsrHttpMessageBundle by @ajgarlag
  4. *
  5. * Copyright (c) 2010-2022 Fabien Potencier
  6. * Copyright (c) 2022 Antonio J. GarcĂ­a Lagar
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Ajgarlag\Bundle\PsrHttpMessageBundle\DependencyInjection;
  12. use Sensio\Bundle\FrameworkExtraBundle\DependencyInjection\Configuration as SensioFrameworkExtraConfiguration;
  13. use Sensio\Bundle\FrameworkExtraBundle\Request\ArgumentValueResolver\Psr7ServerRequestResolver;
  14. use Symfony\Component\Config\FileLocator;
  15. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
  18. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  19. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  20. class AjgarlagPsrHttpMessageExtension extends Extension implements CompilerPassInterface, PrependExtensionInterface
  21. {
  22. public function prepend(ContainerBuilder $container)
  23. {
  24. if (!class_exists(Psr7ServerRequestResolver::class)) {
  25. return;
  26. }
  27. if (isset($bundles['SensioFrameworkExtraBundle'])) {
  28. $configs = $container->getExtensionConfig('sensio_framework_extra');
  29. $config = $this->processConfiguration(new SensioFrameworkExtraConfiguration(), $configs);
  30. $sensioPsr7Enabled = isset($config['psr_message']['enabled']) && $config['psr_message']['enabled'];
  31. $container->setParameter('ajgarlag_psr_http_message_sensio_psr7_enabled', $sensioPsr7Enabled);
  32. }
  33. }
  34. public function load(array $configs, ContainerBuilder $container)
  35. {
  36. $configuration = $this->getConfiguration($configs, $container);
  37. $config = $this->processConfiguration($configuration, $configs);
  38. $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  39. if ($this->isSensioFrameworkExtraPsr7SupportEnabled($container)) {
  40. $loader->load('alias_ajgarlag_psr_http_message.php');
  41. return;
  42. }
  43. $loader->load('psr7.php');
  44. if ($config['alias_sensio_framework_extra_services']['enabled']) {
  45. $loader->load('alias_sensio_framework_extra.php');
  46. }
  47. }
  48. private function isSensioFrameworkExtraPsr7SupportEnabled(ContainerBuilder $container): bool
  49. {
  50. if (!$container->hasParameter('ajgarlag_psr_http_message_sensio_psr7_enabled')) {
  51. return false;
  52. }
  53. return (bool) $container->getParameter('ajgarlag_psr_http_message_sensio_psr7_enabled');
  54. }
  55. public function process(ContainerBuilder $container)
  56. {
  57. }
  58. }