Skip to content

Commit

Permalink
Fix ProfilerController compatibility with Symfony 6
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Dec 13, 2021
1 parent fdcb567 commit 913c7bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
36 changes: 19 additions & 17 deletions Controller/ProfilerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Doctrine\Bundle\DoctrineBundle\Controller;

use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ForwardCompatibility\Result;
use Doctrine\DBAL\Platforms\OraclePlatform;
Expand All @@ -11,27 +12,30 @@
use PDO;
use PDOStatement;
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\VarDumper\Cloner\Data;
use Throwable;
use Twig\Environment;

use function assert;
use function stripos;

class ProfilerController implements ContainerAwareInterface
/** @internal */
class ProfilerController
{
/** @var ContainerInterface */
private $container;

/**
* {@inheritDoc}
*/
public function setContainer(?ContainerInterface $container = null)
/** @var Environment */
private $twig;
/** @var Registry */
private $registry;
/** @var Profiler */
private $profiler;

public function __construct(Environment $twig, Registry $registry, Profiler $profiler)
{
$this->container = $container;
$this->twig = $twig;
$this->registry = $registry;
$this->profiler = $profiler;
}

/**
Expand All @@ -45,11 +49,9 @@ public function setContainer(?ContainerInterface $container = null)
*/
public function explainAction($token, $connectionName, $query)
{
$profiler = $this->container->get('profiler');
assert($profiler instanceof Profiler);
$profiler->disable();
$this->profiler->disable();

$profile = $profiler->loadProfile($token);
$profile = $this->profiler->loadProfile($token);
$collector = $profile->getCollector('db');

assert($collector instanceof DoctrineDataCollector);
Expand All @@ -65,7 +67,7 @@ public function explainAction($token, $connectionName, $query)
return new Response('This query cannot be explained.');
}

$connection = $this->container->get('doctrine')->getConnection($connectionName);
$connection = $this->registry->getConnection($connectionName);
assert($connection instanceof Connection);
try {
$platform = $connection->getDatabasePlatform();
Expand All @@ -82,7 +84,7 @@ public function explainAction($token, $connectionName, $query)
return new Response('This query cannot be explained.');
}

return new Response($this->container->get('twig')->render('@Doctrine/Collector/explain.html.twig', [
return new Response($this->twig->render('@Doctrine/Collector/explain.html.twig', [
'data' => $results,
'query' => $query,
]));
Expand Down
8 changes: 8 additions & 0 deletions Resources/config/orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,13 @@

<tag name="console.command" command="doctrine:mapping:import" />
</service>

<service id="Doctrine\Bundle\DoctrineBundle\Controller\ProfilerController">
<argument type="service" id="twig" on-invalid="ignore"/>
<argument type="service" id="doctrine" />
<argument type="service" id="profiler" on-invalid="ignore" />

<tag name="controller.service_arguments" />
</service>
</services>
</container>

0 comments on commit 913c7bf

Please sign in to comment.