propel-bundle/DataCollector/PropelDataCollector.php
Drew Brown ea6a359272 Symfony 4.0 updates (#483)
* Upd: Add Symfony 4 Compatibility

#SymfonyConHackday2017

* Upd: Configure visibility of services for SF4

* Updated composer to allow Symfony 4.0

* Updated composer to allow Symfony 4.0

* PropelBundle for Symfony 4

* Upd: Travis configuration

* Upd: PHP 5 not supported anymore by PHPUnit

* Upd: Removing old SF version + PHPUnit correction

* * Removed param that was removed in symfony/yaml afb873f
* Updated format of object dumping as deprecated tags using colon symfony/yaml 38d3087

* * Added commands to console.xml as symfony no longer auto registers bundle commands
* Updated two services to public

* * Removed deprecated getMock calls for new createMock calls.

* * Add stub for additional abstract method

* * Updated schema locator test
* reverted unnecessary changes to abstract command and schemal locator
* Added fixtures for schema testing.

* * Updated schema locator test
* reverted unnecessary changes to abstract command and schemal locator
* Added fixtures for schema testing.

* * Removed unnecessary default for services
* Updated readme to reflect symfony version support
2018-02-10 01:25:14 +01:00

116 lines
2.4 KiB
PHP

<?php
/**
* This file is part of the PropelBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Propel\Bundle\PropelBundle\DataCollector;
use Propel\Bundle\PropelBundle\Logger\PropelLogger;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
/**
* The PropelDataCollector collector class collects information.
*
* @author Kévin Gomez <contact@kevingomez.fr>
*/
class PropelDataCollector extends DataCollector
{
protected $logger;
public function __construct(PropelLogger $logger)
{
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data = array(
'queries' => $this->cloneVar($this->buildQueries()),
'querycount' => $this->countQueries(),
);
}
/**
* Returns the collector name.
*
* @return string The collector name.
*/
public function getName()
{
return 'propel';
}
/**
* Returns queries.
*
* @return array Queries
*/
public function getQueries()
{
return $this->data['queries'];
}
/**
* Returns the query count.
*
* @return int The query count
*/
public function getQueryCount()
{
return $this->data['querycount'];
}
/**
* Returns the total time of queries.
*
* @return float The total time of queries
*/
public function getTime()
{
$time = 0;
foreach ($this->data['queries'] as $query) {
$time += (float) $query['time'];
}
return $time;
}
/**
* Creates an array of Build objects.
*
* @return array An array of Build objects
*/
private function buildQueries()
{
return $this->logger->getQueries();
}
/**
* Count queries.
*
* @return int The number of queries.
*/
private function countQueries()
{
return count($this->logger->getQueries());
}
/**
* @inheritdoc
*/
public function reset()
{
// TODO: Implement reset() method.
}
}