You are here

public function CorsCompilerPass::process in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/DependencyInjection/Compiler/CorsCompilerPass.php \Drupal\Core\DependencyInjection\Compiler\CorsCompilerPass::process()

File

core/lib/Drupal/Core/DependencyInjection/Compiler/CorsCompilerPass.php, line 18

Class

CorsCompilerPass
Provides a compiler pass which disables the CORS middleware in case disabled.

Namespace

Drupal\Core\DependencyInjection\Compiler

Code

public function process(ContainerBuilder $container) {
  $enabled = FALSE;
  if ($cors_config = $container
    ->getParameter('cors.config')) {
    $enabled = !empty($cors_config['enabled']);
  }

  // Remove the CORS middleware completely in case it was not enabled.
  if (!$enabled) {
    $container
      ->removeDefinition('http_middleware.cors');
  }
}