3 namespace Drupal\devel\Controller;
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\Core\DrupalKernelInterface;
8 use Drupal\devel\DevelDumperManagerInterface;
9 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
10 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
12 use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
13 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
16 * Provides route responses for the container info pages.
18 class ContainerInfoController extends ControllerBase implements ContainerAwareInterface {
20 use ContainerAwareTrait;
25 * @var \Drupal\Core\DrupalKernelInterface
30 * The dumper manager service.
32 * @var \Drupal\devel\DevelDumperManagerInterface
37 * ServiceInfoController constructor.
39 * @param \Drupal\Core\DrupalKernelInterface $drupalKernel
41 * @param \Drupal\devel\DevelDumperManagerInterface $dumper
42 * The dumper manager service.
44 public function __construct(DrupalKernelInterface $drupalKernel, DevelDumperManagerInterface $dumper) {
45 $this->kernel = $drupalKernel;
46 $this->dumper = $dumper;
52 public static function create(ContainerInterface $container) {
54 $container->get('kernel'),
55 $container->get('devel.dumper')
60 * Builds the services overview page.
63 * A render array as expected by the renderer.
65 public function serviceList() {
70 $this->t('Operations'),
75 if ($container = $this->kernel->getCachedContainerDefinition()) {
76 foreach ($container['services'] as $service_id => $definition) {
77 $service = unserialize($definition);
80 'data' => $service_id,
81 'class' => 'table-filter-text-source',
84 'data' => isset($service['class']) ? $service['class'] : '',
85 'class' => 'table-filter-text-source',
88 'data' => array_search($service_id, $container['aliases']) ?: '',
89 'class' => 'table-filter-text-source',
91 $row['operations']['data'] = [
92 '#type' => 'operations',
95 'title' => $this->t('Devel'),
96 'url' => Url::fromRoute('devel.container_info.service.detail', ['service_id' => $service_id]),
101 $rows[$service_id] = $row;
107 $output['#attached']['library'][] = 'system/drupal.system.modules';
109 $output['filters'] = [
110 '#type' => 'container',
112 'class' => ['table-filter', 'js-show'],
115 $output['filters']['text'] = [
117 '#title' => $this->t('Search'),
119 '#placeholder' => $this->t('Enter service id, alias or class'),
121 'class' => ['table-filter-text'],
122 'data-table' => '.devel-filter-text',
123 'autocomplete' => 'off',
124 'title' => $this->t('Enter a part of the service id, service alias or class to filter by.'),
127 $output['services'] = [
129 '#header' => $headers,
131 '#empty' => $this->t('No services found.'),
134 'class' => ['devel-service-list', 'devel-filter-text'],
142 * Returns a render array representation of the service.
144 * @param string $service_id
145 * The ID of the service to retrieve.
148 * A render array containing the service detail.
150 * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
151 * If the requested service is not defined.
153 public function serviceDetail($service_id) {
154 $instance = $this->container->get($service_id, ContainerInterface::NULL_ON_INVALID_REFERENCE);
155 if ($instance === NULL) {
156 throw new NotFoundHttpException();
161 if ($cached_definitions = $this->kernel->getCachedContainerDefinition()) {
162 // Tries to retrieve the service definition from the kernel's cached
163 // container definition.
164 if (isset($cached_definitions['services'][$service_id])) {
165 $definition = unserialize($cached_definitions['services'][$service_id]);
167 // If the service has an alias add it to the definition.
168 if ($alias = array_search($service_id, $cached_definitions['aliases'])) {
169 $definition['alias'] = $alias;
172 $output['definition'] = $this->dumper->exportAsRenderable($definition, $this->t('Computed Definition'));
176 $output['instance'] = $this->dumper->exportAsRenderable($instance, $this->t('Instance'));
182 * Builds the parameters overview page.
185 * A render array as expected by the renderer.
187 public function parameterList() {
190 $this->t('Operations'),
195 if ($container = $this->kernel->getCachedContainerDefinition()) {
196 foreach ($container['parameters'] as $parameter_name => $definition) {
198 'data' => $parameter_name,
199 'class' => 'table-filter-text-source',
201 $row['operations']['data'] = [
202 '#type' => 'operations',
205 'title' => $this->t('Devel'),
206 'url' => Url::fromRoute('devel.container_info.parameter.detail', ['parameter_name' => $parameter_name]),
211 $rows[$parameter_name] = $row;
217 $output['#attached']['library'][] = 'system/drupal.system.modules';
219 $output['filters'] = [
220 '#type' => 'container',
222 'class' => ['table-filter', 'js-show'],
225 $output['filters']['text'] = [
227 '#title' => $this->t('Search'),
229 '#placeholder' => $this->t('Enter parameter name'),
231 'class' => ['table-filter-text'],
232 'data-table' => '.devel-filter-text',
233 'autocomplete' => 'off',
234 'title' => $this->t('Enter a part of the parameter name to filter by.'),
237 $output['parameters'] = [
239 '#header' => $headers,
241 '#empty' => $this->t('No parameters found.'),
244 'class' => ['devel-parameter-list', 'devel-filter-text'],
252 * Returns a render array representation of the parameter value.
254 * @param string $parameter_name
255 * The name of the parameter to retrieve.
258 * A render array containing the parameter value.
260 * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
261 * If the requested parameter is not defined.
263 public function parameterDetail($parameter_name) {
265 $parameter = $this->container->getParameter($parameter_name);
267 catch (ParameterNotFoundException $e) {
268 throw new NotFoundHttpException();
271 return $this->dumper->exportAsRenderable($parameter);