You are here

public function RestrictByIpServiceProvider::alter in Restrict Login or Role Access by IP Address 8.4

Modifies existing service definitions.

Parameters

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

Overrides ServiceProviderBase::alter

File

src/RestrictByIpServiceProvider.php, line 24
Contains Drupal\restrict_by_ip\RestrictByIpServiceProvider

Class

RestrictByIpServiceProvider
Rename current_user service and replace with one provided by restrict_by_ip module.

Namespace

Drupal\restrict_by_ip

Code

public function alter(ContainerBuilder $container) {

  // Rename current_user service.
  $coreService = $container
    ->getDefinition('current_user');
  $container
    ->setDefinition('restrict_by_ip.current_user', $coreService);

  // Register this modules class as default for current_user service.
  $newService = new Definition('Drupal\\restrict_by_ip\\Session\\AccountProxy');
  $newService
    ->addArgument(new Reference('restrict_by_ip.current_user'));
  $newService
    ->addArgument(new Reference('restrict_by_ip.role_firewall'));
  $container
    ->setDefinition('current_user', $newService);
}