Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6, added Doctrine debug collector #15

Merged
merged 4 commits into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion config/zfsnapphpdebugbar.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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 @@ -23,6 +26,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);
}
}