CorsCompilerPass.php

Same filename in other branches
  1. 8.9.x core/lib/Drupal/Core/DependencyInjection/Compiler/CorsCompilerPass.php
  2. 10 core/lib/Drupal/Core/DependencyInjection/Compiler/CorsCompilerPass.php
  3. 11.x core/lib/Drupal/Core/DependencyInjection/Compiler/CorsCompilerPass.php

Namespace

Drupal\Core\DependencyInjection\Compiler

File

core/lib/Drupal/Core/DependencyInjection/Compiler/CorsCompilerPass.php

View source
<?php

namespace Drupal\Core\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
 * Provides a compiler pass which disables the CORS middleware in case disabled.
 *
 * @see core.services.yml
 */
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');
        }
    }

}

Classes

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.