From 61a8fc3c2ce810f8393b3c24a858c6ff5c114bc0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 16 Jun 2010 14:19:46 +0200 Subject: [PATCH] refactored the profiler classes --- .../Loader/LoaderExtension.php | 2 +- .../HttpKernel/Listener/Profiling.php} | 8 +-- .../HttpKernel}/Listener/WebDebugToolbar.php | 4 +- .../HttpKernel}/LoggerInterface.php | 2 +- .../Profiler}/DataCollector/DataCollector.php | 15 +--- .../DataCollector/DataCollectorInterface.php | 16 +++-- .../DataCollector/MemoryDataCollector.php | 4 +- .../HttpKernel/Profiler}/Profiler.php | 70 ++++++++----------- .../HttpKernel/Profiler}/ProfilerStorage.php | 6 +- .../Foundation/Debug/EventDispatcher.php | 2 +- .../DataCollector/DoctrineDataCollector.php | 10 ++- .../DoctrineBundle/Logger/DbalLogger.php | 2 +- .../Framework/ProfilerBundle/Bundle.php | 39 ----------- .../DependencyInjection/ProfilerExtension.php | 67 ------------------ .../schema/dic/symfony/profiler-1.0.xsd | 13 ---- .../ProfilerExtensionTest.php | 32 --------- .../ProfilerBundle/Tests/TestCase.php | 16 ----- .../PropelBundle/Logger/PropelLogger.php | 2 +- .../Controller/ControllerManager.php | 2 +- .../DataCollector/AppDataCollector.php | 14 +++- .../DataCollector/ConfigDataCollector.php | 13 +++- .../DataCollector/TimerDataCollector.php | 14 +++- .../DependencyInjection/WebExtension.php | 29 +++++++- .../WebBundle/Listener/ControllerLoader.php | 2 +- .../WebBundle/Listener/ExceptionHandler.php | 2 +- .../WebBundle/Listener/RequestParser.php | 2 +- src/Symfony/Framework/WebBundle/Profiler.php | 58 +++++++++++++++ .../Resources/config/collectors.xml | 17 +++-- .../config/schema/dic/symfony/symfony-1.0.xsd | 12 ++-- .../Resources/config/toolbar.xml | 2 +- .../skeleton/application/xml/Kernel.php | 1 - .../application/xml/config/config.xml | 2 +- .../application/xml/config/config_dev.xml | 6 +- .../application/xml/config/config_test.xml | 6 +- .../skeleton/application/yaml/Kernel.php | 1 - .../application/yaml/config/config.yml | 2 +- .../application/yaml/config/config_dev.yml | 2 +- .../application/yaml/config/config_test.yml | 2 +- .../WebBundle/Templating/Debugger.php | 2 +- .../DependencyInjection/WebExtensionTest.php | 14 +++- .../Framework/ZendBundle/Logger/Logger.php | 2 +- 41 files changed, 231 insertions(+), 286 deletions(-) rename src/Symfony/{Framework/ProfilerBundle/Listener/DataCollector.php => Components/HttpKernel/Listener/Profiling.php} (85%) rename src/Symfony/{Framework/ProfilerBundle => Components/HttpKernel}/Listener/WebDebugToolbar.php (96%) rename src/Symfony/{Foundation => Components/HttpKernel}/LoggerInterface.php (94%) rename src/Symfony/{Framework/ProfilerBundle => Components/HttpKernel/Profiler}/DataCollector/DataCollector.php (65%) rename src/Symfony/{Framework/ProfilerBundle => Components/HttpKernel/Profiler}/DataCollector/DataCollectorInterface.php (57%) rename src/Symfony/{Framework/ProfilerBundle => Components/HttpKernel/Profiler}/DataCollector/MemoryDataCollector.php (92%) rename src/Symfony/{Framework/ProfilerBundle => Components/HttpKernel/Profiler}/Profiler.php (76%) rename src/Symfony/{Framework/ProfilerBundle => Components/HttpKernel/Profiler}/ProfilerStorage.php (96%) delete mode 100644 src/Symfony/Framework/ProfilerBundle/Bundle.php delete mode 100644 src/Symfony/Framework/ProfilerBundle/DependencyInjection/ProfilerExtension.php delete mode 100644 src/Symfony/Framework/ProfilerBundle/Resources/config/schema/dic/symfony/profiler-1.0.xsd delete mode 100644 src/Symfony/Framework/ProfilerBundle/Tests/DependencyInjection/ProfilerExtensionTest.php delete mode 100644 src/Symfony/Framework/ProfilerBundle/Tests/TestCase.php rename src/Symfony/Framework/{ProfilerBundle => WebBundle}/DataCollector/AppDataCollector.php (86%) rename src/Symfony/Framework/{ProfilerBundle => WebBundle}/DataCollector/ConfigDataCollector.php (94%) rename src/Symfony/Framework/{ProfilerBundle => WebBundle}/DataCollector/TimerDataCollector.php (81%) create mode 100644 src/Symfony/Framework/WebBundle/Profiler.php rename src/Symfony/Framework/{ProfilerBundle => WebBundle}/Resources/config/collectors.xml (73%) rename src/Symfony/Framework/{ProfilerBundle => WebBundle}/Resources/config/toolbar.xml (84%) diff --git a/src/Symfony/Components/DependencyInjection/Loader/LoaderExtension.php b/src/Symfony/Components/DependencyInjection/Loader/LoaderExtension.php index 3ceade83942f..53fc48d0ec16 100644 --- a/src/Symfony/Components/DependencyInjection/Loader/LoaderExtension.php +++ b/src/Symfony/Components/DependencyInjection/Loader/LoaderExtension.php @@ -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); diff --git a/src/Symfony/Framework/ProfilerBundle/Listener/DataCollector.php b/src/Symfony/Components/HttpKernel/Listener/Profiling.php similarity index 85% rename from src/Symfony/Framework/ProfilerBundle/Listener/DataCollector.php rename to src/Symfony/Components/HttpKernel/Listener/Profiling.php index e9f5e9af1580..295a0f54ba83 100644 --- a/src/Symfony/Framework/ProfilerBundle/Listener/DataCollector.php +++ b/src/Symfony/Components/HttpKernel/Listener/Profiling.php @@ -1,12 +1,12 @@ */ -class DataCollector +class Profiling { protected $profiler; diff --git a/src/Symfony/Framework/ProfilerBundle/Listener/WebDebugToolbar.php b/src/Symfony/Components/HttpKernel/Listener/WebDebugToolbar.php similarity index 96% rename from src/Symfony/Framework/ProfilerBundle/Listener/WebDebugToolbar.php rename to src/Symfony/Components/HttpKernel/Listener/WebDebugToolbar.php index ecb52d14694e..93936884e333 100644 --- a/src/Symfony/Framework/ProfilerBundle/Listener/WebDebugToolbar.php +++ b/src/Symfony/Components/HttpKernel/Listener/WebDebugToolbar.php @@ -1,13 +1,13 @@ */ 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; @@ -42,8 +35,6 @@ public function setData($data) $this->data = $data; } - abstract public function collect(); - public function setProfiler(Profiler $profiler) { $this->profiler = $profiler; diff --git a/src/Symfony/Framework/ProfilerBundle/DataCollector/DataCollectorInterface.php b/src/Symfony/Components/HttpKernel/Profiler/DataCollector/DataCollectorInterface.php similarity index 57% rename from src/Symfony/Framework/ProfilerBundle/DataCollector/DataCollectorInterface.php rename to src/Symfony/Components/HttpKernel/Profiler/DataCollector/DataCollectorInterface.php index d3aa22825862..af70ceabc287 100644 --- a/src/Symfony/Framework/ProfilerBundle/DataCollector/DataCollectorInterface.php +++ b/src/Symfony/Components/HttpKernel/Profiler/DataCollector/DataCollectorInterface.php @@ -1,8 +1,8 @@ */ 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); } diff --git a/src/Symfony/Framework/ProfilerBundle/DataCollector/MemoryDataCollector.php b/src/Symfony/Components/HttpKernel/Profiler/DataCollector/MemoryDataCollector.php similarity index 92% rename from src/Symfony/Framework/ProfilerBundle/DataCollector/MemoryDataCollector.php rename to src/Symfony/Components/HttpKernel/Profiler/DataCollector/MemoryDataCollector.php index 3e64183b214f..c58ba000c652 100644 --- a/src/Symfony/Framework/ProfilerBundle/DataCollector/MemoryDataCollector.php +++ b/src/Symfony/Components/HttpKernel/Profiler/DataCollector/MemoryDataCollector.php @@ -1,6 +1,6 @@ */ class MemoryDataCollector extends DataCollector diff --git a/src/Symfony/Framework/ProfilerBundle/Profiler.php b/src/Symfony/Components/HttpKernel/Profiler/Profiler.php similarity index 76% rename from src/Symfony/Framework/ProfilerBundle/Profiler.php rename to src/Symfony/Components/HttpKernel/Profiler/Profiler.php index 689bf5a917af..d9f9f74ee41f 100644 --- a/src/Symfony/Framework/ProfilerBundle/Profiler.php +++ b/src/Symfony/Components/HttpKernel/Profiler/Profiler.php @@ -1,11 +1,11 @@ */ 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() @@ -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 { @@ -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]); @@ -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); - } } diff --git a/src/Symfony/Framework/ProfilerBundle/ProfilerStorage.php b/src/Symfony/Components/HttpKernel/Profiler/ProfilerStorage.php similarity index 96% rename from src/Symfony/Framework/ProfilerBundle/ProfilerStorage.php rename to src/Symfony/Components/HttpKernel/Profiler/ProfilerStorage.php index 6ef9f2c69bf7..c60db02b467e 100644 --- a/src/Symfony/Framework/ProfilerBundle/ProfilerStorage.php +++ b/src/Symfony/Components/HttpKernel/Profiler/ProfilerStorage.php @@ -1,6 +1,6 @@ */ class ProfilerStorage @@ -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)'); diff --git a/src/Symfony/Foundation/Debug/EventDispatcher.php b/src/Symfony/Foundation/Debug/EventDispatcher.php index 76ada90d9213..11a8cb937b14 100644 --- a/src/Symfony/Foundation/Debug/EventDispatcher.php +++ b/src/Symfony/Foundation/Debug/EventDispatcher.php @@ -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; /* diff --git a/src/Symfony/Framework/DoctrineBundle/DataCollector/DoctrineDataCollector.php b/src/Symfony/Framework/DoctrineBundle/DataCollector/DoctrineDataCollector.php index 2d0639d23a0e..2592d8ba01dd 100644 --- a/src/Symfony/Framework/DoctrineBundle/DataCollector/DoctrineDataCollector.php +++ b/src/Symfony/Framework/DoctrineBundle/DataCollector/DoctrineDataCollector.php @@ -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. @@ -22,6 +23,13 @@ */ class DoctrineDataCollector extends DataCollector { + protected $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + public function collect() { $this->data = array(); diff --git a/src/Symfony/Framework/DoctrineBundle/Logger/DbalLogger.php b/src/Symfony/Framework/DoctrineBundle/Logger/DbalLogger.php index 7c21aaa17d1b..3080c4bfa2f8 100644 --- a/src/Symfony/Framework/DoctrineBundle/Logger/DbalLogger.php +++ b/src/Symfony/Framework/DoctrineBundle/Logger/DbalLogger.php @@ -2,7 +2,7 @@ namespace Symfony\Framework\DoctrineBundle\Logger; -use Symfony\Foundation\LoggerInterface; +use Symfony\Components\HttpKernel\LoggerInterface; use Doctrine\DBAL\Logging\DebugStack; /* diff --git a/src/Symfony/Framework/ProfilerBundle/Bundle.php b/src/Symfony/Framework/ProfilerBundle/Bundle.php deleted file mode 100644 index 1aa8b005f4d4..000000000000 --- a/src/Symfony/Framework/ProfilerBundle/Bundle.php +++ /dev/null @@ -1,39 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -/** - * Bundle. - * - * @package Symfony - * @subpackage Framework_ProfilerBundle - * @author Fabien Potencier - */ -class Bundle extends BaseBundle -{ - /** - * Customizes the Container instance. - * - * @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance - * - * @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance - */ - public function buildContainer(ContainerInterface $container) - { - Loader::registerExtension(new ProfilerExtension()); - } -} diff --git a/src/Symfony/Framework/ProfilerBundle/DependencyInjection/ProfilerExtension.php b/src/Symfony/Framework/ProfilerBundle/DependencyInjection/ProfilerExtension.php deleted file mode 100644 index 6e05139d0c87..000000000000 --- a/src/Symfony/Framework/ProfilerBundle/DependencyInjection/ProfilerExtension.php +++ /dev/null @@ -1,67 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -/** - * ProfilerExtension manages the data collectors and the web debug toolbar. - * - * @package Symfony - * @subpackage Framework_ProfilerBundle - * @author Fabien Potencier - */ -class ProfilerExtension extends LoaderExtension -{ - public function configLoad($config, BuilderConfiguration $configuration) - { - if (!$configuration->hasDefinition('profiler')) { - $loader = new XmlFileLoader(__DIR__.'/../Resources/config'); - $configuration->merge($loader->load('collectors.xml')); - } - - if (isset($config['toolbar'])) { - if ($config['toolbar']) { - if (!$configuration->hasDefinition('debug.toolbar')) { - $loader = new XmlFileLoader(__DIR__.'/../Resources/config'); - $configuration->merge($loader->load('toolbar.xml')); - } - } else { - $configuration->getDefinition('debug.toolbar')->clearAnnotations(); - } - } - - return $configuration; - } - - /** - * Returns the base path for the XSD files. - * - * @return string The XSD base path - */ - public function getXsdValidationBasePath() - { - return __DIR__.'/../Resources/config/'; - } - - public function getNamespace() - { - return 'http://www.symfony-project.org/schema/dic/symfony/profiler'; - } - - public function getAlias() - { - return 'profiler'; - } -} diff --git a/src/Symfony/Framework/ProfilerBundle/Resources/config/schema/dic/symfony/profiler-1.0.xsd b/src/Symfony/Framework/ProfilerBundle/Resources/config/schema/dic/symfony/profiler-1.0.xsd deleted file mode 100644 index b77f7fa99f17..000000000000 --- a/src/Symfony/Framework/ProfilerBundle/Resources/config/schema/dic/symfony/profiler-1.0.xsd +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - diff --git a/src/Symfony/Framework/ProfilerBundle/Tests/DependencyInjection/ProfilerExtensionTest.php b/src/Symfony/Framework/ProfilerBundle/Tests/DependencyInjection/ProfilerExtensionTest.php deleted file mode 100644 index ff3f3d77f913..000000000000 --- a/src/Symfony/Framework/ProfilerBundle/Tests/DependencyInjection/ProfilerExtensionTest.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Framework\ProfilerBundle\Tests\DependencyInjection; - -use Symfony\Framework\ProfilerBundle\Tests\TestCase; -use Symfony\Framework\ProfilerBundle\DependencyInjection\ProfilerExtension; -use Symfony\Components\DependencyInjection\BuilderConfiguration; - -class ProfilerExtensionTest extends TestCase -{ - public function testLoggerLoad() - { - $configuration = new BuilderConfiguration(); - $loader = new ProfilerExtension(); - - $configuration = $loader->configLoad(array(), $configuration); - $this->assertEquals('Symfony\\Framework\\ProfilerBundle\\Profiler', $configuration->getParameter('profiler.class'), '->configLoad() loads the collectors.xml file if not already loaded'); - $this->assertFalse($configuration->hasParameter('debug.toolbar.class'), '->configLoad() does not load the toolbar.xml file'); - - $configuration = $loader->configLoad(array('toolbar' => true), $configuration); - $this->assertEquals('Symfony\\Framework\\ProfilerBundle\\Listener\\WebDebugToolbar', $configuration->getParameter('debug.toolbar.class'), '->configLoad() loads the collectors.xml file if the toolbar option is given'); - } -} diff --git a/src/Symfony/Framework/ProfilerBundle/Tests/TestCase.php b/src/Symfony/Framework/ProfilerBundle/Tests/TestCase.php deleted file mode 100644 index 9c33135fbe8c..000000000000 --- a/src/Symfony/Framework/ProfilerBundle/Tests/TestCase.php +++ /dev/null @@ -1,16 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Framework\ProfilerBundle\Tests; - -class TestCase extends \PHPUnit_Framework_TestCase -{ -} diff --git a/src/Symfony/Framework/PropelBundle/Logger/PropelLogger.php b/src/Symfony/Framework/PropelBundle/Logger/PropelLogger.php index b29715743758..05e447ad398f 100644 --- a/src/Symfony/Framework/PropelBundle/Logger/PropelLogger.php +++ b/src/Symfony/Framework/PropelBundle/Logger/PropelLogger.php @@ -2,7 +2,7 @@ namespace Symfony\Framework\PropelBundle\Logger; -use Symfony\Foundation\LoggerInterface; +use Symfony\Components\HttpKernel\LoggerInterface; /* * This file is part of the Symfony framework. diff --git a/src/Symfony/Framework/WebBundle/Controller/ControllerManager.php b/src/Symfony/Framework/WebBundle/Controller/ControllerManager.php index 9028daffcf80..c7d09d21130b 100644 --- a/src/Symfony/Framework/WebBundle/Controller/ControllerManager.php +++ b/src/Symfony/Framework/WebBundle/Controller/ControllerManager.php @@ -2,7 +2,7 @@ namespace Symfony\Framework\WebBundle\Controller; -use Symfony\Foundation\LoggerInterface; +use Symfony\Components\HttpKernel\LoggerInterface; use Symfony\Components\DependencyInjection\ContainerInterface; use Symfony\Components\HttpKernel\HttpKernelInterface; use Symfony\Components\HttpKernel\Request; diff --git a/src/Symfony/Framework/ProfilerBundle/DataCollector/AppDataCollector.php b/src/Symfony/Framework/WebBundle/DataCollector/AppDataCollector.php similarity index 86% rename from src/Symfony/Framework/ProfilerBundle/DataCollector/AppDataCollector.php rename to src/Symfony/Framework/WebBundle/DataCollector/AppDataCollector.php index 579595edfef8..94660fb75c89 100644 --- a/src/Symfony/Framework/ProfilerBundle/DataCollector/AppDataCollector.php +++ b/src/Symfony/Framework/WebBundle/DataCollector/AppDataCollector.php @@ -1,6 +1,9 @@ */ class AppDataCollector extends DataCollector { + protected $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + public function collect() { $request = $this->container->getRequestService(); diff --git a/src/Symfony/Framework/ProfilerBundle/DataCollector/ConfigDataCollector.php b/src/Symfony/Framework/WebBundle/DataCollector/ConfigDataCollector.php similarity index 94% rename from src/Symfony/Framework/ProfilerBundle/DataCollector/ConfigDataCollector.php rename to src/Symfony/Framework/WebBundle/DataCollector/ConfigDataCollector.php index e7577506500a..93c4cd8403ca 100644 --- a/src/Symfony/Framework/ProfilerBundle/DataCollector/ConfigDataCollector.php +++ b/src/Symfony/Framework/WebBundle/DataCollector/ConfigDataCollector.php @@ -1,8 +1,10 @@ */ class ConfigDataCollector extends DataCollector { + protected $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + public function collect() { $kernel = $this->container->getKernelService(); diff --git a/src/Symfony/Framework/ProfilerBundle/DataCollector/TimerDataCollector.php b/src/Symfony/Framework/WebBundle/DataCollector/TimerDataCollector.php similarity index 81% rename from src/Symfony/Framework/ProfilerBundle/DataCollector/TimerDataCollector.php rename to src/Symfony/Framework/WebBundle/DataCollector/TimerDataCollector.php index 74a7c11ad136..3abad4d21dc8 100644 --- a/src/Symfony/Framework/ProfilerBundle/DataCollector/TimerDataCollector.php +++ b/src/Symfony/Framework/WebBundle/DataCollector/TimerDataCollector.php @@ -1,6 +1,9 @@ */ class TimerDataCollector extends DataCollector { + protected $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + public function collect() { $this->data = array( diff --git a/src/Symfony/Framework/WebBundle/DependencyInjection/WebExtension.php b/src/Symfony/Framework/WebBundle/DependencyInjection/WebExtension.php index 14a3bfb944de..c5e897f0a4c3 100644 --- a/src/Symfony/Framework/WebBundle/DependencyInjection/WebExtension.php +++ b/src/Symfony/Framework/WebBundle/DependencyInjection/WebExtension.php @@ -39,7 +39,7 @@ class WebExtension extends LoaderExtension * * @return BuilderConfiguration A BuilderConfiguration instance */ - public function webLoad($config, BuilderConfiguration $configuration) + public function configLoad($config, BuilderConfiguration $configuration) { if (!$configuration->hasDefinition('controller_manager')) { $loader = new XmlFileLoader(__DIR__.'/../Resources/config'); @@ -50,6 +50,33 @@ public function webLoad($config, BuilderConfiguration $configuration) $configuration->setParameter('debug.file_link_format', 'txmt://open?url=file://%%f&line=%%l'); } + if (isset($config['toolbar']) && $config['toolbar']) { + $config['profiler'] = true; + } + + if (isset($config['profiler'])) { + if ($config['profiler']) { + if (!$configuration->hasDefinition('profiler')) { + $loader = new XmlFileLoader(__DIR__.'/../Resources/config'); + $configuration->merge($loader->load('collectors.xml')); + } + } elseif ($configuration->hasDefinition('profiler')) { + $configuration->getDefinition('profiling')->clearAnnotations(); + } + } + + // toolbar need to be registered after the profiler + if (isset($config['toolbar'])) { + if ($config['toolbar']) { + if (!$configuration->hasDefinition('debug.toolbar')) { + $loader = new XmlFileLoader(__DIR__.'/../Resources/config'); + $configuration->merge($loader->load('toolbar.xml')); + } + } elseif ($configuration->hasDefinition('debug.toolbar')) { + $configuration->getDefinition('debug.toolbar')->clearAnnotations(); + } + } + return $configuration; } diff --git a/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php b/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php index f8eb006507c9..5d83fdf87b66 100644 --- a/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php +++ b/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php @@ -3,7 +3,7 @@ namespace Symfony\Framework\WebBundle\Listener; use Symfony\Framework\WebBundle\Controller\ControllerManager; -use Symfony\Foundation\LoggerInterface; +use Symfony\Components\HttpKernel\LoggerInterface; use Symfony\Components\EventDispatcher\EventDispatcher; use Symfony\Components\EventDispatcher\Event; diff --git a/src/Symfony/Framework/WebBundle/Listener/ExceptionHandler.php b/src/Symfony/Framework/WebBundle/Listener/ExceptionHandler.php index c150987e2f07..c1b95e6837c8 100644 --- a/src/Symfony/Framework/WebBundle/Listener/ExceptionHandler.php +++ b/src/Symfony/Framework/WebBundle/Listener/ExceptionHandler.php @@ -5,7 +5,7 @@ use Symfony\Components\DependencyInjection\ContainerInterface; use Symfony\Components\EventDispatcher\EventDispatcher; use Symfony\Components\EventDispatcher\Event; -use Symfony\Foundation\LoggerInterface; +use Symfony\Components\HttpKernel\LoggerInterface; use Symfony\Components\HttpKernel\HttpKernelInterface; /* diff --git a/src/Symfony/Framework/WebBundle/Listener/RequestParser.php b/src/Symfony/Framework/WebBundle/Listener/RequestParser.php index e42d018a677a..32cd491f75f2 100644 --- a/src/Symfony/Framework/WebBundle/Listener/RequestParser.php +++ b/src/Symfony/Framework/WebBundle/Listener/RequestParser.php @@ -2,7 +2,7 @@ namespace Symfony\Framework\WebBundle\Listener; -use Symfony\Foundation\LoggerInterface; +use Symfony\Components\HttpKernel\LoggerInterface; use Symfony\Components\DependencyInjection\ContainerInterface; use Symfony\Components\EventDispatcher\EventDispatcher; use Symfony\Components\EventDispatcher\Event; diff --git a/src/Symfony/Framework/WebBundle/Profiler.php b/src/Symfony/Framework/WebBundle/Profiler.php new file mode 100644 index 000000000000..3e008ab34eea --- /dev/null +++ b/src/Symfony/Framework/WebBundle/Profiler.php @@ -0,0 +1,58 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Profiler. + * + * @package Symfony + * @subpackage Framework_WebBundle + * @author Fabien Potencier + */ +class Profiler extends BaseProfiler +{ + protected $container; + + public function __construct(ContainerInterface $container, ProfilerStorage $profilerStorage, LoggerInterface $logger = null) + { + parent::__construct($profilerStorage, $logger); + + $this->container = $container; + $this->initCollectors(); + $this->loadCollectorData(); + } + + 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->setCollectors(array_merge($coreCollectors, $userCollectors)); + } +} diff --git a/src/Symfony/Framework/ProfilerBundle/Resources/config/collectors.xml b/src/Symfony/Framework/WebBundle/Resources/config/collectors.xml similarity index 73% rename from src/Symfony/Framework/ProfilerBundle/Resources/config/collectors.xml rename to src/Symfony/Framework/WebBundle/Resources/config/collectors.xml index fc5fca3c64c8..dfbe7ae951b9 100644 --- a/src/Symfony/Framework/ProfilerBundle/Resources/config/collectors.xml +++ b/src/Symfony/Framework/WebBundle/Resources/config/collectors.xml @@ -5,15 +5,15 @@ xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd"> - Symfony\Framework\ProfilerBundle\Profiler - Symfony\Framework\ProfilerBundle\ProfilerStorage + Symfony\Framework\WebBundle\Profiler + Symfony\Components\HttpKernel\Profiler\ProfilerStorage %kernel.cache_dir%/profiler.db 86400 - Symfony\Framework\ProfilerBundle\Listener\DataCollector - Symfony\Framework\ProfilerBundle\DataCollector\ConfigDataCollector - Symfony\Framework\ProfilerBundle\DataCollector\AppDataCollector - Symfony\Framework\ProfilerBundle\DataCollector\TimerDataCollector - Symfony\Framework\ProfilerBundle\DataCollector\MemoryDataCollector + Symfony\Components\HttpKernel\Listener\Profiling + Symfony\Framework\WebBundle\DataCollector\ConfigDataCollector + Symfony\Framework\WebBundle\DataCollector\AppDataCollector + Symfony\Framework\WebBundle\DataCollector\TimerDataCollector + Symfony\Components\HttpKernel\Profiler\DataCollector\MemoryDataCollector @@ -29,7 +29,7 @@ %profiler.storage.lifetime% - + @@ -51,7 +51,6 @@ - diff --git a/src/Symfony/Framework/WebBundle/Resources/config/schema/dic/symfony/symfony-1.0.xsd b/src/Symfony/Framework/WebBundle/Resources/config/schema/dic/symfony/symfony-1.0.xsd index 733fca835a6d..d467514dfa23 100644 --- a/src/Symfony/Framework/WebBundle/Resources/config/schema/dic/symfony/symfony-1.0.xsd +++ b/src/Symfony/Framework/WebBundle/Resources/config/schema/dic/symfony/symfony-1.0.xsd @@ -5,10 +5,16 @@ targetNamespace="http://www.symfony-project.org/schema/dic/symfony" elementFormDefault="qualified"> - + + + + + + + @@ -32,10 +38,6 @@ - - - - diff --git a/src/Symfony/Framework/ProfilerBundle/Resources/config/toolbar.xml b/src/Symfony/Framework/WebBundle/Resources/config/toolbar.xml similarity index 84% rename from src/Symfony/Framework/ProfilerBundle/Resources/config/toolbar.xml rename to src/Symfony/Framework/WebBundle/Resources/config/toolbar.xml index 1f50621ae1c8..062fcbfc0551 100644 --- a/src/Symfony/Framework/ProfilerBundle/Resources/config/toolbar.xml +++ b/src/Symfony/Framework/WebBundle/Resources/config/toolbar.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd"> - Symfony\Framework\ProfilerBundle\Listener\WebDebugToolbar + Symfony\Components\HttpKernel\Listener\WebDebugToolbar diff --git a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/xml/Kernel.php b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/xml/Kernel.php index a831698d0f9e..2e918772234f 100644 --- a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/xml/Kernel.php +++ b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/xml/Kernel.php @@ -28,7 +28,6 @@ public function registerBundles() ); if ($this->isDebug()) { - $bundles[] = new Symfony\Framework\ProfilerBundle\Bundle(); } return $bundles; diff --git a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/xml/config/config.xml b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/xml/config/config.xml index 786d18271b2a..94d342b763f5 100644 --- a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/xml/config/config.xml +++ b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/xml/config/config.xml @@ -22,7 +22,7 @@ error_handler_level="null" /> - + + http://www.symfony-project.org/schema/dic/zend http://www.symfony-project.org/schema/dic/zend/zend-1.0.xsd"> @@ -18,7 +16,7 @@ path="%kernel.logs_dir%/%kernel.environment%.log" /> - diff --git a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/xml/config/config_test.xml b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/xml/config/config_test.xml index 29c247f299f6..ca030166a20d 100644 --- a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/xml/config/config_test.xml +++ b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/xml/config/config_test.xml @@ -4,17 +4,15 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:zend="http://www.symfony-project.org/schema/dic/zend" xmlns:web="http://www.symfony-project.org/schema/dic/symfony" - xmlns:profiler="http://www.symfony-project.org/schema/dic/symfony/profiler" xmlns:kernel="http://www.symfony-project.org/schema/dic/symfony/kernel" xsi:schemaLocation="http://www.symfony-project.org/schema/dic/services http://www.symfony-project.org/schema/dic/services/services-1.0.xsd - http://www.symfony-project.org/schema/dic/zend http://www.symfony-project.org/schema/dic/zend/zend-1.0.xsd - http://www.symfony-project.org/schema/dic/symfony/profiler http://www.symfony-project.org/schema/dic/symfony/profiler-1.0.xsd"> + http://www.symfony-project.org/schema/dic/zend http://www.symfony-project.org/schema/dic/zend/zend-1.0.xsd"> - diff --git a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/Kernel.php b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/Kernel.php index 2a076c4b03c9..1befeb98e832 100644 --- a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/Kernel.php +++ b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/Kernel.php @@ -28,7 +28,6 @@ public function registerBundles() ); if ($this->isDebug()) { - $bundles[] = new Symfony\Framework\ProfilerBundle\Bundle(); } return $bundles; diff --git a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/config/config.yml b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/config/config.yml index 790b70d1ba2c..75617be26fad 100644 --- a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/config/config.yml +++ b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/config/config.yml @@ -5,7 +5,7 @@ kernel.config: charset: UTF-8 error_handler_level: null -web.web: ~ +web.config: ~ web.templating: escaping: htmlspecialchars diff --git a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/config/config_dev.yml b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/config/config_dev.yml index 01b7a84ba8f6..a13472930084 100644 --- a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/config/config_dev.yml +++ b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/config/config_dev.yml @@ -5,5 +5,5 @@ zend.logger: priority: debug path: %kernel.logs_dir%/%kernel.environment%.log -profiler.config: +web.config: toolbar: true diff --git a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/config/config_test.yml b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/config/config_test.yml index d8d29c445b74..f83bc41290fd 100644 --- a/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/config/config_test.yml +++ b/src/Symfony/Framework/WebBundle/Resources/skeleton/application/yaml/config/config_test.yml @@ -4,7 +4,7 @@ imports: zend.logger: priority: debug -profiler.config: +web.config: toolbar: false kernel.test: ~ diff --git a/src/Symfony/Framework/WebBundle/Templating/Debugger.php b/src/Symfony/Framework/WebBundle/Templating/Debugger.php index 1730a5dbfcc1..dc3277bc5e82 100644 --- a/src/Symfony/Framework/WebBundle/Templating/Debugger.php +++ b/src/Symfony/Framework/WebBundle/Templating/Debugger.php @@ -3,7 +3,7 @@ namespace Symfony\Framework\WebBundle\Templating; use Symfony\Components\Templating\DebuggerInterface; -use Symfony\Foundation\LoggerInterface; +use Symfony\Components\HttpKernel\LoggerInterface; /* * This file is part of the Symfony package. diff --git a/src/Symfony/Framework/WebBundle/Tests/DependencyInjection/WebExtensionTest.php b/src/Symfony/Framework/WebBundle/Tests/DependencyInjection/WebExtensionTest.php index 42a5e4965151..8691c6538d2e 100644 --- a/src/Symfony/Framework/WebBundle/Tests/DependencyInjection/WebExtensionTest.php +++ b/src/Symfony/Framework/WebBundle/Tests/DependencyInjection/WebExtensionTest.php @@ -17,13 +17,23 @@ class WebExtensionTest extends TestCase { - public function testWebLoad() + public function testConfigLoad() { $configuration = new BuilderConfiguration(); $loader = new WebExtension(); - $configuration = $loader->webLoad(array(), $configuration); + $configuration = $loader->configLoad(array(), $configuration); $this->assertEquals('Symfony\\Framework\\WebBundle\\Listener\\RequestParser', $configuration->getParameter('request_parser.class'), '->webLoad() loads the web.xml file if not already loaded'); + + $configuration = new BuilderConfiguration(); + $loader = new WebExtension(); + + $configuration = $loader->configLoad(array('profiler' => true), $configuration); + $this->assertEquals('Symfony\\Framework\\WebBundle\\Profiler', $configuration->getParameter('profiler.class'), '->configLoad() loads the collectors.xml file if not already loaded'); + $this->assertFalse($configuration->hasParameter('debug.toolbar.class'), '->configLoad() does not load the toolbar.xml file'); + + $configuration = $loader->configLoad(array('toolbar' => true), $configuration); + $this->assertEquals('Symfony\\Components\\HttpKernel\\Listener\\WebDebugToolbar', $configuration->getParameter('debug.toolbar.class'), '->configLoad() loads the collectors.xml file if the toolbar option is given'); } public function testUserLoad() diff --git a/src/Symfony/Framework/ZendBundle/Logger/Logger.php b/src/Symfony/Framework/ZendBundle/Logger/Logger.php index 409d3f81ae04..0c9258943562 100644 --- a/src/Symfony/Framework/ZendBundle/Logger/Logger.php +++ b/src/Symfony/Framework/ZendBundle/Logger/Logger.php @@ -3,7 +3,7 @@ namespace Symfony\Framework\ZendBundle\Logger; use Zend\Log\Logger as BaseLogger; -use Symfony\Foundation\LoggerInterface; +use Symfony\Components\HttpKernel\LoggerInterface; /* * This file is part of the Symfony framework.