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