You are here

class CorsCompilerPass in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/DependencyInjection/Compiler/CorsCompilerPass.php \Drupal\Core\DependencyInjection\Compiler\CorsCompilerPass
  2. 9 core/lib/Drupal/Core/DependencyInjection/Compiler/CorsCompilerPass.php \Drupal\Core\DependencyInjection\Compiler\CorsCompilerPass

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

Hierarchy

  • class \Drupal\Core\DependencyInjection\Compiler\CorsCompilerPass implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface

Expanded class hierarchy of CorsCompilerPass

See also

core.services.yml

1 file declares its use of CorsCompilerPass
CoreServiceProvider.php in core/lib/Drupal/Core/CoreServiceProvider.php

File

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

Namespace

Drupal\Core\DependencyInjection\Compiler
View source
class CorsCompilerPass implements CompilerPassInterface {

  /**
   * {@inheritdoc}
   */
  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');
    }
  }

}

Members