[ProfilerBundle] refactored some code

This commit is contained in:
Fabien Potencier 2010-03-01 19:10:47 +01:00
parent 74ff6cbd9f
commit 9738f34c4d
5 changed files with 29 additions and 12 deletions

View File

@ -58,6 +58,16 @@ class UniversalClassLoader
protected $namespaces = array();
protected $prefixes = array();
public function getNamespaces()
{
return $this->namespaces;
}
public function getPrefixes()
{
return $this->prefixes;
}
/**
* Registers an array of namespaces
*

View File

@ -26,7 +26,7 @@ class ConfigDataCollector extends DataCollector
$kernel = $this->container->getKernelService();
return array(
'token' => $this->manager->getRequestDebugData()->getToken(),
'token' => $this->manager->getProfilerStorage()->getToken(),
'symfony_version' => Kernel::VERSION,
'name' => $kernel->getName(),
'env' => $kernel->getEnvironment(),

View File

@ -5,7 +5,7 @@ namespace Symfony\Framework\ProfilerBundle\DataCollector;
use Symfony\Components\DependencyInjection\ContainerInterface;
use Symfony\Components\EventDispatcher\Event;
use Symfony\Components\RequestHandler\Response;
use Symfony\Framework\ProfilerBundle\RequestDebugData;
use Symfony\Framework\ProfilerBundle\ProfilerStorage;
/*
* This file is part of the symfony framework.
@ -25,16 +25,16 @@ use Symfony\Framework\ProfilerBundle\RequestDebugData;
class DataCollectorManager
{
protected $container;
protected $requestDebugData;
protected $profilerStorage;
protected $collectors;
protected $response;
protected $lifetime;
public function __construct(ContainerInterface $container, $lifetime = 86400)
public function __construct(ContainerInterface $container, ProfilerStorage $profilerStorage, $lifetime = 86400)
{
$this->container = $container;
$this->lifetime = $lifetime;
$this->requestDebugData = new RequestDebugData(uniqid(), $this->container->getParameter('kernel.cache_dir').'/debug.db');
$this->profilerStorage = $profilerStorage;
$this->collectors = $this->initCollectors();
}
@ -57,15 +57,15 @@ class DataCollectorManager
{
$data[$name] = $collector->getData();
}
$this->requestDebugData->write($data);
$this->requestDebugData->purge($this->lifetime);
$this->profilerStorage->write($data);
$this->profilerStorage->purge($this->lifetime);
return $response;
}
public function getRequestDebugData()
public function getProfilerStorage()
{
return $this->requestDebugData;
return $this->profilerStorage;
}
public function getResponse()

View File

@ -17,16 +17,16 @@ namespace Symfony\Framework\ProfilerBundle;
* @package symfony
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class RequestDebugData
class ProfilerStorage
{
protected $token;
protected $data;
protected $store;
public function __construct($token, $store)
public function __construct($store, $token = null)
{
$this->token = $token;
$this->store = $store;
$this->token = null === $token ? uniqid() : $token;
$this->data = null;
}

View File

@ -6,6 +6,8 @@
<parameters>
<parameter key="data_collector_manager.class">Symfony\Framework\ProfilerBundle\DataCollector\DataCollectorManager</parameter>
<parameter key="data_collector_manager.storage.class">Symfony\Framework\ProfilerBundle\ProfilerStorage</parameter>
<parameter key="data_collector_manager.storage.file">%kernel.cache_dir%/profiler.db</parameter>
<parameter key="data_collector_manager.lifetime">86400</parameter>
<parameter key="data_collector.config.class">Symfony\Framework\ProfilerBundle\DataCollector\ConfigDataCollector</parameter>
<parameter key="data_collector.app.class">Symfony\Framework\ProfilerBundle\DataCollector\AppDataCollector</parameter>
@ -17,9 +19,14 @@
<service id="data_collector_manager" class="%data_collector_manager.class%">
<annotation name="kernel.listener" event="core.response" method="handle" />
<argument type="service" id="service_container" />
<argument type="service" id="data_collector_manager.storage" />
<argument>%data_collector_manager.lifetime%</argument>
</service>
<service id="data_collector_manager.storage" class="%data_collector_manager.storage.class%">
<argument>%data_collector_manager.storage.file%</argument>
</service>
<service id="data_collector.config" class="%data_collector.config.class%">
<annotation name="data_collector" core="true" />
<argument type="service" id="service_container" />