snapshotpl / ZfSnapPhpDebugBar

PHP Debug Bar module for Zend Framework 2 & 3
29 stars 11 forks source link

How integrate Doctrine Queries? #6

Closed a-h-abid closed 7 years ago

a-h-abid commented 9 years ago

Nice thing, just not seeing Db Queries. Can you help how to see Queries through Doctrine? Using doctrine/doctrine-orm-module

snapshotpl commented 9 years ago

Try http://phpdebugbar.com/docs/bridge-collectors.html#doctrine However I will try to simplify this integration.

bupy7 commented 8 years ago

@abdmaster,

Create collector:

use Interop\Container\ContainerInterface;
use DebugBar\Bridge\DoctrineCollector;
use Doctrine\DBAL\Logging\DebugStack;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
 * Factory of `DoctrineCollector`.
 * @see DoctrineCollector
 */
class DoctrineCollectorFactory implements FactoryInterface
{
    /**
     * {@inheritdoc}
     */
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $debugStack = new DebugStack;
        $entityManager = $container->get('Doctrine\ORM\EntityManager');
        $entityManager->getConnection()->getConfiguration()->setSQLLogger($debugStack);
        $collector = new DoctrineCollector($debugStack);
        return $collector;
    }

    /**
     * {@inheritdoc}
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        return $this($serviceLocator, DoctrineCollector::class);
    }
}

Update config:

use DebugBar\Bridge\DoctrineCollector;
use <NAMESPACE>\<TO>\DoctrineCollectorFactory;

return [
    'php-debug-bar' => [
        'collectors' => [
            DoctrineCollector::class,
        ],
    ],
    'service_manager' => [
        'factories' => [
            DoctrineCollector::class => DoctrineCollectorFactory::class,
        ],
    ],
];
snapshotpl commented 8 years ago

@bupy7 great! Can you prepare merge request with this into module?

bupy7 commented 8 years ago

@snapshotpl Yes, I can. )

snapshotpl commented 8 years ago

Awesome. Can you start from https://github.com/snapshotpl/ZfSnapPhpDebugBar/pull/13 ?

bupy7 commented 8 years ago

@snapshotpl Ok.

a-h-abid commented 8 years ago

Thanks @bupy7 thats awesome. :)

snapshotpl commented 7 years ago

@a-h-abid merged and released

a-h-abid commented 7 years ago

Awesome :)