get('profiler'), $container->get('database') ); } /** * Constructs a new WebprofilerController. * * @param \Symfony\Component\HttpKernel\Profiler\Profiler $profiler * @param \Drupal\Core\Database\Connection $database */ public function __construct(Profiler $profiler, Connection $database) { $this->profiler = $profiler; $this->database = $database; } /** * @param Profile $profile * @param int $qid * * @return JsonResponse */ public function explainAction(Profile $profile, $qid) { $query = $this->getQuery($profile, $qid); $data = []; $result = $this->database->query('EXPLAIN ' . $query['query'], (array) $query['args']) ->fetchAllAssoc('table'); $i = 1; foreach ($result as $row) { foreach ($row as $key => $value) { $data[$i][$key] = $value; } $i++; } return new JsonResponse(['data' => $data]); } /** * @param $profile ->getToken() * @param int $qid * * @return array */ private function getQuery(Profile $profile, $qid) { $this->profiler->disable(); $token = $profile->getToken(); if (!$profile = $this->profiler->loadProfile($token)) { throw new NotFoundHttpException($this->t('Token @token does not exist.', ['@token' => $token])); } /** @var DatabaseDataCollector $databaseCollector */ $databaseCollector = $profile->getCollector('database'); $queries = $databaseCollector->getQueries(); $query = $queries[$qid]; return $query; } }