Skip to content

Commit

Permalink
added integration Doctrine Queries #6 (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
bupy7 authored and snapshotpl committed Oct 27, 2016
1 parent 771cb2d commit 1bf6423
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
12 changes: 11 additions & 1 deletion config/zfsnapphpdebugbar.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
'zend-db-adapter-service-name' => Zend\Db\Adapter\Adapter::class,
// ServiceManager service keys to inject collectors
// http://phpdebugbar.com/docs/data-collectors.html
'collectors' => [],
'collectors' => [
// uncomment if you use Doctrine ORM
//DebugBar\Bridge\DoctrineCollector::class,
],
// ServiceManager service key to inject storage
// http://phpdebugbar.com/docs/storage.html
'storage' => null,
Expand All @@ -25,6 +28,13 @@
'factories' => [
'debugbar' => ZfSnapPhpDebugBar\Service\PhpDebugBarFactory::class,
ZfSnapPhpDebugBar\Log\Writer\PhpDebugBar::class => ZfSnapPhpDebugBar\Log\Writer\PhpDebugBarFactory::class,
DebugBar\Bridge\DoctrineCollector::class => ZfSnapPhpDebugBar\Collector\DoctrineCollectorFactory::class,
],
'delegators' => [
// uncomment if you use Doctrine ORM
//'doctrine.configuration.orm_default' => [
// ZfSnapPhpDebugBar\Delegator\DoctrineConfigurationDelegatorFactory::class,
//],
],
],
'controllers' => [
Expand Down
22 changes: 22 additions & 0 deletions src/Collector/DoctrineCollectorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace ZfSnapPhpDebugBar\Collector;

use Interop\Container\ContainerInterface;
use DebugBar\Bridge\DoctrineCollector;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class DoctrineCollectorFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$debugStack = $container->get('doctrine.configuration.orm_default')->getSQLLogger();
return new DoctrineCollector($debugStack);
}

public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this($serviceLocator, DoctrineCollector::class);
}
}
23 changes: 23 additions & 0 deletions src/Delegator/DoctrineConfigurationDelegatorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace ZfSnapPhpDebugBar\Delegator;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\DelegatorFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Doctrine\DBAL\Logging\DebugStack;

class DoctrineConfigurationDelegatorFactory implements DelegatorFactoryInterface
{
public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
{
$doctrineConfiguration = $callback();
$doctrineConfiguration->setSQLLogger(new DebugStack);
return $doctrineConfiguration;
}

public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback)
{
return $this($serviceLocator, $requestedName, $callback);
}
}

0 comments on commit 1bf6423

Please sign in to comment.