function WebprofilerServiceProvider::alter

File

webprofiler/src/WebprofilerServiceProvider.php, line 77

Class

WebprofilerServiceProvider
Defines a service profiler for the webprofiler module.

Namespace

Drupal\webprofiler

Code

public function alter(ContainerBuilder $container) {
    $modules = $container->getParameter('container.modules');
    // Alter the views.executable service only if Views module is enabled.
    if (isset($modules['views'])) {
        $container->getDefinition('views.executable')
            ->setClass('Drupal\\webprofiler\\Views\\ViewExecutableFactoryWrapper');
    }
    // Replace the regular form_builder service with a traceable one.
    $container->getDefinition('form_builder')
        ->setClass('Drupal\\webprofiler\\Form\\FormBuilderWrapper');
    // Replace the regular access_manager service with a traceable one.
    $container->getDefinition('access_manager')
        ->setClass('Drupal\\webprofiler\\Access\\AccessManagerWrapper')
        ->addMethodCall('setDataCollector', [
        new Reference('webprofiler.request'),
    ]);
    // Replace the regular theme.negotiator service with a traceable one.
    $container->getDefinition('theme.negotiator')
        ->setClass('Drupal\\webprofiler\\Theme\\ThemeNegotiatorWrapper');
    // Replace the regular config.factory service with a traceable one.
    $container->getDefinition('config.factory')
        ->setClass('Drupal\\webprofiler\\Config\\ConfigFactoryWrapper')
        ->addMethodCall('setDataCollector', [
        new Reference('webprofiler.config'),
    ]);
    // Replace the regular string_translation service with a traceable one.
    $container->getDefinition('string_translation')
        ->setClass('Drupal\\webprofiler\\StringTranslation\\TranslationManagerWrapper');
    // Replace the regular event_dispatcher service with a traceable one.
    $container->getDefinition('event_dispatcher')
        ->setClass('Drupal\\webprofiler\\EventDispatcher\\TraceableEventDispatcher')
        ->addMethodCall('setStopwatch', [
        new Reference('stopwatch'),
    ]);
    $container->getDefinition('http_kernel.basic')
        ->replaceArgument(1, new Reference('webprofiler.debug.controller_resolver'));
}