CorsCompilerPass.php 773 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Drupal\Core\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  4. use Symfony\Component\DependencyInjection\ContainerBuilder;
  5. /**
  6. * Provides a compiler pass which disables the CORS middleware in case disabled.
  7. *
  8. * @see core.services.yml
  9. */
  10. class CorsCompilerPass implements CompilerPassInterface {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function process(ContainerBuilder $container) {
  15. $enabled = FALSE;
  16. if ($cors_config = $container->getParameter('cors.config')) {
  17. $enabled = !empty($cors_config['enabled']);
  18. }
  19. // Remove the CORS middleware completely in case it was not enabled.
  20. if (!$enabled) {
  21. $container->removeDefinition('http_middleware.cors');
  22. }
  23. }
  24. }