diff --git a/src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php index 9ed05821dfac..0c35cf170151 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php @@ -11,6 +11,7 @@ namespace Symfony\Component\HttpKernel\DataCollector; +use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -21,7 +22,7 @@ * * @author Fabien Potencier */ -class EventDataCollector extends DataCollector +class EventDataCollector extends DataCollector implements LateDataCollectorInterface { protected $dispatcher; @@ -41,6 +42,14 @@ public function collect(Request $request, Response $response, \Exception $except ); } + public function lateCollect() + { + if ($this->dispatcher instanceof TraceableEventDispatcherInterface) { + $this->setCalledListeners($this->dispatcher->getCalledListeners()); + $this->setNotCalledListeners($this->dispatcher->getNotCalledListeners()); + } + } + /** * Sets the called listeners. * @@ -89,16 +98,6 @@ public function getNotCalledListeners() return $this->data['not_called_listeners']; } - public function serialize() - { - if ($this->dispatcher instanceof TraceableEventDispatcherInterface) { - $this->setCalledListeners($this->dispatcher->getCalledListeners()); - $this->setNotCalledListeners($this->dispatcher->getNotCalledListeners()); - } - - return parent::serialize(); - } - /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/HttpKernel/DataCollector/LateDataCollectorInterface.php b/src/Symfony/Component/HttpKernel/DataCollector/LateDataCollectorInterface.php new file mode 100644 index 000000000000..2c4ccb6850ed --- /dev/null +++ b/src/Symfony/Component/HttpKernel/DataCollector/LateDataCollectorInterface.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\DataCollector; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; + +/** + * LateDataCollectorInterface. + * + * @author Fabien Potencier + */ +interface LateDataCollectorInterface +{ + /** + * Collects data as late as possible. + */ + public function lateCollect(); +} diff --git a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php index f08720e8073b..7a94fa859546 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php @@ -32,6 +32,14 @@ public function __construct($logger = null) } } + /** + * {@inheritdoc} + */ + public function collect(Request $request, Response $response, \Exception $exception = null) + { + // everything is done as late as possible + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php index 03d61e5af1e0..8db93621537b 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php @@ -11,6 +11,7 @@ namespace Symfony\Component\HttpKernel\DataCollector; +use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -19,7 +20,7 @@ * * @author Fabien Potencier */ -class MemoryDataCollector extends DataCollector +class MemoryDataCollector extends DataCollector implements LateDataCollectorInterface { public function __construct() { @@ -37,6 +38,14 @@ public function collect(Request $request, Response $response, \Exception $except $this->updateMemoryUsage(); } + /** + * {@inheritdoc} + */ + public function lateCollect() + { + $this->updateMemoryUsage(); + } + /** * Gets the memory. * @@ -65,13 +74,6 @@ public function updateMemoryUsage() $this->data['memory'] = memory_get_peak_usage(true); } - public function serialize() - { - $this->updateMemoryUsage(); - - return parent::serialize(); - } - /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php index 4f73418f26fb..3dd59465df97 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\DataCollector; use Symfony\Component\HttpKernel\DataCollector\DataCollector; +use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -22,7 +23,7 @@ * * @author Fabien Potencier */ -class TimeDataCollector extends DataCollector +class TimeDataCollector extends DataCollector implements LateDataCollectorInterface { protected $kernel; protected $stopwatch; @@ -51,6 +52,17 @@ public function collect(Request $request, Response $response, \Exception $except ); } + /** + * {@inheritdoc} + */ + public function lateCollect() + { + if (null !== $this->stopwatch && isset($this->data['token'])) { + $this->setEvents($this->stopwatch->getSectionEvents($this->data['token'])); + } + unset($this->data['token']); + } + /** * Sets the request events. * @@ -117,16 +129,6 @@ public function getStartTime() return $this->data['start_time']; } - public function serialize() - { - if (null !== $this->stopwatch && isset($this->data['token'])) { - $this->setEvents($this->stopwatch->getSectionEvents($this->data['token'])); - } - unset($this->data['token']); - - return parent::serialize(); - } - /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/HttpKernel/Profiler/Profiler.php b/src/Symfony/Component/HttpKernel/Profiler/Profiler.php index 3315eebd21ef..1c90a8a3c85b 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/Profiler.php +++ b/src/Symfony/Component/HttpKernel/Profiler/Profiler.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface; use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface; +use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; use Psr\Log\LoggerInterface; /** @@ -109,6 +110,13 @@ public function loadProfile($token) */ public function saveProfile(Profile $profile) { + // late collect + foreach ($profile->getCollectors() as $collector) { + if ($collector instanceof LateDataCollectorInterface) { + $collector->lateCollect(); + } + } + if (!($ret = $this->storage->write($profile)) && null !== $this->logger) { $this->logger->warning('Unable to store the profiler information.'); }