You are here

class ServicePass in Devel 8.2

Same name and namespace in other branches
  1. 8.3 webprofiler/src/Compiler/ServicePass.php \Drupal\webprofiler\Compiler\ServicePass
  2. 8 webprofiler/src/Compiler/ServicePass.php \Drupal\webprofiler\Compiler\ServicePass
  3. 4.x webprofiler/src/Compiler/ServicePass.php \Drupal\webprofiler\Compiler\ServicePass

Class ServicePass

Hierarchy

  • class \Drupal\webprofiler\Compiler\ServicePass implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface

Expanded class hierarchy of ServicePass

1 file declares its use of ServicePass
WebprofilerServiceProvider.php in webprofiler/src/WebprofilerServiceProvider.php

File

webprofiler/src/Compiler/ServicePass.php, line 13

Namespace

Drupal\webprofiler\Compiler
View source
class ServicePass implements CompilerPassInterface {

  /**
   * {@inheritdoc}
   */
  public function process(ContainerBuilder $container) {
    if (FALSE === $container
      ->hasDefinition('webprofiler.services')) {
      return;
    }
    $definition = $container
      ->getDefinition('webprofiler.services');
    $graph = $container
      ->getCompiler()
      ->getServiceReferenceGraph();
    $definition
      ->addMethodCall('setServices', [
      $this
        ->extractData($container, $graph),
    ]);
  }

  /**
   * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
   * @param \Symfony\Component\DependencyInjection\Compiler\ServiceReferenceGraph $graph
   *
   * @return array
   */
  private function extractData(ContainerBuilder $container, ServiceReferenceGraph $graph) {
    $data = [];
    foreach ($container
      ->getDefinitions() as $id => $definition) {
      $inEdges = [];
      $outEdges = [];
      if ($graph
        ->hasNode($id)) {
        $node = $graph
          ->getNode($id);

        /** @var \Symfony\Component\DependencyInjection\Compiler\ServiceReferenceGraphEdge $edge */
        foreach ($node
          ->getInEdges() as $edge) {

          /** @var \Symfony\Component\DependencyInjection\Reference $edgeValue */
          $edgeValue = $edge
            ->getValue();
          $inEdges[] = [
            'id' => $edge
              ->getSourceNode()
              ->getId(),
            'invalidBehavior' => $edgeValue ? $edgeValue
              ->getInvalidBehavior() : NULL,
          ];
        }

        /** @var \Symfony\Component\DependencyInjection\Compiler\ServiceReferenceGraphEdge $edge */
        foreach ($node
          ->getOutEdges() as $edge) {

          /** @var \Symfony\Component\DependencyInjection\Reference $edgeValue */
          $edgeValue = $edge
            ->getValue();
          $outEdges[] = [
            'id' => $edge
              ->getDestNode()
              ->getId(),
            'invalidBehavior' => $edgeValue ? $edgeValue
              ->getInvalidBehavior() : NULL,
          ];
        }
      }
      if ($definition instanceof Definition) {
        $class = $definition
          ->getClass();
        try {
          $reflectedClass = new \ReflectionClass($class);
          $file = $reflectedClass
            ->getFileName();
        } catch (\ReflectionException $e) {
          $file = NULL;
        }
        $tags = $definition
          ->getTags();
        $public = $definition
          ->isPublic();
        $synthetic = $definition
          ->isSynthetic();
      }
      else {
        $id = $definition
          ->__toString();
        $class = NULL;
        $file = NULL;
        $tags = [];
        $public = NULL;
        $synthetic = NULL;
      }
      $data[$id] = [
        'inEdges' => $inEdges,
        'outEdges' => $outEdges,
        'value' => [
          'class' => $class,
          'file' => $file,
          'id' => $id,
          'tags' => $tags,
          'public' => $public,
          'synthetic' => $synthetic,
        ],
      ];
    }
    return $data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ServicePass::extractData private function
ServicePass::process public function You can modify the container here before it is dumped to PHP code.