Augmentation vers version 3.3.0

This commit is contained in:
Gauvain Boiché
2020-03-31 15:31:03 +02:00
parent d926806907
commit a1864c0414
2618 changed files with 406015 additions and 31377 deletions

View File

@@ -26,6 +26,11 @@ class AjaxDataCollector extends DataCollector
// all collecting is done client side
}
public function reset()
{
// all collecting is done client side
}
public function getName()
{
return 'ajax';

View File

@@ -15,11 +15,12 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\VarDumper\Caster\LinkStub;
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class ConfigDataCollector extends DataCollector
class ConfigDataCollector extends DataCollector implements LateDataCollectorInterface
{
/**
* @var KernelInterface
@@ -27,6 +28,7 @@ class ConfigDataCollector extends DataCollector
private $kernel;
private $name;
private $version;
private $hasVarDumper;
/**
* @param string $name The name of the application using the web profiler
@@ -36,6 +38,7 @@ class ConfigDataCollector extends DataCollector
{
$this->name = $name;
$this->version = $version;
$this->hasVarDumper = class_exists(LinkStub::class);
}
/**
@@ -51,7 +54,7 @@ class ConfigDataCollector extends DataCollector
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data = array(
$this->data = [
'app_name' => $this->name,
'app_version' => $this->version,
'token' => $response->headers->get('X-Debug-Token'),
@@ -61,23 +64,46 @@ class ConfigDataCollector extends DataCollector
'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a',
'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a',
'php_version' => PHP_VERSION,
'php_architecture' => PHP_INT_SIZE * 8,
'php_intl_locale' => class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a',
'php_timezone' => date_default_timezone_get(),
'xdebug_enabled' => \extension_loaded('xdebug'),
'eaccel_enabled' => \extension_loaded('eaccelerator') && ini_get('eaccelerator.enable'),
'apc_enabled' => \extension_loaded('apc') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN),
'xcache_enabled' => \extension_loaded('xcache') && filter_var(ini_get('xcache.cacher'), FILTER_VALIDATE_BOOLEAN),
'wincache_enabled' => \extension_loaded('wincache') && filter_var(ini_get('wincache.ocenabled'), FILTER_VALIDATE_BOOLEAN),
'apcu_enabled' => \extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN),
'zend_opcache_enabled' => \extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN),
'bundles' => array(),
'bundles' => [],
'sapi_name' => \PHP_SAPI,
);
];
if (isset($this->kernel)) {
foreach ($this->kernel->getBundles() as $name => $bundle) {
$this->data['bundles'][$name] = $bundle->getPath();
$this->data['bundles'][$name] = $this->hasVarDumper ? new LinkStub($bundle->getPath()) : $bundle->getPath();
}
$this->data['symfony_state'] = $this->determineSymfonyState();
$this->data['symfony_minor_version'] = sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE);
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE);
$this->data['symfony_eom'] = $eom->format('F Y');
$this->data['symfony_eol'] = $eol->format('F Y');
}
if (preg_match('~^(\d+(?:\.\d+)*)(.+)?$~', $this->data['php_version'], $matches) && isset($matches[2])) {
$this->data['php_version'] = $matches[1];
$this->data['php_version_extra'] = $matches[2];
}
}
/**
* {@inheritdoc}
*/
public function reset()
{
$this->data = [];
}
public function lateCollect()
{
$this->data = $this->cloneVar($this->data);
}
public function getApplicationName()
@@ -93,7 +119,7 @@ class ConfigDataCollector extends DataCollector
/**
* Gets the token.
*
* @return string The token
* @return string|null The token
*/
public function getToken()
{
@@ -120,9 +146,37 @@ class ConfigDataCollector extends DataCollector
return $this->data['symfony_state'];
}
public function setCacheVersionInfo($cacheVersionInfo)
/**
* Returns the minor Symfony version used (without patch numbers of extra
* suffix like "RC", "beta", etc.).
*
* @return string
*/
public function getSymfonyMinorVersion()
{
// no-op for BC
return $this->data['symfony_minor_version'];
}
/**
* Returns the human redable date when this Symfony version ends its
* maintenance period.
*
* @return string
*/
public function getSymfonyEom()
{
return $this->data['symfony_eom'];
}
/**
* Returns the human redable date when this Symfony version reaches its
* "end of life" and won't receive bugs or security fixes.
*
* @return string
*/
public function getSymfonyEol()
{
return $this->data['symfony_eol'];
}
/**
@@ -135,6 +189,40 @@ class ConfigDataCollector extends DataCollector
return $this->data['php_version'];
}
/**
* Gets the PHP version extra part.
*
* @return string|null The extra part
*/
public function getPhpVersionExtra()
{
return isset($this->data['php_version_extra']) ? $this->data['php_version_extra'] : null;
}
/**
* @return int The PHP architecture as number of bits (e.g. 32 or 64)
*/
public function getPhpArchitecture()
{
return $this->data['php_architecture'];
}
/**
* @return string
*/
public function getPhpIntlLocale()
{
return $this->data['php_intl_locale'];
}
/**
* @return string
*/
public function getPhpTimezone()
{
return $this->data['php_timezone'];
}
/**
* Gets the application name.
*
@@ -176,23 +264,13 @@ class ConfigDataCollector extends DataCollector
}
/**
* Returns true if EAccelerator is enabled.
* Returns true if APCu is enabled.
*
* @return bool true if EAccelerator is enabled, false otherwise
* @return bool true if APCu is enabled, false otherwise
*/
public function hasEAccelerator()
public function hasApcu()
{
return $this->data['eaccel_enabled'];
}
/**
* Returns true if APC is enabled.
*
* @return bool true if APC is enabled, false otherwise
*/
public function hasApc()
{
return $this->data['apc_enabled'];
return $this->data['apcu_enabled'];
}
/**
@@ -205,36 +283,6 @@ class ConfigDataCollector extends DataCollector
return $this->data['zend_opcache_enabled'];
}
/**
* Returns true if XCache is enabled.
*
* @return bool true if XCache is enabled, false otherwise
*/
public function hasXCache()
{
return $this->data['xcache_enabled'];
}
/**
* Returns true if WinCache is enabled.
*
* @return bool true if WinCache is enabled, false otherwise
*/
public function hasWinCache()
{
return $this->data['wincache_enabled'];
}
/**
* Returns true if any accelerator is enabled.
*
* @return bool true if any accelerator is enabled, false otherwise
*/
public function hasAccelerator()
{
return $this->hasApc() || $this->hasZendOpcache() || $this->hasEAccelerator() || $this->hasXCache() || $this->hasWinCache();
}
public function getBundles()
{
return $this->data['bundles'];
@@ -266,8 +314,8 @@ class ConfigDataCollector extends DataCollector
private function determineSymfonyState()
{
$now = new \DateTime();
$eom = \DateTime::createFromFormat('m/Y', Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
$eol = \DateTime::createFromFormat('m/Y', Kernel::END_OF_LIFE)->modify('last day of this month');
$eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE)->modify('last day of this month');
$eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE)->modify('last day of this month');
if ($now > $eol) {
$versionState = 'eol';

View File

@@ -12,6 +12,11 @@
namespace Symfony\Component\HttpKernel\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
use Symfony\Component\VarDumper\Caster\CutStub;
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Cloner\Stub;
use Symfony\Component\VarDumper\Cloner\VarCloner;
/**
* DataCollector.
@@ -23,21 +28,68 @@ use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
*/
abstract class DataCollector implements DataCollectorInterface, \Serializable
{
protected $data = array();
/**
* @var array|Data
*/
protected $data = [];
/**
* @var ValueExporter
*/
private $valueExporter;
/**
* @var ClonerInterface
*/
private $cloner;
public function serialize()
{
return serialize($this->data);
$trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
$isCalledFromOverridingMethod = isset($trace[1]['function'], $trace[1]['object']) && 'serialize' === $trace[1]['function'] && $this === $trace[1]['object'];
return $isCalledFromOverridingMethod ? $this->data : serialize($this->data);
}
public function unserialize($data)
{
$this->data = unserialize($data);
$this->data = \is_array($data) ? $data : unserialize($data);
}
/**
* Converts the variable into a serializable Data instance.
*
* This array can be displayed in the template using
* the VarDumper component.
*
* @param mixed $var
*
* @return Data
*/
protected function cloneVar($var)
{
if ($var instanceof Data) {
return $var;
}
if (null === $this->cloner) {
if (class_exists(CutStub::class)) {
$this->cloner = new VarCloner();
$this->cloner->setMaxItems(-1);
$this->cloner->addCasters($this->getCasters());
} else {
@trigger_error(sprintf('Using the %s() method without the VarDumper component is deprecated since Symfony 3.2 and won\'t be supported in 4.0. Install symfony/var-dumper version 3.2 or above.', __METHOD__), E_USER_DEPRECATED);
$this->cloner = false;
}
}
if (false === $this->cloner) {
if (null === $this->valueExporter) {
$this->valueExporter = new ValueExporter();
}
return $this->valueExporter->exportValue($var);
}
return $this->cloner->cloneVar($var);
}
/**
@@ -46,13 +98,37 @@ abstract class DataCollector implements DataCollectorInterface, \Serializable
* @param mixed $var A PHP variable
*
* @return string The string representation of the variable
*
* @deprecated since version 3.2, to be removed in 4.0. Use cloneVar() instead.
*/
protected function varToString($var)
{
@trigger_error(sprintf('The %s() method is deprecated since Symfony 3.2 and will be removed in 4.0. Use cloneVar() instead.', __METHOD__), E_USER_DEPRECATED);
if (null === $this->valueExporter) {
$this->valueExporter = new ValueExporter();
}
return $this->valueExporter->exportValue($var);
}
/**
* @return callable[] The casters to add to the cloner
*/
protected function getCasters()
{
return [
'*' => function ($v, array $a, Stub $s, $isNested) {
if (!$v instanceof Stub) {
foreach ($a as $k => $v) {
if (\is_object($v) && !$v instanceof \DateTimeInterface && !$v instanceof Stub) {
$a[$k] = new CutStub($v);
}
}
}
return $a;
},
];
}
}

View File

@@ -18,6 +18,8 @@ use Symfony\Component\HttpFoundation\Response;
* DataCollectorInterface.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @method reset() Resets this data collector to its initial state.
*/
interface DataCollectorInterface
{

View File

@@ -49,12 +49,12 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
$this->dumperIsInjected = null !== $dumper;
// All clones share these properties by reference:
$this->rootRefs = array(
$this->rootRefs = [
&$this->data,
&$this->dataCount,
&$this->isCollected,
&$this->clonesCount,
);
];
}
public function __clone()
@@ -71,12 +71,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
$this->isCollected = false;
}
$trace = DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS;
if (\PHP_VERSION_ID >= 50400) {
$trace = debug_backtrace($trace, 7);
} else {
$trace = debug_backtrace($trace);
}
$trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS, 7);
$file = $trace[0]['file'];
$line = $trace[0]['line'];
@@ -108,7 +103,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
if ($src) {
$src = explode("\n", $src);
$fileExcerpt = array();
$fileExcerpt = [];
for ($i = max($line - 3, 1), $max = min($line + 3, \count($src)); $i <= $max; ++$i) {
$fileExcerpt[] = '<li'.($i === $line ? ' class="selected"' : '').'><code>'.$this->htmlEncode($src[$i - 1]).'</code></li>';
@@ -158,6 +153,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
) {
if ($response->headers->has('Content-Type') && false !== strpos($response->headers->get('Content-Type'), 'html')) {
$this->dumper = new HtmlDumper('php://output', $this->charset);
$this->dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
} else {
$this->dumper = new CliDumper('php://output', $this->charset);
}
@@ -168,6 +164,18 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
}
}
public function reset()
{
if ($this->stopwatch) {
$this->stopwatch->reset();
}
$this->data = [];
$this->dataCount = 0;
$this->isCollected = true;
$this->clonesCount = 0;
$this->clonesIndex = 0;
}
public function serialize()
{
if ($this->clonesCount !== $this->clonesIndex) {
@@ -177,7 +185,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
$this->data[] = $this->fileLinkFormat;
$this->data[] = $this->charset;
$ser = serialize($this->data);
$this->data = array();
$this->data = [];
$this->dataCount = 0;
$this->isCollected = true;
if (!$this->dumperIsInjected) {
@@ -189,7 +197,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
public function unserialize($data)
{
parent::unserialize($data);
$this->data = unserialize($data);
$charset = array_pop($this->data);
$fileLinkFormat = array_pop($this->data);
$this->dataCount = \count($this->data);
@@ -207,18 +215,14 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
if ('html' === $format) {
$dumper = new HtmlDumper($data, $this->charset);
$dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
} else {
throw new \InvalidArgumentException(sprintf('Invalid dump format: %s', $format));
}
$dumps = array();
$dumps = [];
foreach ($this->data as $dump) {
if (method_exists($dump['data'], 'withMaxDepth')) {
$dumper->dump($dump['data']->withMaxDepth($maxDepthLimit)->withMaxItemsPerDepth($maxItemsPerDepth));
} else {
// getLimitedClone is @deprecated, to be removed in 3.0
$dumper->dump($dump['data']->getLimitedClone($maxDepthLimit, $maxItemsPerDepth));
}
$dumper->dump($dump['data']->withMaxDepth($maxDepthLimit)->withMaxItemsPerDepth($maxItemsPerDepth));
$dump['data'] = stream_get_contents($data, -1, 0);
ftruncate($data, 0);
rewind($data);
@@ -246,8 +250,9 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
--$i;
}
if (!\in_array(\PHP_SAPI, array('cli', 'phpdbg'), true) && stripos($h[$i], 'html')) {
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && stripos($h[$i], 'html')) {
$this->dumper = new HtmlDumper('php://output', $this->charset);
$this->dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]);
} else {
$this->dumper = new CliDumper('php://output', $this->charset);
}
@@ -257,25 +262,24 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
$this->doDump($dump['data'], $dump['name'], $dump['file'], $dump['line']);
}
$this->data = array();
$this->data = [];
$this->dataCount = 0;
}
}
private function doDump($data, $name, $file, $line)
{
if (\PHP_VERSION_ID >= 50400 && $this->dumper instanceof CliDumper) {
$contextDumper = function ($name, $file, $line, $fileLinkFormat) {
if ($this->dumper instanceof CliDumper) {
$contextDumper = function ($name, $file, $line, $fmt) {
if ($this instanceof HtmlDumper) {
if ($file) {
$s = $this->style('meta', '%s');
$f = strip_tags($this->style('', $file));
$name = strip_tags($this->style('', $name));
$file = strip_tags($this->style('', $file));
if ($fileLinkFormat) {
$link = strtr(strip_tags($this->style('', $fileLinkFormat)), array('%f' => $file, '%l' => (int) $line));
$name = sprintf('<a href="%s" title="%s">'.$s.'</a>', $link, $file, $name);
if ($fmt && $link = \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $line]) : $fmt->format($file, $line)) {
$name = sprintf('<a href="%s" title="%s">'.$s.'</a>', strip_tags($this->style('', $link)), $f, $name);
} else {
$name = sprintf('<abbr title="%s">'.$s.'</abbr>', $file, $name);
$name = sprintf('<abbr title="%s">'.$s.'</abbr>', $f, $name);
}
} else {
$name = $this->style('meta', $name);

View File

@@ -27,6 +27,9 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
public function __construct(EventDispatcherInterface $dispatcher = null)
{
if ($dispatcher instanceof TraceableEventDispatcherInterface && !method_exists($dispatcher, 'reset')) {
@trigger_error(sprintf('Implementing "%s" without the "reset()" method is deprecated since Symfony 3.4 and will be unsupported in 4.0 for class "%s".', TraceableEventDispatcherInterface::class, \get_class($dispatcher)), E_USER_DEPRECATED);
}
$this->dispatcher = $dispatcher;
}
@@ -35,10 +38,23 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data = array(
'called_listeners' => array(),
'not_called_listeners' => array(),
);
$this->data = [
'called_listeners' => [],
'not_called_listeners' => [],
];
}
public function reset()
{
$this->data = [];
if ($this->dispatcher instanceof TraceableEventDispatcherInterface) {
if (!method_exists($this->dispatcher, 'reset')) {
return; // @deprecated
}
$this->dispatcher->reset();
}
}
public function lateCollect()
@@ -47,6 +63,7 @@ class EventDataCollector extends DataCollector implements LateDataCollectorInter
$this->setCalledListeners($this->dispatcher->getCalledListeners());
$this->setNotCalledListeners($this->dispatcher->getNotCalledListeners());
}
$this->data = $this->cloneVar($this->data);
}
/**

View File

@@ -28,12 +28,20 @@ class ExceptionDataCollector extends DataCollector
public function collect(Request $request, Response $response, \Exception $exception = null)
{
if (null !== $exception) {
$this->data = array(
$this->data = [
'exception' => FlattenException::create($exception),
);
];
}
}
/**
* {@inheritdoc}
*/
public function reset()
{
$this->data = [];
}
/**
* Checks if the exception is not null.
*
@@ -47,7 +55,7 @@ class ExceptionDataCollector extends DataCollector
/**
* Gets the exception.
*
* @return \Exception The exception
* @return \Exception|FlattenException
*/
public function getException()
{

View File

@@ -11,6 +11,7 @@
namespace Symfony\Component\HttpKernel\DataCollector;
use Symfony\Component\Debug\Exception\SilencedErrorContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
@@ -22,31 +23,20 @@ use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
*/
class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface
{
private $errorNames = array(
E_DEPRECATED => 'E_DEPRECATED',
E_USER_DEPRECATED => 'E_USER_DEPRECATED',
E_NOTICE => 'E_NOTICE',
E_USER_NOTICE => 'E_USER_NOTICE',
E_STRICT => 'E_STRICT',
E_WARNING => 'E_WARNING',
E_USER_WARNING => 'E_USER_WARNING',
E_COMPILE_WARNING => 'E_COMPILE_WARNING',
E_CORE_WARNING => 'E_CORE_WARNING',
E_USER_ERROR => 'E_USER_ERROR',
E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
E_COMPILE_ERROR => 'E_COMPILE_ERROR',
E_PARSE => 'E_PARSE',
E_ERROR => 'E_ERROR',
E_CORE_ERROR => 'E_CORE_ERROR',
);
private $logger;
private $containerPathPrefix;
public function __construct($logger = null)
public function __construct($logger = null, $containerPathPrefix = null)
{
if (null !== $logger && $logger instanceof DebugLoggerInterface) {
if (!method_exists($logger, 'clear')) {
@trigger_error(sprintf('Implementing "%s" without the "clear()" method is deprecated since Symfony 3.4 and will be unsupported in 4.0 for class "%s".', DebugLoggerInterface::class, \get_class($logger)), E_USER_DEPRECATED);
}
$this->logger = $logger;
}
$this->containerPathPrefix = $containerPathPrefix;
}
/**
@@ -60,27 +50,36 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
/**
* {@inheritdoc}
*/
public function lateCollect()
public function reset()
{
if (null !== $this->logger) {
$this->data = $this->computeErrorsCount();
$this->data['logs'] = $this->sanitizeLogs($this->logger->getLogs());
if ($this->logger && method_exists($this->logger, 'clear')) {
$this->logger->clear();
}
$this->data = [];
}
/**
* Gets the logs.
*
* @return array An array of logs
* {@inheritdoc}
*/
public function lateCollect()
{
if (null !== $this->logger) {
$containerDeprecationLogs = $this->getContainerDeprecationLogs();
$this->data = $this->computeErrorsCount($containerDeprecationLogs);
$this->data['compiler_logs'] = $this->getContainerCompilerLogs();
$this->data['logs'] = $this->sanitizeLogs(array_merge($this->logger->getLogs(), $containerDeprecationLogs));
$this->data = $this->cloneVar($this->data);
}
}
public function getLogs()
{
return isset($this->data['logs']) ? $this->data['logs'] : array();
return isset($this->data['logs']) ? $this->data['logs'] : [];
}
public function getPriorities()
{
return isset($this->data['priorities']) ? $this->data['priorities'] : array();
return isset($this->data['priorities']) ? $this->data['priorities'] : [];
}
public function countErrors()
@@ -93,11 +92,21 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0;
}
public function countWarnings()
{
return isset($this->data['warning_count']) ? $this->data['warning_count'] : 0;
}
public function countScreams()
{
return isset($this->data['scream_count']) ? $this->data['scream_count'] : 0;
}
public function getCompilerLogs()
{
return isset($this->data['compiler_logs']) ? $this->data['compiler_logs'] : [];
}
/**
* {@inheritdoc}
*/
@@ -106,106 +115,161 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
return 'logger';
}
private function getContainerDeprecationLogs()
{
if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Deprecations.log')) {
return [];
}
if ('' === $logContent = trim(file_get_contents($file))) {
return [];
}
$bootTime = filemtime($file);
$logs = [];
foreach (unserialize($logContent) as $log) {
$log['context'] = ['exception' => new SilencedErrorContext($log['type'], $log['file'], $log['line'], $log['trace'], $log['count'])];
$log['timestamp'] = $bootTime;
$log['priority'] = 100;
$log['priorityName'] = 'DEBUG';
$log['channel'] = '-';
$log['scream'] = false;
unset($log['type'], $log['file'], $log['line'], $log['trace'], $log['trace'], $log['count']);
$logs[] = $log;
}
return $logs;
}
private function getContainerCompilerLogs()
{
if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Compiler.log')) {
return [];
}
$logs = [];
foreach (file($file, FILE_IGNORE_NEW_LINES) as $log) {
$log = explode(': ', $log, 2);
if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) {
$log = ['Unknown Compiler Pass', implode(': ', $log)];
}
$logs[$log[0]][] = ['message' => $log[1]];
}
return $logs;
}
private function sanitizeLogs($logs)
{
$errorContextById = array();
$sanitizedLogs = array();
$sanitizedLogs = [];
$silencedLogs = [];
foreach ($logs as $log) {
$context = $this->sanitizeContext($log['context']);
if (!$this->isSilencedOrDeprecationErrorLog($log)) {
$sanitizedLogs[] = $log;
if (isset($context['type'], $context['file'], $context['line'], $context['level'])) {
$errorId = md5("{$context['type']}/{$context['line']}/{$context['file']}\x00{$log['message']}", true);
$silenced = !($context['type'] & $context['level']);
if (isset($this->errorNames[$context['type']])) {
$context = array_merge(array('name' => $this->errorNames[$context['type']]), $context);
}
continue;
}
if (isset($errorContextById[$errorId])) {
if (isset($errorContextById[$errorId]['errorCount'])) {
++$errorContextById[$errorId]['errorCount'];
} else {
$errorContextById[$errorId]['errorCount'] = 2;
}
if (!$silenced && isset($errorContextById[$errorId]['scream'])) {
unset($errorContextById[$errorId]['scream']);
$errorContextById[$errorId]['level'] = $context['level'];
}
$message = $log['message'];
$exception = $log['context']['exception'];
if ($exception instanceof SilencedErrorContext) {
if (isset($silencedLogs[$h = spl_object_hash($exception)])) {
continue;
}
$silencedLogs[$h] = true;
$errorContextById[$errorId] = &$context;
if ($silenced) {
$context['scream'] = true;
if (!isset($sanitizedLogs[$message])) {
$sanitizedLogs[$message] = $log + [
'errorCount' => 0,
'scream' => true,
];
}
$sanitizedLogs[$message]['errorCount'] += $exception->count;
$log['context'] = &$context;
unset($context);
continue;
}
$errorId = md5("{$exception->getSeverity()}/{$exception->getLine()}/{$exception->getFile()}\0{$message}", true);
if (isset($sanitizedLogs[$errorId])) {
++$sanitizedLogs[$errorId]['errorCount'];
} else {
$log['context'] = $context;
}
$log += [
'errorCount' => 1,
'scream' => false,
];
$sanitizedLogs[] = $log;
$sanitizedLogs[$errorId] = $log;
}
}
return $sanitizedLogs;
return array_values($sanitizedLogs);
}
private function sanitizeContext($context)
private function isSilencedOrDeprecationErrorLog(array $log)
{
if (\is_array($context)) {
foreach ($context as $key => $value) {
$context[$key] = $this->sanitizeContext($value);
}
return $context;
if (!isset($log['context']['exception'])) {
return false;
}
if (\is_resource($context)) {
return sprintf('Resource(%s)', get_resource_type($context));
$exception = $log['context']['exception'];
if ($exception instanceof SilencedErrorContext) {
return true;
}
if (\is_object($context)) {
if ($context instanceof \Exception) {
return sprintf('Exception(%s): %s', \get_class($context), $context->getMessage());
}
return sprintf('Object(%s)', \get_class($context));
if ($exception instanceof \ErrorException && \in_array($exception->getSeverity(), [E_DEPRECATED, E_USER_DEPRECATED], true)) {
return true;
}
return $context;
return false;
}
private function computeErrorsCount()
private function computeErrorsCount(array $containerDeprecationLogs)
{
$count = array(
$silencedLogs = [];
$count = [
'error_count' => $this->logger->countErrors(),
'deprecation_count' => 0,
'warning_count' => 0,
'scream_count' => 0,
'priorities' => array(),
);
'priorities' => [],
];
foreach ($this->logger->getLogs() as $log) {
if (isset($count['priorities'][$log['priority']])) {
++$count['priorities'][$log['priority']]['count'];
} else {
$count['priorities'][$log['priority']] = array(
$count['priorities'][$log['priority']] = [
'count' => 1,
'name' => $log['priorityName'],
);
];
}
if ('WARNING' === $log['priorityName']) {
++$count['warning_count'];
}
if (isset($log['context']['type'], $log['context']['level'])) {
if (E_DEPRECATED === $log['context']['type'] || E_USER_DEPRECATED === $log['context']['type']) {
if ($this->isSilencedOrDeprecationErrorLog($log)) {
$exception = $log['context']['exception'];
if ($exception instanceof SilencedErrorContext) {
if (isset($silencedLogs[$h = spl_object_hash($exception)])) {
continue;
}
$silencedLogs[$h] = true;
$count['scream_count'] += $exception->count;
} else {
++$count['deprecation_count'];
} elseif (!($log['context']['type'] & $log['context']['level'])) {
++$count['scream_count'];
}
}
}
foreach ($containerDeprecationLogs as $deprecationLog) {
$count['deprecation_count'] += $deprecationLog['context']['exception']->count;
}
ksort($count['priorities']);
return $count;

View File

@@ -23,10 +23,7 @@ class MemoryDataCollector extends DataCollector implements LateDataCollectorInte
{
public function __construct()
{
$this->data = array(
'memory' => 0,
'memory_limit' => $this->convertToBytes(ini_get('memory_limit')),
);
$this->reset();
}
/**
@@ -37,6 +34,17 @@ class MemoryDataCollector extends DataCollector implements LateDataCollectorInte
$this->updateMemoryUsage();
}
/**
* {@inheritdoc}
*/
public function reset()
{
$this->data = [
'memory' => 0,
'memory_limit' => $this->convertToBytes(ini_get('memory_limit')),
];
}
/**
* {@inheritdoc}
*/

View File

@@ -12,16 +12,18 @@
namespace Symfony\Component\HttpKernel\DataCollector;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class RequestDataCollector extends DataCollector implements EventSubscriberInterface
class RequestDataCollector extends DataCollector implements EventSubscriberInterface, LateDataCollectorInterface
{
protected $controllers;
@@ -35,28 +37,18 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$responseHeaders = $response->headers->all();
foreach ($response->headers->getCookies() as $cookie) {
$responseHeaders['set-cookie'][] = (string) $cookie;
}
// attributes are serialized and as they can be anything, they need to be converted to strings.
$attributes = array();
$attributes = [];
$route = '';
foreach ($request->attributes->all() as $key => $value) {
if ('_route' === $key && \is_object($value)) {
$attributes[$key] = $this->varToString($value->getPath());
} elseif ('_route_params' === $key) {
// we need to keep route params as an array (see getRouteParams())
foreach ($value as $k => $v) {
$value[$k] = $this->varToString($v);
}
$attributes[$key] = $value;
if ('_route' === $key) {
$route = \is_object($value) ? $value->getPath() : $value;
$attributes[$key] = $route;
} else {
$attributes[$key] = $this->varToString($value);
$attributes[$key] = $value;
}
}
$content = null;
try {
$content = $request->getContent();
} catch (\LogicException $e) {
@@ -64,9 +56,9 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
$content = false;
}
$sessionMetadata = array();
$sessionAttributes = array();
$flashes = array();
$sessionMetadata = [];
$sessionAttributes = [];
$flashes = [];
if ($request->hasSession()) {
$session = $request->getSession();
if ($session->isStarted()) {
@@ -80,7 +72,13 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
$statusCode = $response->getStatusCode();
$this->data = array(
$responseCookies = [];
foreach ($response->headers->getCookies() as $cookie) {
$responseCookies[$cookie->getName()] = $cookie;
}
$this->data = [
'method' => $request->getMethod(),
'format' => $request->getRequestFormat(),
'content' => $content,
'content_type' => $response->headers->get('Content-Type', 'text/html'),
@@ -92,14 +90,16 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
'request_server' => $request->server->all(),
'request_cookies' => $request->cookies->all(),
'request_attributes' => $attributes,
'response_headers' => $responseHeaders,
'route' => $route,
'response_headers' => $response->headers->all(),
'response_cookies' => $responseCookies,
'session_metadata' => $sessionMetadata,
'session_attributes' => $sessionAttributes,
'flashes' => $flashes,
'path_info' => $request->getPathInfo(),
'controller' => 'n/a',
'locale' => $request->getLocale(),
);
];
if (isset($this->data['request_headers']['php-auth-pw'])) {
$this->data['request_headers']['php-auth-pw'] = '******';
@@ -118,56 +118,52 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
continue;
}
if ('request_headers' === $key || 'response_headers' === $key) {
$value = array_map(function ($v) { return isset($v[0]) && !isset($v[1]) ? $v[0] : $v; }, $value);
}
if ('request_server' !== $key && 'request_cookies' !== $key) {
$this->data[$key] = $value;
$this->data[$key] = array_map(function ($v) { return isset($v[0]) && !isset($v[1]) ? $v[0] : $v; }, $value);
}
}
if (isset($this->controllers[$request])) {
$controller = $this->controllers[$request];
if (\is_array($controller)) {
try {
$r = new \ReflectionMethod($controller[0], $controller[1]);
$this->data['controller'] = array(
'class' => \is_object($controller[0]) ? \get_class($controller[0]) : $controller[0],
'method' => $controller[1],
'file' => $r->getFileName(),
'line' => $r->getStartLine(),
);
} catch (\ReflectionException $e) {
if (\is_callable($controller)) {
// using __call or __callStatic
$this->data['controller'] = array(
'class' => \is_object($controller[0]) ? \get_class($controller[0]) : $controller[0],
'method' => $controller[1],
'file' => 'n/a',
'line' => 'n/a',
);
}
}
} elseif ($controller instanceof \Closure) {
$r = new \ReflectionFunction($controller);
$this->data['controller'] = array(
'class' => $r->getName(),
'method' => null,
'file' => $r->getFileName(),
'line' => $r->getStartLine(),
);
} elseif (\is_object($controller)) {
$r = new \ReflectionClass($controller);
$this->data['controller'] = array(
'class' => $r->getName(),
'method' => null,
'file' => $r->getFileName(),
'line' => $r->getStartLine(),
);
} else {
$this->data['controller'] = (string) $controller ?: 'n/a';
}
$this->data['controller'] = $this->parseController($this->controllers[$request]);
unset($this->controllers[$request]);
}
if ($request->attributes->has('_redirected') && $redirectCookie = $request->cookies->get('sf_redirect')) {
$this->data['redirect'] = json_decode($redirectCookie, true);
$response->headers->clearCookie('sf_redirect');
}
if ($response->isRedirect()) {
$response->headers->setCookie(new Cookie(
'sf_redirect',
json_encode([
'token' => $response->headers->get('x-debug-token'),
'route' => $request->attributes->get('_route', 'n/a'),
'method' => $request->getMethod(),
'controller' => $this->parseController($request->attributes->get('_controller')),
'status_code' => $statusCode,
'status_text' => Response::$statusTexts[(int) $statusCode],
])
));
}
$this->data['identifier'] = $this->data['route'] ?: (\is_array($this->data['controller']) ? $this->data['controller']['class'].'::'.$this->data['controller']['method'].'()' : $this->data['controller']);
}
public function lateCollect()
{
$this->data = $this->cloneVar($this->data);
}
public function reset()
{
$this->data = [];
$this->controllers = new \SplObjectStorage();
}
public function getMethod()
{
return $this->data['method'];
}
public function getPathInfo()
@@ -177,52 +173,57 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
public function getRequestRequest()
{
return new ParameterBag($this->data['request_request']);
return new ParameterBag($this->data['request_request']->getValue());
}
public function getRequestQuery()
{
return new ParameterBag($this->data['request_query']);
return new ParameterBag($this->data['request_query']->getValue());
}
public function getRequestHeaders()
{
return new ParameterBag($this->data['request_headers']);
return new ParameterBag($this->data['request_headers']->getValue());
}
public function getRequestServer()
public function getRequestServer($raw = false)
{
return new ParameterBag($this->data['request_server']);
return new ParameterBag($this->data['request_server']->getValue($raw));
}
public function getRequestCookies()
public function getRequestCookies($raw = false)
{
return new ParameterBag($this->data['request_cookies']);
return new ParameterBag($this->data['request_cookies']->getValue($raw));
}
public function getRequestAttributes()
{
return new ParameterBag($this->data['request_attributes']);
return new ParameterBag($this->data['request_attributes']->getValue());
}
public function getResponseHeaders()
{
return new ParameterBag($this->data['response_headers']);
return new ParameterBag($this->data['response_headers']->getValue());
}
public function getResponseCookies()
{
return new ParameterBag($this->data['response_cookies']->getValue());
}
public function getSessionMetadata()
{
return $this->data['session_metadata'];
return $this->data['session_metadata']->getValue();
}
public function getSessionAttributes()
{
return $this->data['session_attributes'];
return $this->data['session_attributes']->getValue();
}
public function getFlashes()
{
return $this->data['flashes'];
return $this->data['flashes']->getValue();
}
public function getContent()
@@ -264,7 +265,12 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
*/
public function getRoute()
{
return isset($this->data['request_attributes']['_route']) ? $this->data['request_attributes']['_route'] : '';
return $this->data['route'];
}
public function getIdentifier()
{
return $this->data['identifier'];
}
/**
@@ -276,27 +282,53 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
*/
public function getRouteParams()
{
return isset($this->data['request_attributes']['_route_params']) ? $this->data['request_attributes']['_route_params'] : array();
return isset($this->data['request_attributes']['_route_params']) ? $this->data['request_attributes']['_route_params']->getValue() : [];
}
/**
* Gets the controller.
* Gets the parsed controller.
*
* @return string The controller as a string
* @return array|string The controller as a string or array of data
* with keys 'class', 'method', 'file' and 'line'
*/
public function getController()
{
return $this->data['controller'];
}
/**
* Gets the previous request attributes.
*
* @return array|bool A legacy array of data from the previous redirection response
* or false otherwise
*/
public function getRedirect()
{
return isset($this->data['redirect']) ? $this->data['redirect'] : false;
}
public function onKernelController(FilterControllerEvent $event)
{
$this->controllers[$event->getRequest()] = $event->getController();
}
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
return;
}
if ($event->getRequest()->cookies->has('sf_redirect')) {
$event->getRequest()->attributes->set('_redirected', true);
}
}
public static function getSubscribedEvents()
{
return array(KernelEvents::CONTROLLER => 'onKernelController');
return [
KernelEvents::CONTROLLER => 'onKernelController',
KernelEvents::RESPONSE => 'onKernelResponse',
];
}
/**
@@ -306,4 +338,78 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
{
return 'request';
}
/**
* Parse a controller.
*
* @param mixed $controller The controller to parse
*
* @return array|string An array of controller data or a simple string
*/
protected function parseController($controller)
{
if (\is_string($controller) && false !== strpos($controller, '::')) {
$controller = explode('::', $controller);
}
if (\is_array($controller)) {
try {
$r = new \ReflectionMethod($controller[0], $controller[1]);
return [
'class' => \is_object($controller[0]) ? \get_class($controller[0]) : $controller[0],
'method' => $controller[1],
'file' => $r->getFileName(),
'line' => $r->getStartLine(),
];
} catch (\ReflectionException $e) {
if (\is_callable($controller)) {
// using __call or __callStatic
return [
'class' => \is_object($controller[0]) ? \get_class($controller[0]) : $controller[0],
'method' => $controller[1],
'file' => 'n/a',
'line' => 'n/a',
];
}
}
}
if ($controller instanceof \Closure) {
$r = new \ReflectionFunction($controller);
$controller = [
'class' => $r->getName(),
'method' => null,
'file' => $r->getFileName(),
'line' => $r->getStartLine(),
];
if (false !== strpos($r->name, '{closure}')) {
return $controller;
}
$controller['method'] = $r->name;
if ($class = $r->getClosureScopeClass()) {
$controller['class'] = $class->name;
} else {
return $r->name;
}
return $controller;
}
if (\is_object($controller)) {
$r = new \ReflectionClass($controller);
return [
'class' => $r->getName(),
'method' => null,
'file' => $r->getFileName(),
'line' => $r->getStartLine(),
];
}
return \is_string($controller) ? $controller : 'n/a';
}
}

View File

@@ -23,17 +23,14 @@ use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
*/
class RouterDataCollector extends DataCollector
{
/**
* @var \SplObjectStorage
*/
protected $controllers;
public function __construct()
{
$this->controllers = new \SplObjectStorage();
$this->data = array(
'redirect' => false,
'url' => null,
'route' => null,
);
$this->reset();
}
/**
@@ -53,6 +50,17 @@ class RouterDataCollector extends DataCollector
unset($this->controllers[$request]);
}
public function reset()
{
$this->controllers = new \SplObjectStorage();
$this->data = [
'redirect' => false,
'url' => null,
'route' => null,
];
}
protected function guessRoute(Request $request, $controller)
{
return 'n/a';

View File

@@ -14,10 +14,10 @@ namespace Symfony\Component\HttpKernel\DataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent;
/**
* TimeDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class TimeDataCollector extends DataCollector implements LateDataCollectorInterface
@@ -25,7 +25,7 @@ class TimeDataCollector extends DataCollector implements LateDataCollectorInterf
protected $kernel;
protected $stopwatch;
public function __construct(KernelInterface $kernel = null, $stopwatch = null)
public function __construct(KernelInterface $kernel = null, Stopwatch $stopwatch = null)
{
$this->kernel = $kernel;
$this->stopwatch = $stopwatch;
@@ -39,14 +39,27 @@ class TimeDataCollector extends DataCollector implements LateDataCollectorInterf
if (null !== $this->kernel) {
$startTime = $this->kernel->getStartTime();
} else {
$startTime = $request->server->get('REQUEST_TIME_FLOAT', $request->server->get('REQUEST_TIME'));
$startTime = $request->server->get('REQUEST_TIME_FLOAT');
}
$this->data = array(
$this->data = [
'token' => $response->headers->get('X-Debug-Token'),
'start_time' => $startTime * 1000,
'events' => array(),
);
'events' => [],
'stopwatch_installed' => class_exists(Stopwatch::class, false),
];
}
/**
* {@inheritdoc}
*/
public function reset()
{
$this->data = [];
if (null !== $this->stopwatch) {
$this->stopwatch->reset();
}
}
/**
@@ -63,7 +76,7 @@ class TimeDataCollector extends DataCollector implements LateDataCollectorInterf
/**
* Sets the request events.
*
* @param array $events The request events
* @param StopwatchEvent[] $events The request events
*/
public function setEvents(array $events)
{
@@ -77,7 +90,7 @@ class TimeDataCollector extends DataCollector implements LateDataCollectorInterf
/**
* Gets the request events.
*
* @return array The request events
* @return StopwatchEvent[] The request events
*/
public function getEvents()
{
@@ -119,13 +132,21 @@ class TimeDataCollector extends DataCollector implements LateDataCollectorInterf
/**
* Gets the request time.
*
* @return int The time
* @return float
*/
public function getStartTime()
{
return $this->data['start_time'];
}
/**
* @return bool whether or not the stopwatch component is installed
*/
public function isStopwatchInstalled()
{
return $this->data['stopwatch_installed'];
}
/**
* {@inheritdoc}
*/

View File

@@ -11,8 +11,12 @@
namespace Symfony\Component\HttpKernel\DataCollector\Util;
@trigger_error('The '.__NAMESPACE__.'\ValueExporter class is deprecated since Symfony 3.2 and will be removed in 4.0. Use the VarDumper component instead.', E_USER_DEPRECATED);
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 3.2, to be removed in 4.0. Use the VarDumper component instead.
*/
class ValueExporter
{
@@ -32,7 +36,7 @@ class ValueExporter
}
if (\is_object($value)) {
if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
if ($value instanceof \DateTimeInterface) {
return sprintf('Object(%s) - %s', \get_class($value), $value->format(\DateTime::ATOM));
}
@@ -46,7 +50,7 @@ class ValueExporter
$indent = str_repeat(' ', $depth);
$a = array();
$a = [];
foreach ($value as $k => $v) {
if (\is_array($v)) {
$deep = true;
@@ -58,7 +62,13 @@ class ValueExporter
return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), str_repeat(' ', $depth - 1));
}
return sprintf('[%s]', implode(', ', $a));
$s = sprintf('[%s]', implode(', ', $a));
if (80 > \strlen($s)) {
return $s;
}
return sprintf("[\n%s%s\n]", $indent, implode(sprintf(",\n%s", $indent), $a));
}
if (\is_resource($value)) {