Skip to content

Commit

Permalink
refactored the profiler classes
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 16, 2010
1 parent b9ae18d commit 61a8fc3
Show file tree
Hide file tree
Showing 41 changed files with 231 additions and 286 deletions.
Expand Up @@ -49,7 +49,7 @@ public function setConfiguration($name, $resource)
public function load($tag, array $config, BuilderConfiguration $configuration)
{
if (!method_exists($this, $method = $tag.'Load')) {
throw new \InvalidArgumentException(sprintf('The tag "%s" is not defined in the "%s" extension.', $tag, $this->getNamespace()));
throw new \InvalidArgumentException(sprintf('The tag "%s:%s" is not defined in the "%s" extension.', $this->getAlias(), $tag, $this->getAlias()));
}

return $this->$method($config, $configuration);
Expand Down
@@ -1,12 +1,12 @@
<?php

namespace Symfony\Framework\ProfilerBundle\Listener;
namespace Symfony\Components\HttpKernel\Listener;

use Symfony\Components\EventDispatcher\EventDispatcher;
use Symfony\Components\EventDispatcher\Event;
use Symfony\Components\HttpKernel\Response;
use Symfony\Components\HttpKernel\HttpKernelInterface;
use Symfony\Framework\ProfilerBundle\Profiler;
use Symfony\Components\HttpKernel\Profiler\Profiler;

/*
* This file is part of the Symfony framework.
Expand All @@ -18,13 +18,13 @@
*/

/**
* DataCollector collects data for the current request by listening to the core.response event.
* Profiling collects data for the current request by listening to the core.response event.
*
* @package Symfony
* @subpackage Framework_ProfilerBundle
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class DataCollector
class Profiling
{
protected $profiler;

Expand Down
@@ -1,13 +1,13 @@
<?php

namespace Symfony\Framework\ProfilerBundle\Listener;
namespace Symfony\Components\HttpKernel\Listener;

use Symfony\Components\DependencyInjection\ContainerInterface;
use Symfony\Components\EventDispatcher\EventDispatcher;
use Symfony\Components\EventDispatcher\Event;
use Symfony\Components\HttpKernel\Response;
use Symfony\Components\HttpKernel\HttpKernelInterface;
use Symfony\Framework\ProfilerBundle\Profiler;
use Symfony\Components\HttpKernel\Profiler\Profiler;

/*
* This file is part of the Symfony framework.
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Symfony\Foundation;
namespace Symfony\Components\HttpKernel;

/*
* This file is part of the Symfony framework.
Expand Down
@@ -1,9 +1,8 @@
<?php

namespace Symfony\Framework\ProfilerBundle\DataCollector;
namespace Symfony\Components\HttpKernel\Profiler\DataCollector;

use Symfony\Components\DependencyInjection\ContainerInterface;
use Symfony\Framework\ProfilerBundle\Profiler;
use Symfony\Components\HttpKernel\Profiler\Profiler;

/*
* This file is part of the Symfony framework.
Expand All @@ -18,20 +17,14 @@
* DataCollector.
*
* @package Symfony
* @subpackage Framework_ProfilerBundle
* @subpackage Components_HttpKernel
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
abstract class DataCollector implements DataCollectorInterface
{
protected $profiler;
protected $container;
protected $data;

public function __construct(ContainerInterface $container)
{
$this->container = $container;
}

public function getData()
{
return $this->data;
Expand All @@ -42,8 +35,6 @@ public function setData($data)
$this->data = $data;
}

abstract public function collect();

public function setProfiler(Profiler $profiler)
{
$this->profiler = $profiler;
Expand Down
@@ -1,8 +1,8 @@
<?php

namespace Symfony\Framework\ProfilerBundle\DataCollector;
namespace Symfony\Components\HttpKernel\Profiler\DataCollector;

use Symfony\Framework\ProfilerBundle\Profiler;
use Symfony\Components\HttpKernel\Profiler\Profiler;

/*
* This file is part of the Symfony framework.
Expand All @@ -17,14 +17,18 @@
* DataCollectorInterface.
*
* @package Symfony
* @subpackage Framework_ProfilerBundle
* @subpackage Components_HttpKernel
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
interface DataCollectorInterface
{
public function setProfiler(Profiler $profiler);
function getData();

public function getData();
function setData($data);

public function getName();
function getName();

function collect();

function setProfiler(Profiler $profiler);
}
@@ -1,6 +1,6 @@
<?php

namespace Symfony\Framework\ProfilerBundle\DataCollector;
namespace Symfony\Components\HttpKernel\Profiler\DataCollector;

/*
* This file is part of the Symfony framework.
Expand All @@ -15,7 +15,7 @@
* MemoryDataCollector.
*
* @package Symfony
* @subpackage Framework_ProfilerBundle
* @subpackage Components_HttpKernel
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class MemoryDataCollector extends DataCollector
Expand Down
@@ -1,11 +1,11 @@
<?php

namespace Symfony\Framework\ProfilerBundle;
namespace Symfony\Components\HttpKernel\Profiler;

use Symfony\Components\DependencyInjection\ContainerInterface;
use Symfony\Components\HttpKernel\Response;
use Symfony\Framework\ProfilerBundle\ProfilerStorage;
use Symfony\Foundation\LoggerInterface;
use Symfony\Components\HttpKernel\Profiler\ProfilerStorage;
use Symfony\Components\HttpKernel\Profiler\DataCollector\DataCollectorInterface;
use Symfony\Components\HttpKernel\LoggerInterface;

/*
* This file is part of the Symfony framework.
Expand All @@ -20,24 +20,21 @@
* Profiler.
*
* @package Symfony
* @subpackage Framework_ProfilerBundle
* @subpackage Components_HttpKernel
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class Profiler implements \ArrayAccess
{
protected $container;
protected $profilerStorage;
protected $collectors;
protected $response;
protected $logger;

public function __construct(ContainerInterface $container, ProfilerStorage $profilerStorage, LoggerInterface $logger = null)
public function __construct(ProfilerStorage $profilerStorage, LoggerInterface $logger = null)
{
$this->container = $container;
$this->profilerStorage = $profilerStorage;
$this->logger = $logger;
$this->initCollectors();
$this->loadCollectorData();
$this->collectors = array();
}

public function __clone()
Expand Down Expand Up @@ -81,16 +78,6 @@ public function collect(Response $response)
}
}

public function getProfilerStorage()
{
return $this->profilerStorage;
}

public function getResponse()
{
return $this->response;
}

public function loadCollectorData()
{
try {
Expand All @@ -104,11 +91,34 @@ public function loadCollectorData()
}
}

public function getProfilerStorage()
{
return $this->profilerStorage;
}

public function getResponse()
{
return $this->response;
}

public function getCollectors()
{
return $this->collectors;
}

public function setCollectors(array $collectors = array())
{
$this->collectors = array();
foreach ($collectors as $name => $collector) {
$this->setCollector($name, $collector);
}
}

public function setCollector($name, DataCollectorInterface $collector)
{
$this->collectors[$name] = $collector;
}

public function hasCollector($name)
{
return isset($this->collectors[$name]);
Expand Down Expand Up @@ -169,24 +179,4 @@ public function offsetUnset($name)
{
throw new \LogicException('The Collectors cannot be removed.');
}

protected function initCollectors()
{
$config = $this->container->findAnnotatedServiceIds('data_collector');
$ids = array();
$coreCollectors = array();
$userCollectors = array();
foreach ($config as $id => $attributes) {
$collector = $this->container->getService($id);
$collector->setProfiler($this);

if (isset($attributes[0]['core']) && $attributes[0]['core']) {
$coreCollectors[$collector->getName()] = $collector;
} else {
$userCollectors[$collector->getName()] = $collector;
}
}

$this->collectors = array_merge($coreCollectors, $userCollectors);
}
}
@@ -1,6 +1,6 @@
<?php

namespace Symfony\Framework\ProfilerBundle;
namespace Symfony\Components\HttpKernel\Profiler;

/*
* This file is part of the Symfony framework.
Expand All @@ -15,7 +15,7 @@
* ProfilerStorage.
*
* @package Symfony
* @subpackage Framework_ProfilerBundle
* @subpackage Components_HttpKernel
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class ProfilerStorage
Expand Down Expand Up @@ -100,7 +100,7 @@ protected function initDb($readOnly = true)
} elseif (class_exists('\PDO') && in_array('sqlite', \PDO::getAvailableDrivers(), true)) {
$db = new \PDO('sqlite:'.$this->store);
} else {
throw new \RuntimeException('You need to enable either the SQLite or PDO_SQLite extension for the ProfilerBundle to run properly.');
throw new \RuntimeException('You need to enable either the SQLite or PDO_SQLite extension for the profiler to run properly.');
}

$db->exec('CREATE TABLE IF NOT EXISTS data (token STRING, data STRING, created_at INTEGER)');
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Foundation/Debug/EventDispatcher.php
Expand Up @@ -5,7 +5,7 @@
use Symfony\Foundation\EventDispatcher as BaseEventDispatcher;
use Symfony\Components\EventDispatcher\EventDispatcherInterface;
use Symfony\Components\EventDispatcher\Event;
use Symfony\Foundation\LoggerInterface;
use Symfony\Components\HttpKernel\LoggerInterface;
use Symfony\Components\DependencyInjection\ContainerInterface;

/*
Expand Down
Expand Up @@ -2,7 +2,8 @@

namespace Symfony\Framework\DoctrineBundle\DataCollector;

use Symfony\Framework\ProfilerBundle\DataCollector\DataCollector;
use Symfony\Components\HttpKernel\Profiler\DataCollector\DataCollector;
use Symfony\Components\DependencyInjection\ContainerInterface;

/*
* This file is part of the Symfony framework.
Expand All @@ -22,6 +23,13 @@
*/
class DoctrineDataCollector extends DataCollector
{
protected $container;

public function __construct(ContainerInterface $container)
{
$this->container = $container;
}

public function collect()
{
$this->data = array();
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Framework/DoctrineBundle/Logger/DbalLogger.php
Expand Up @@ -2,7 +2,7 @@

namespace Symfony\Framework\DoctrineBundle\Logger;

use Symfony\Foundation\LoggerInterface;
use Symfony\Components\HttpKernel\LoggerInterface;
use Doctrine\DBAL\Logging\DebugStack;

/*
Expand Down
39 changes: 0 additions & 39 deletions src/Symfony/Framework/ProfilerBundle/Bundle.php

This file was deleted.

0 comments on commit 61a8fc3

Please sign in to comment.