123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
-
-
-
- namespace Doctrine\Bundle\DoctrineBundle\Controller;
-
- use Symfony\Component\DependencyInjection\ContainerAware;
- use Symfony\Component\HttpFoundation\Response;
-
-
- class ProfilerController extends ContainerAware
- {
-
-
- public function explainAction($token, $connectionName, $query)
- {
-
- $profiler = $this->container->get('profiler');
- $profiler->disable();
-
- $profile = $profiler->loadProfile($token);
- $queries = $profile->getCollector('db')->getQueries();
-
- if (!isset($queries[$connectionName][$query])) {
- return new Response('This query does not exist.');
- }
-
- $query = $queries[$connectionName][$query];
- if (!$query['explainable']) {
- return new Response('This query cannot be explained.');
- }
-
-
- $connection = $this->container->get('doctrine')->getConnection($connectionName);
- try {
- $results = $connection->executeQuery('EXPLAIN '.$query['sql'], $query['params'], $query['types'])
- ->fetchAll(\PDO::FETCH_ASSOC);
- } catch (\Exception $e) {
- return new Response('This query cannot be explained.');
- }
-
- return $this->container->get('templating')->renderResponse('DoctrineBundle:Collector:explain.html.twig', array(
- 'data' => $results,
- 'query' => $query,
- ));
- }
- }
|