function CoreServiceProvider::alter

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/CoreServiceProvider.php \Drupal\Core\CoreServiceProvider::alter()
  2. 10 core/lib/Drupal/Core/CoreServiceProvider.php \Drupal\Core\CoreServiceProvider::alter()
  3. 9 core/lib/Drupal/Core/CoreServiceProvider.php \Drupal\Core\CoreServiceProvider::alter()

Alters the UUID service to use the most efficient method available.

Parameters

\Drupal\Core\DependencyInjection\ContainerBuilder $container: The container builder.

File

core/lib/Drupal/Core/CoreServiceProvider.php, line 113

Class

CoreServiceProvider
ServiceProvider class for mandatory core services.

Namespace

Drupal\Core

Code

public function alter(ContainerBuilder $container) {
  $uuid_service = $container->getDefinition('uuid');
  // Debian/Ubuntu uses the (broken) OSSP extension as their UUID
  // implementation. The OSSP implementation is not compatible with the
  // PECL functions.
  if (function_exists('uuid_create') && !function_exists('uuid_make')) {
    $uuid_service->setClass('Drupal\\Component\\Uuid\\Pecl');
  }
  elseif (function_exists('com_create_guid')) {
    $uuid_service->setClass('Drupal\\Component\\Uuid\\Com');
  }
  // Look for missing services that are now defined by the path_alias module,
  // add them as a fallback until the module is installed.
  // @todo Remove this in Drupal 9 in https://www.drupal.org/node/3092090.
  $services = [
    'path_alias.subscriber' => PathSubscriber::class,
    'path_alias.path_processor' => PathProcessorAlias::class,
    'path_alias.manager' => AliasManager::class,
    'path_alias.whitelist' => AliasWhitelist::class,
    'path_alias.repository' => AliasRepository::class,
  ];
  foreach ($services as $id => $class) {
    if (!$container->hasDefinition($id)) {
      $definition = $container->register($id, $class);
      // Mark the fallback services as deprecated in order to allow other
      // modules to provide additional checks before relying or altering them.
      $definition->setDeprecated(TRUE, 'The "%service_id%" service is in fallback mode. See https://drupal.org/node/3092086');
      switch ($id) {
        case 'path_alias.subscriber':
          $definition->addArgument(new Reference('path.alias_manager'));
          $definition->addArgument(new Reference('path.current'));
          break;

        case 'path_alias.path_processor':
          $definition->addArgument(new Reference('path.alias_manager'));
          break;

        case 'path_alias.repository':
          $definition->addArgument(new Reference('database'));
          break;

        case 'path_alias.whitelist':
          $definition->addArgument('path_alias_whitelist');
          $definition->addArgument(new Reference('cache.bootstrap'));
          $definition->addArgument(new Reference('lock'));
          $definition->addArgument(new Reference('state'));
          $definition->addArgument(new Reference('path_alias.repository'));
          break;

        case 'path_alias.manager':
          $definition->addArgument(new Reference('path_alias.repository'));
          $definition->addArgument(new Reference('path_alias.whitelist'));
          $definition->addArgument(new Reference('language_manager'));
          $definition->addArgument(new Reference('cache.data'));
          break;

      }
    }
  }
}

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