You are here

public function ServiceProviderTestServiceProvider::alter in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/service_provider_test/src/ServiceProviderTestServiceProvider.php \Drupal\service_provider_test\ServiceProviderTestServiceProvider::alter()
  2. 9 core/modules/system/tests/modules/service_provider_test/src/ServiceProviderTestServiceProvider.php \Drupal\service_provider_test\ServiceProviderTestServiceProvider::alter()

Modifies existing service definitions.

Parameters

ContainerBuilder $container: The ContainerBuilder whose service definitions can be altered.

Overrides ServiceModifierInterface::alter

File

core/modules/system/tests/modules/service_provider_test/src/ServiceProviderTestServiceProvider.php, line 14

Class

ServiceProviderTestServiceProvider

Namespace

Drupal\service_provider_test

Code

public function alter(ContainerBuilder $container) {
  if ($container
    ->has('file.usage')) {

    // Override the class used for the file.usage service.
    $definition = $container
      ->getDefinition('file.usage');
    $definition
      ->setClass('Drupal\\service_provider_test\\TestFileUsage');
  }
  if ($indicator = Settings::get('deployment_identifier')) {
    $container
      ->setParameter('container_rebuild_indicator', $indicator);
  }
  if ($parameter = Settings::get('container_rebuild_test_parameter')) {
    $container
      ->setParameter('container_rebuild_test_parameter', $parameter);
  }
}