You are here

class CorsCompilerPass in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/DependencyInjection/Compiler/CorsCompilerPass.php \Drupal\Core\DependencyInjection\Compiler\CorsCompilerPass
  2. 10 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

Namesort descending Modifiers Type Description Overrides
CorsCompilerPass::process public function You can modify the container here before it is dumped to PHP code.