You are here

public function ContainerInfoController::serviceDetail in Devel 8.3

Same name and namespace in other branches
  1. 8 src/Controller/ContainerInfoController.php \Drupal\devel\Controller\ContainerInfoController::serviceDetail()
  2. 8.2 src/Controller/ContainerInfoController.php \Drupal\devel\Controller\ContainerInfoController::serviceDetail()
  3. 4.x src/Controller/ContainerInfoController.php \Drupal\devel\Controller\ContainerInfoController::serviceDetail()

Returns a render array representation of the service.

Parameters

string $service_id: The ID of the service to retrieve.

Return value

array A render array containing the service detail.

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException If the requested service is not defined.

1 string reference to 'ContainerInfoController::serviceDetail'
devel.routing.yml in ./devel.routing.yml
devel.routing.yml

File

src/Controller/ContainerInfoController.php, line 145

Class

ContainerInfoController
Provides route responses for the container info pages.

Namespace

Drupal\devel\Controller

Code

public function serviceDetail($service_id) {
  $instance = $this->container
    ->get($service_id, ContainerInterface::NULL_ON_INVALID_REFERENCE);
  if ($instance === NULL) {
    throw new NotFoundHttpException();
  }
  $output = [];
  if ($cached_definitions = $this->kernel
    ->getCachedContainerDefinition()) {

    // Tries to retrieve the service definition from the kernel's cached
    // container definition.
    if (isset($cached_definitions['services'][$service_id])) {
      $definition = unserialize($cached_definitions['services'][$service_id]);

      // If the service has an alias add it to the definition.
      if ($alias = array_search($service_id, $cached_definitions['aliases'])) {
        $definition['alias'] = $alias;
      }
      $output['definition'] = $this->dumper
        ->exportAsRenderable($definition, $this
        ->t('Computed Definition'));
    }
  }
  $output['instance'] = $this->dumper
    ->exportAsRenderable($instance, $this
    ->t('Instance'));
  return $output;
}