Permalink
Browse files

Merge pull request #52 from jhuet/49-zend-developer-tools-integration

Zend developer tools integration
  • Loading branch information...
2 parents 5368715 + d26f9a2 commit f7e9379736f06cd045decd5cbc953e983f2ef560 @Ocramius Ocramius committed Dec 15, 2012
View
@@ -54,6 +54,10 @@
)
),
+ 'mongo_logger_collector' => array(
+ 'odm_default' => array(),
+ ),
+
'authentication' => array(
'odm_default' => array(
'objectManager' => 'doctrine.documentmanager.odm_default',
@@ -63,4 +67,25 @@
),
),
),
+
+ // zendframework/zend-developer-tools specific settings
+
+ 'view_manager' => array(
+ 'template_map' => array(
+ 'zend-developer-tools/toolbar/doctrine-odm' => __DIR__ . '/../view/zend-developer-tools/toolbar/doctrine-odm.phtml',
+ ),
+ ),
+
+ 'zenddevelopertools' => array(
+ 'profiler' => array(
+ 'collectors' => array(
+ 'odm_default' => 'doctrine.mongo_logger_collector.odm_default',
+ ),
+ ),
+ 'toolbar' => array(
+ 'entries' => array(
+ 'odm_default' => 'zend-developer-tools/toolbar/doctrine-odm',
+ ),
+ ),
+ ),
);
@@ -0,0 +1,117 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+namespace DoctrineMongoODMModule\Collector;
+
+
+use ZendDeveloperTools\Collector\CollectorInterface;
+use ZendDeveloperTools\Collector\AutoHideInterface;
+
+use Zend\Mvc\MvcEvent;
+
+use DoctrineMongoODMModule\Logging\DebugStack;
+
+/**
+ * Collector to be used in ZendDeveloperTools to record and display Mongo
+ * queries
+ *
+ * @license MIT
+ * @link www.doctrine-project.org
+ */
+class MongoLoggerCollector implements CollectorInterface, AutoHideInterface
+{
+ /**
+ * Collector priority
+ */
+ const PRIORITY = 10;
+
+ /**
+ * @var DebugStack
+ */
+ protected $mongoLogger;
+
+ /**
+ * @var string
+ */
+ protected $name;
+
+ /**
+ * @param DebugStack $mongoLogger
+ * @param string $name
+ */
+ public function __construct(DebugStack $mongoLogger, $name)
+ {
+ $this->mongoLogger = $mongoLogger;
+ $this->name = (string) $name;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getPriority()
+ {
+ return static::PRIORITY;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function collect(MvcEvent $mvcEvent)
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function canHide()
+ {
+ return empty($this->mongoLogger->queries);
+ }
+
+ /**
+ * @return int
+ */
+ public function getQueryCount()
+ {
+ return count($this->mongoLogger->queries);
+ }
+
+ /**
+ * @return array
+ */
+ public function getQueries()
+ {
+ return $this->mongoLogger->queries;
+ }
+
+ /**
+ * @return float
+ */
+ public function getQueryTime()
+ {
+ return 0.0;
+ }
+}
@@ -0,0 +1,38 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+namespace DoctrineMongoODMModule\Logging;
+
+/**
+ * A logger that logs to the standard output using echo/var_dump.
+ *
+ * @license MIT
+ * @link www.doctrine-project.org
+ */
+class EchoLogger implements Logger
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function log(array $logs)
+ {
+ if ($logs) {
+ var_dump($logs);
+ }
+ }
+}
@@ -0,0 +1,51 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+namespace DoctrineMongoODMModule\Logging;
+
+/**
+ * Chains multiple Logger
+ *
+ * @license MIT
+ * @link www.doctrine-project.org
+ */
+class LoggerChain implements Logger
+{
+ private $loggers = array();
+
+ /**
+ * Adds a logger in the chain
+ *
+ * @param Logger $logger
+ */
+ public function addLogger(Logger $logger)
+ {
+ $this->loggers[] = $logger;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function log(array $logs)
+ {
+ foreach ($this->loggers as $logger) {
+ $logger->log($logs);
+ }
+ }
+}
+
@@ -21,11 +21,14 @@
use DoctrineModule\Service as CommonService;
use DoctrineMongoODMModule\Service as ODMService;
+
use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
+use Zend\ModuleManager\Feature\InitProviderInterface;
+use Zend\ModuleManager\ModuleManagerInterface;
use Zend\Loader\AutoloaderFactory;
use Zend\Loader\StandardAutoloader;
@@ -37,8 +40,24 @@
* @since 0.1.0
* @author Tim Roediger <superdweebie@gmail.com>
*/
-class Module implements BootstrapListenerInterface, AutoloaderProviderInterface, ConfigProviderInterface, ServiceProviderInterface
+class Module implements
+ BootstrapListenerInterface,
+ AutoloaderProviderInterface,
+ ConfigProviderInterface,
+ ServiceProviderInterface,
+ InitProviderInterface
{
+ /**
+ * {@inheritDoc}
+ */
+ public function init(ModuleManagerInterface $manager)
+ {
+ $events = $manager->getEventManager();
+ // Initialize logger collector once the profiler is initialized itself
+ $events->attach('profiler_init', function(EventInterface $e) use ($manager) {
+ $manager->getEvent()->getParam('ServiceManager')->get('doctrine.mongo_logger_collector.odm_default');
+ });
+ }
/**
* {@inheritDoc}
@@ -103,7 +122,9 @@ public function getServiceConfig()
{
return array(
'invokables' => array(
- 'DoctrineMongoODMModule\Logging\DebugStack' => 'DoctrineMongoODMModule\Logging\DebugStack',
+ 'DoctrineMongoODMModule\Logging\DebugStack' => 'DoctrineMongoODMModule\Logging\DebugStack',
+ 'DoctrineMongoODMModule\Logging\LoggerChain' => 'DoctrineMongoODMModule\Logging\LoggerChain',
+ 'DoctrineMongoODMModule\Logging\EchoLogger' => 'DoctrineMongoODMModule\Logging\EchoLogger',
),
'aliases' => array(
'Doctrine\ODM\Mongo\DocumentManager' => 'doctrine.documentmanager.odm_default',
@@ -117,6 +138,7 @@ public function getServiceConfig()
'doctrine.driver.odm_default' => new CommonService\DriverFactory('odm_default'),
'doctrine.documentmanager.odm_default' => new ODMService\DocumentManagerFactory('odm_default'),
'doctrine.eventmanager.odm_default' => new CommonService\EventManagerFactory('odm_default'),
+ 'doctrine.mongo_logger_collector.odm_default' => new ODMService\MongoLoggerCollectorFactory('odm_default'),
)
);
}
Oops, something went wrong.

0 comments on commit f7e9379

Please sign in to comment.