10000 [WIP] Master profiler component by yjv · Pull Request #20502 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Master profiler component #20502

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 10 commits into from
Prev Previous commit
Next Next commit
movedthins artound renamed things
  • Loading branch information
yjv committed Nov 6, 2016
commit 52e2eecd4d53307444d22ae9307b40b290b64c13
10000
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
* Time: 10:27 PM
*/

namespace Symfony\Component\Profiler\Data;
namespace Symfony\Component\Profiler\Context;

use Symfony\Component\Console\Command\Command;

class ConsoleCommandData implements DataInterface
class ConsoleCommandContext implements ContextInterface
{
protected $exception;
protected $exitCode;
Expand Down Expand Up @@ -44,7 +44,7 @@ public function getException()
/**
* @return null|string
*/
public function getUri()
public function getName()
{
return sprintf('command=>%s', $this->command->getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Time: 5:06 PM
*/

namespace Symfony\Component\Profiler\Data;
namespace Symfony\Component\Profiler\Context;

interface DataInterface
interface ContextInterface
{
/**
* @return \Exception|\Throwable|null
Expand All @@ -18,7 +18,7 @@ public function getException();
/**
* @return null|string
*/
public function getUri();
public function getName();

/**
* @return null|string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* Time: 10:18 PM
*/

namespace Symfony\Component\Profiler\Data;
namespace Symfony\Component\Profiler\Context;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class RequestData implements DataInterface
class RequestContext implements ContextInterface
{
protected $exception;
protected $request;
Expand All @@ -33,7 +33,7 @@ public function getException()
return $this->exception;
}

public function getUri()
public function getName()
{
return $this->request->getUri();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace Symfony\Component\Profiler\DataCollector;

use Symfony\Component\Profiler\Data\DataInterface;
use Symfony\Component\Profiler\Context\ContextInterface;
use Symfony\Component\Profiler\Profile;
use Symfony\Component\Profiler\Data\RequestData;
use Symfony\Component\Profiler\Context\RequestContext;

/**
* AjaxDataCollector.
Expand All @@ -22,9 +22,9 @@
*/
class AjaxDataCollector extends DataCollector
{
public function collectData(DataInterface $data, Profile $profile)
public function collectData(ContextInterface $context, Profile $profile)
{
return $data instanceof RequestData;
return $context instanceof RequestContext;
}

public function getName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Profiler\Data\DataInterface;
use Symfony\Component\Profiler\Context\ContextInterface;
use Symfony\Component\Profiler\Profile;

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ public function setKernel(KernelInterface $kernel = null)
/**
* {@inheritdoc}
*/
public function collectData(DataInterface $data, Profile $profile)
public function collectData(ContextInterface $context, Profile $profile)
{
$this->data = array(
'app_name' => $this->name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Profiler\DataCollector;

use Symfony\Component\Profiler\Data\DataInterface;
use Symfony\Component\Profiler\Context\ContextInterface;
use Symfony\Component\Profiler\Profile;

/**
Expand All @@ -24,11 +24,11 @@ interface DataCollectorInterface
/**
* Collects data for the given Request and Response.
*
* @param DataInterface $data
* @param ContextInterface $context
* @param Profile $profile
* @return
*/
public function collectData(DataInterface $data, Profile $profile);
public function collectData(ContextInterface $context, Profile $profile);

/**
* Returns the name of the collector.
Expand Down
24 changes: 12 additions & 12 deletions src/Symfony/Component/Profiler/DataCollector/DumpDataCollector.php
Original file line number Diff line number Diff line change
F438 Expand Up @@ -12,9 +12,9 @@
namespace Symfony\Component\Profiler\DataCollector;

use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Profiler\Data\DataInterface;
use Symfony\Component\Profiler\Context\ContextInterface;
use Symfony\Component\Profiler\Profile;
use Symfony\Component\Profiler\Data\RequestData;
use Symfony\Component\Profiler\Context\RequestContext;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Cloner\VarCloner;
Expand Down Expand Up @@ -140,31 +140,31 @@ public function dump(Data $data)
}
}

public function collectData(DataInterface $data, Profile $profile)
public function collectData(ContextInterface $context, Profile $profile)
{
// Sub-requests and programmatic calls stay in the collected profile.
if ($this->dumper) {
return true;
}

if ($data instanceof RequestData) {
$request = $data->getRequest();
if ($context instanceof RequestContext) {
$request = $context->getRequest();

if (($this->requestStack && $this->requestStack->getMasterRequest() !== $request) || $request->isXmlHttpRequest() || $request->headers->has('Origin')) {
return true;
}
}

// In all other conditions that remove the web debug toolbar, dumps are written on the output.
if (!$data instanceof RequestData
if (!$context instanceof RequestContext
|| !$this->requestStack
|| !$data->getResponse()->headers->has('X-Debug-Token')
|| $data->getResponse()->isRedirection()
|| ($data->getResponse()->headers->has('Content-Type') && false === strpos($data->getResponse()->headers->get('Content-Type'), 'html'))
|| 'html' !== $data->getRequest()->getRequestFormat()
|| false === strripos($data->getResponse()->getContent(), '</body>')
|| !$context->getResponse()->headers->has('X-Debug-Token')
|| $context->getResponse()->isRedirection()
|| ($context->getResponse()->headers->has('Content-Type') && false === strpos($context->getResponse()->headers->get('Content-Type'), 'html'))
|| 'html' !== $context->getRequest()->getRequestFormat()
|| false === strripos($context->getResponse()->getContent(), '</body>')
) {
if ($data instanceof RequestData && $data->getResponse()->headers->has('Content-Type') && false !== strpos($data->getResponse()->headers->get('Content-Type'), 'html')) {
if ($context instanceof RequestContext && $context->getResponse()->headers->has('Content-Type') && false !== strpos($context->getResponse()->headers->get('Content-Type'), 'html')) {
$this->dumper = new HtmlDumper('php://output', $this->charset);
$this->dumper->setDisplayOptions(array('fileLinkFormat' => $this->fileLinkFormat));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcherInterface;
use Symfony\Component\Profiler\Data\DataInterface;
use Symfony\Component\Profiler\Context\ContextInterface;
use Symfony\Component\Profiler\Profile;

/**
Expand All @@ -33,7 +33,7 @@ public function __construct(EventDispatcherInterface $dispatcher = null)
/**
* {@inheritdoc}
*/
public function collectData(DataInterface $data, Profile $profile)
public function collectData(ContextInterface $context, Profile $profile)
{
$this->data = array(
'called_listeners' => array(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\Profiler\DataCollector;

use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\Profiler\Data\DataInterface;
use Symfony\Component\Profiler\Context\ContextInterface;
use Symfony\Component\Profiler\Profile;

/**
Expand All @@ -25,11 +25,11 @@ class ExceptionDataCollector extends DataCollector
/**
* {@inheritdoc}
*/
public function collectData(DataInterface $data, Profile $profile)
public function collectData(ContextInterface $context, Profile $profile)
{
if (null !== $data->getException()) {
if (null !== $context->getException()) {
$this->data = array(
'exception' => FlattenException::create($data->getException()),
'exception' => FlattenException::create($context->getException()),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Symfony\Component\Debug\Exception\SilencedErrorContext;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use Symfony\Component\Profiler\Data\DataInterface;
use Symfony\Component\Profiler\Context\ContextInterface;
use Symfony\Component\Profiler\Profile;

/**
Expand All @@ -35,7 +35,7 @@ public function __construct($logger = null)
/**
* {@inheritdoc}
*/
public function collectData(DataInterface $data, Profile $profile)
public function collectData(ContextInterface $context, Profile $profile)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Component\Profiler\DataCollector;

use Symfony\Component\Profiler\Data\DataInterface;
use Symfony\Component\Profiler\Context\ContextInterface;
use Symfony\Component\Profiler\Profile;

/**
Expand All @@ -32,7 +32,7 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function collectData(DataInterface $data, Profile $profile)
public function collectData(ContextInterface $context, Profile $profile)
{
$this->updateMemoryUsage();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Profiler\Data\DataInterface;
use Symfony\Component\Profiler\Context\ContextInterface;
use Symfony\Component\Profiler\Profile;
use Symfony\Component\Profiler\Data\RequestData;
use Symfony\Component\Profiler\Context\RequestContext;
use Symfony\Component\Routing\Route;

/**
Expand All @@ -43,14 +43,14 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function collectData(DataInterface $data, Profile $profile)
public function collectData(ContextInterface $context, Profile $profile)
{
if (!$data instanceof RequestData) {
if (!$context instanceof RequestContext) {
return false;
}

$response = $data->getResponse();
$request = $data->getRequest();
$response = $context->getResponse();
$request = $context->getRequest();
$profile->setMethod($request->getMethod());
try {
$profile->setIp($request->getClientIp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\Profiler\Data\DataInterface;
use Symfony\Component\Profiler\Context\ContextInterface;
use Symfony\Component\Profiler\Profile;
use Symfony\Component\Profiler\Data\RequestData;
use Symfony\Component\Profiler\Context\RequestContext;

/**
* RouterDataCollector.
Expand All @@ -41,14 +41,14 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function collectData(DataInterface $data, Profile $profile)
public function collectData(ContextInterface $context, Profile $profile)
{
if (!$data instanceof RequestData) {
if (!$context instanceof RequestContext) {
return false;
}

$request = $data->getRequest();
$response = $data->getResponse();
$request = $context->getRequest();
$response = $context->getResponse();

if ($response instanceof RedirectResponse) {
$this->data['redirect'] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Profiler\Data\DataInterface;
use Symfony\Component\Profiler\Context\ContextInterface;
use Symfony\Component\Profiler\Profile;
use Symfony\Component\Profiler\Data\RequestData;
use Symfony\Component\Profiler\Context\RequestContext;
use Symfony\Component\Stopwatch\Stopwatch;

/**
Expand All @@ -37,13 +37,13 @@ public function __construct(KernelInterface $kernel = null, Stopwatch $stopwatch
/**
* {@inheritdoc}
*/
public function collectData(DataInterface $data, Profile $profile)
public function collectData(ContextInterface $context, Profile $profile)
{
if (null !== $this->kernel) {
$startTime = $this->kernel->getStartTime();
} else {
if ($data instanceof RequestData) {
$request = $data->getRequest();
if ($context instanceof RequestContext) {
$request = $context->getRequest();
} else {
$request = Request::createFromGlobals();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Profiler/FileProfilerStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function write(Profile $profile)
'data' => $profile->getCollectors(),
'ip' => $profile->getIp(),
'method' => $profile->getMethod(),
'url' => $profile->getUrl(),
'url' => $profile->getName(),
'time' => $profile->getTime(),
'status_code' => $profile->getStatusCode(),
);
Expand All @@ -169,7 +169,7 @@ public function write(Profile $profile)
$profile->getToken(),
$profile->getIp(),
$profile->getMethod(),
$profile->getUrl(),
$profile->getName(),
$profile->getTime(),
$profile->getParentToken(),
$profile->getStatusCode(),
Expand Down Expand Up @@ -258,7 +258,7 @@ protected function createProfileFromData($token, $data, $parent = null)
$profile = new Profile($token);
$profile->setIp($data['ip']);
$profile->setMethod($data['method']);
$profile->setUrl($data['url']);
$profile->setName($data['url']);
$profile->setTime($data['time']);
$profile->setStatusCode($data['status_code']);
$profile->setCollectors($data['data']);
Expand Down
Loading
0