ModifyServiceDefinitionsPass.php 1017 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
<?php

/**
 * @file
 * Contains Drupal\Core\DependencyInjection\Compiler\ModifyServiceDefinitionsPass.
 */

namespace Drupal\Core\DependencyInjection\Compiler;

use Drupal\Core\DrupalKernelInterface;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
 * Passes the container to the alter() method of all service providers.
 */
class ModifyServiceDefinitionsPass implements CompilerPassInterface {

  /**
   * {@inheritdoc}
   */
  public function process(ContainerBuilder $container) {
    if (!$container->has('kernel')) {
      return;
    }
    $kernel = $container->get('kernel');
    if (!($kernel instanceof DrupalKernelInterface)) {
      return;
    }
    $providers = $kernel->getServiceProviders();
    foreach ($providers as $provider) {
      if ($provider instanceof ServiceModifierInterface) {
        $provider->alter($container);
      }
    }
  }

}