Skip to content

DataCollector Component #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* ConfigDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\ConfigDataCollector instead.
*/
class ConfigDataCollector extends DataCollector
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\DataCollector;

use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
use Symfony\Component\Profiler\DataCollector\AbstractDataCollector;

/**
* DataCollector.
Expand All @@ -20,8 +21,10 @@
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Bernhard Schussek <bschussek@symfony.com>
*
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\AbstractDataCollector instead.
*/
abstract class DataCollector implements DataCollectorInterface, \Serializable
abstract class DataCollector extends AbstractDataCollector implements DataCollectorInterface, \Serializable
{
protected $data = array();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
* @author Fabien Potencier <fabien@symfony.com>
*
* @api
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\DataCollectorInterface instead.
*/
interface DataCollectorInterface
interface DataCollectorInterface extends \Symfony\Component\Profiler\DataCollector\DataCollectorInterface
{
/**
* Collects data for the given Request and Response.
Expand All @@ -33,13 +34,4 @@ interface DataCollectorInterface
* @api
*/
public function collect(Request $request, Response $response, \Exception $exception = null);

/**
* Returns the name of the collector.
*
* @return string The collector name
*
* @api
*/
public function getName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

/**
* @author Nicolas Grekas <p@tchwork.com>
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\DumpDataCollector instead.
*/
class DumpDataCollector extends DataCollector implements DataDumperInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,88 +20,9 @@
* EventDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\EventDataCollector instead.
*/
class EventDataCollector extends DataCollector implements LateDataCollectorInterface
class EventDataCollector extends \Symfony\Component\Profiler\DataCollector\EventDataCollector
{
protected $dispatcher;

public function __construct(EventDispatcherInterface $dispatcher = null)
{
$this->dispatcher = $dispatcher;
}

/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data = array(
'called_listeners' => array(),
'not_called_listeners' => array(),
);
}

public function lateCollect()
{
if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
$this->setCalledListeners($this->dispatcher->getCalledListeners());
$this->setNotCalledListeners($this->dispatcher->getNotCalledListeners());
}
}

/**
* Sets the called listeners.
*
* @param array $listeners An array of called listeners
*
* @see TraceableEventDispatcherInterface
*/
public function setCalledListeners(array $listeners)
{
$this->data['called_listeners'] = $listeners;
}

/**
* Gets the called listeners.
*
* @return array An array of called listeners
*
* @see TraceableEventDispatcherInterface
*/
public function getCalledListeners()
{
return $this->data['called_listeners'];
}

/**
* Sets the not called listeners.
*
* @param array $listeners An array of not called listeners
*
* @see TraceableEventDispatcherInterface
*/
public function setNotCalledListeners(array $listeners)
{
$this->data['not_called_listeners'] = $listeners;
}

/**
* Gets the not called listeners.
*
* @return array An array of not called listeners
*
* @see TraceableEventDispatcherInterface
*/
public function getNotCalledListeners()
{
return $this->data['not_called_listeners'];
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'events';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* ExceptionDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\ExceptionDataCollector instead.
*/
class ExceptionDataCollector extends DataCollector
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
* LateDataCollectorInterface.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\LateDataCollectorInterface instead.
*/
interface LateDataCollectorInterface
interface LateDataCollectorInterface extends \Symfony\Component\Profiler\DataCollector\LateDataCollectorInterface
{
/**
* Collects data as late as possible.
*/
public function lateCollect();

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* LogDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\LoggerDataCollector instead.
*/
class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* MemoryDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\MemoryDataCollector instead.
*
*/
class MemoryDataCollector extends DataCollector implements LateDataCollectorInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* RequestDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\RequestDataCollector instead.
*/
class RequestDataCollector extends DataCollector implements EventSubscriberInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* RouterDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\RouterDataCollector instead.
*/
class RouterDataCollector extends DataCollector
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* TimeDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\TimeDataCollector instead.
*/
class TimeDataCollector extends DataCollector implements LateDataCollectorInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

/**
* @author Bernhard Schussek <bschussek@gmail.com>
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\DataCollector\Util\ValueExporter instead.
*/
class ValueExporter
{
Expand Down
127 changes: 4 additions & 123 deletions src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,134 +11,15 @@

namespace Symfony\Component\HttpKernel\EventListener;

use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Profiler\EventListener\HttpProfilerListener;

/**
* ProfilerListener collects data for the current request by listening to the kernel events.
*
* @author Fabien Potencier <fabien@symfony.com>
* @deprecated since x.x, to be removed in x.x. Use Symfony\Component\Profiler\EventListener\ProfileListener instead.
*/
class ProfilerListener implements EventSubscriberInterface
class ProfilerListener extends HttpProfilerListener
{
protected $profiler;
protected $matcher;
protected $onlyException;
protected $onlyMasterRequests;
protected $exception;
protected $requests = array();
protected $profiles;
protected $requestStack;
protected $parents;

/**
* Constructor.
*
* @param Profiler $profiler A Profiler instance
* @param RequestMatcherInterface|null $matcher A RequestMatcher instance
* @param bool $onlyException true if the profiler only collects data when an exception occurs, false otherwise
* @param bool $onlyMasterRequests true if the profiler only collects data when the request is a master request, false otherwise
* @param RequestStack|null $requestStack A RequestStack instance
*/
public function __construct(Profiler $profiler, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false, RequestStack $requestStack = null)
{
$this->profiler = $profiler;
$this->matcher = $matcher;
$this->onlyException = (bool) $onlyException;
$this->onlyMasterRequests = (bool) $onlyMasterRequests;
$this->profiles = new \SplObjectStorage();
$this->parents = new \SplObjectStorage();
$this->requestStack = $requestStack;
}

/**
* Handles the onKernelException event.
*
* @param GetResponseForExceptionEvent $event A GetResponseForExceptionEvent instance
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if ($this->onlyMasterRequests && !$event->isMasterRequest()) {
return;
}

$this->exception = $event->getException();
}

/**
* Handles the onKernelResponse event.
*
* @param FilterResponseEvent $event A FilterResponseEvent instance
*/
public function onKernelResponse(FilterResponseEvent $event)
{
$master = $event->isMasterRequest();
if ($this->onlyMasterRequests && !$master) {
return;
}

if ($this->onlyException && null === $this->exception) {
return;
}

$request = $event->getRequest();
$exception = $this->exception;
$this->exception = null;

if (null !== $this->matcher && !$this->matcher->matches($request)) {
return;
}

if (!$profile = $this->profiler->collect($request, $event->getResponse(), $exception)) {
return;
}

$this->profiles[$request] = $profile;

if (null !== $this->requestStack) {
$this->parents[$request] = $this->requestStack->getParentRequest();
} elseif (!$master) {
// to be removed when requestStack is required
array_pop($this->requests);

$this->parents[$request] = end($this->requests);
}
}

public function onKernelTerminate(PostResponseEvent $event)
{
// attach children to parents
foreach ($this->profiles as $request) {
// isset call should be removed when requestStack is required
if (isset($this->parents[$request]) && null !== $parentRequest = $this->parents[$request]) {
if (isset($this->profiles[$parentRequest])) {
$this->profiles[$parentRequest]->addChild($this->profiles[$request]);
}
}
}

// save profiles
foreach ($this->profiles as $request) {
$this->profiler->saveProfile($this->profiles[$request]);
}

$this->profiles = new \SplObjectStorage();
$this->parents = new \SplObjectStorage();
$this->requests = array();
}

public static function getSubscribedEvents()
{
return array(
KernelEvents::RESPONSE => array('onKernelResponse', -100),
KernelEvents::EXCEPTION => 'onKernelException',
KernelEvents::TERMINATE => array('onKernelTerminate', -1024),
);
}
}
}
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy