Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zend Developer Tools integration based on #51 logs implementation.
- Loading branch information
Showing
6 changed files
with
546 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/DoctrineMongoODMModule/Collector/MongoLoggerCollector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/DoctrineMongoODMModule/Options/MongoLoggerCollector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,100 @@ | |||
<?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\Options; | |||
|
|||
use Zend\Stdlib\AbstractOptions; | |||
|
|||
/** | |||
* Configuration options for a collector | |||
* | |||
* @license MIT | |||
* @link http://www.doctrine-project.org/ | |||
*/ | |||
class MongoLoggerCollector extends AbstractOptions | |||
{ | |||
/** | |||
* @var string name to be assigned to the collector | |||
*/ | |||
protected $name = 'odm_default'; | |||
|
|||
/** | |||
* @var string|null service name of the configuration where the logger has to be put | |||
*/ | |||
protected $configuration; | |||
|
|||
/** | |||
* @var string|null service name of the Logger to be used | |||
*/ | |||
protected $mongoLogger; | |||
|
|||
/** | |||
* @param string $name | |||
*/ | |||
public function setName($name) | |||
{ | |||
$this->name = (string) $name; | |||
} | |||
|
|||
/** | |||
* Name of the collector | |||
* | |||
* @return string | |||
*/ | |||
public function getName() | |||
{ | |||
return $this->name; | |||
} | |||
|
|||
/** | |||
* @param string|null $configuration | |||
*/ | |||
public function setConfiguration($configuration) | |||
{ | |||
$this->configuration = $configuration ? (string) $configuration : null; | |||
} | |||
|
|||
/** | |||
* Configuration service name (where to set the logger) | |||
* | |||
* @return string | |||
*/ | |||
public function getConfiguration() | |||
{ | |||
return $this->configuration ? $this->configuration : 'doctrine.configuration.odm_default'; | |||
} | |||
|
|||
/** | |||
* @param string|null $mongoLogger | |||
*/ | |||
public function setMongoLogger($mongoLogger) | |||
{ | |||
$this->mongoLogger = $mongoLogger ? (string) $mongoLogger : null; | |||
} | |||
|
|||
/** | |||
* Logger service name | |||
* | |||
* @return string|null | |||
*/ | |||
public function getMongoLogger() | |||
{ | |||
return $this->mongoLogger; | |||
} | |||
} |
89 changes: 89 additions & 0 deletions
89
src/DoctrineMongoODMModule/Service/MongoLoggerCollectorFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,89 @@ | |||
<?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\Service; | |||
|
|||
use DoctrineModule\Service\AbstractFactory; | |||
|
|||
use Zend\ServiceManager\ServiceLocatorInterface; | |||
|
|||
use DoctrineMongoODMModule\Collector\MongoLoggerCollector; | |||
|
|||
use DoctrineMongoODMModule\Logging\DebugStack; | |||
use DoctrineMongoODMModule\Logging\LoggerChain; | |||
|
|||
/** | |||
* Mongo Logger Configuration ServiceManager factory | |||
* | |||
* @license MIT | |||
* @link http://www.doctrine-project.org/ | |||
*/ | |||
class MongoLoggerCollectorFactory extends AbstractFactory | |||
{ | |||
/** | |||
* @var string | |||
*/ | |||
protected $name; | |||
|
|||
/** | |||
* @param $name | |||
*/ | |||
public function __construct($name) | |||
{ | |||
$this->name = $name; | |||
} | |||
|
|||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public function createService(ServiceLocatorInterface $serviceLocator) | |||
{ | |||
/** @var $options \DoctrineMongoODMModule\Options\MongoLoggerCollector */ | |||
$options = $this->getOptions($serviceLocator, 'mongo_logger_collector'); | |||
|
|||
if ($options->getMongoLogger()) { | |||
$debugStackLogger = $serviceLocator->get($options->getMongoLogger()); | |||
} else { | |||
$debugStackLogger = new DebugStack(); | |||
} | |||
|
|||
/** @var $options \Doctrine\ODM\MongoDB\Configuration */ | |||
$configuration = $serviceLocator->get($options->getConfiguration()); | |||
|
|||
if (null !== $configuration->getLoggerCallable()) { | |||
$logger = new LoggerChain(); | |||
$logger->addLogger($debugStackLogger); | |||
$callable = $configuration->getLoggerCallable(); | |||
$logger->addLogger($callable[0]); | |||
$configuration->setLoggerCallable(array($logger, 'log')); | |||
} else { | |||
$configuration->setLoggerCallable(array($debugStackLogger, 'log')); | |||
} | |||
|
|||
return new MongoLoggerCollector($debugStackLogger, $options->getName()); | |||
} | |||
|
|||
/** | |||
* {@inheritDoc} | |||
*/ | |||
public function getOptionsClass() | |||
{ | |||
return 'DoctrineMongoODMModule\Options\MongoLoggerCollector'; | |||
} | |||
} |
Oops, something went wrong.