12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- /*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Bundle\DoctrineBundle\DataCollector;
- use Symfony\Component\HttpKernel\DataCollector\DataCollector;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Bundle\DoctrineBundle\Logger\DbalLogger;
- use Symfony\Bridge\Doctrine\RegistryInterface;
- /**
- * DoctrineDataCollector.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
- class DoctrineDataCollector extends DataCollector
- {
- private $connections;
- private $managers;
- private $logger;
- public function __construct(RegistryInterface $registry, DbalLogger $logger = null)
- {
- $this->connections = $registry->getConnectionNames();
- $this->managers = $registry->getEntityManagerNames();
- $this->logger = $logger;
- }
- /**
- * {@inheritdoc}
- */
- public function collect(Request $request, Response $response, \Exception $exception = null)
- {
- $this->data = array(
- 'queries' => null !== $this->logger ? $this->logger->queries : array(),
- 'connections' => $this->connections,
- 'managers' => $this->managers,
- );
- }
- public function getManagers()
- {
- return $this->data['managers'];
- }
- public function getConnections()
- {
- return $this->data['connections'];
- }
- public function getQueryCount()
- {
- return count($this->data['queries']);
- }
- public function getQueries()
- {
- return $this->data['queries'];
- }
- public function getTime()
- {
- $time = 0;
- foreach ($this->data['queries'] as $query) {
- $time += $query['executionMS'];
- }
- return $time;
- }
- /**
- * {@inheritdoc}
- */
- public function getName()
- {
- return 'db';
- }
- }
|