Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
+25 -17
View File
@@ -54,14 +54,14 @@ class FileProfilerStorage implements ProfilerStorageInterface
$file = $this->getIndexFilename();
if (!file_exists($file)) {
return array();
return [];
}
$file = fopen($file, 'r');
fseek($file, 0, SEEK_END);
fseek($file, 0, \SEEK_END);
$result = array();
while (count($result) < $limit && $line = $this->readLineFromFile($file)) {
$result = [];
while (\count($result) < $limit && $line = $this->readLineFromFile($file)) {
$values = str_getcsv($line);
list($csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent, $csvStatusCode) = $values;
$csvTime = (int) $csvTime;
@@ -78,7 +78,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
continue;
}
$result[$csvToken] = array(
$result[$csvToken] = [
'token' => $csvToken,
'ip' => $csvIp,
'method' => $csvMethod,
@@ -86,7 +86,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
'time' => $csvTime,
'parent' => $csvParent,
'status_code' => $csvStatusCode,
);
];
}
fclose($file);
@@ -118,7 +118,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
public function read($token)
{
if (!$token || !file_exists($file = $this->getFilename($token))) {
return;
return null;
}
return $this->createProfileFromData($token, unserialize(file_get_contents($file)));
@@ -136,24 +136,32 @@ class FileProfilerStorage implements ProfilerStorageInterface
$profileIndexed = is_file($file);
if (!$profileIndexed) {
// Create directory
$dir = dirname($file);
$dir = \dirname($file);
if (!is_dir($dir) && false === @mkdir($dir, 0777, true) && !is_dir($dir)) {
throw new \RuntimeException(sprintf('Unable to create the storage directory (%s).', $dir));
}
}
$profileToken = $profile->getToken();
// when there are errors in sub-requests, the parent and/or children tokens
// may equal the profile token, resulting in infinite loops
$parentToken = $profile->getParentToken() !== $profileToken ? $profile->getParentToken() : null;
$childrenToken = array_filter(array_map(function ($p) use ($profileToken) {
return $profileToken !== $p->getToken() ? $p->getToken() : null;
}, $profile->getChildren()));
// Store profile
$data = array(
'token' => $profile->getToken(),
'parent' => $profile->getParentToken(),
'children' => array_map(function ($p) { return $p->getToken(); }, $profile->getChildren()),
$data = [
'token' => $profileToken,
'parent' => $parentToken,
'children' => $childrenToken,
'data' => $profile->getCollectors(),
'ip' => $profile->getIp(),
'method' => $profile->getMethod(),
'url' => $profile->getUrl(),
'time' => $profile->getTime(),
'status_code' => $profile->getStatusCode(),
);
];
if (false === file_put_contents($file, serialize($data))) {
return false;
@@ -165,7 +173,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
return false;
}
fputcsv($file, array(
fputcsv($file, [
$profile->getToken(),
$profile->getIp(),
$profile->getMethod(),
@@ -173,7 +181,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
$profile->getTime(),
$profile->getParentToken(),
$profile->getStatusCode(),
));
]);
fclose($file);
}
@@ -221,7 +229,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
$position = ftell($file);
if (0 === $position) {
return;
return null;
}
while (true) {
@@ -243,7 +251,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
$position += $upTo;
$line = substr($buffer, $upTo + 1).$line;
fseek($file, max(0, $position), SEEK_SET);
fseek($file, max(0, $position), \SEEK_SET);
if ('' !== $line) {
break;
+16 -21
View File
@@ -25,7 +25,7 @@ class Profile
/**
* @var DataCollectorInterface[]
*/
private $collectors = array();
private $collectors = [];
private $ip;
private $method;
@@ -41,11 +41,9 @@ class Profile
/**
* @var Profile[]
*/
private $children = array();
private $children = [];
/**
* Constructor.
*
* @param string $token The token
*/
public function __construct($token)
@@ -75,10 +73,8 @@ class Profile
/**
* Sets the parent token.
*
* @param Profile $parent
*/
public function setParent(Profile $parent)
public function setParent(self $parent)
{
$this->parent = $parent;
}
@@ -96,7 +92,7 @@ class Profile
/**
* Returns the parent token.
*
* @return null|string The parent token
* @return string|null The parent token
*/
public function getParentToken()
{
@@ -106,7 +102,7 @@ class Profile
/**
* Returns the IP.
*
* @return string The IP
* @return string|null The IP
*/
public function getIp()
{
@@ -126,7 +122,7 @@ class Profile
/**
* Returns the request method.
*
* @return string The request method
* @return string|null The request method
*/
public function getMethod()
{
@@ -141,13 +137,16 @@ class Profile
/**
* Returns the URL.
*
* @return string The URL
* @return string|null The URL
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl($url)
{
$this->url = $url;
@@ -168,7 +167,7 @@ class Profile
}
/**
* @param int The time
* @param int $time The time
*/
public function setTime($time)
{
@@ -184,7 +183,7 @@ class Profile
}
/**
* @return int
* @return int|null
*/
public function getStatusCode()
{
@@ -208,7 +207,7 @@ class Profile
*/
public function setChildren(array $children)
{
$this->children = array();
$this->children = [];
foreach ($children as $child) {
$this->addChild($child);
}
@@ -216,10 +215,8 @@ class Profile
/**
* Adds the child token.
*
* @param Profile $child
*/
public function addChild(Profile $child)
public function addChild(self $child)
{
$this->children[] = $child;
$child->setParent($this);
@@ -260,7 +257,7 @@ class Profile
*/
public function setCollectors(array $collectors)
{
$this->collectors = array();
$this->collectors = [];
foreach ($collectors as $collector) {
$this->addCollector($collector);
}
@@ -268,8 +265,6 @@ class Profile
/**
* Adds a Collector.
*
* @param DataCollectorInterface $collector A DataCollectorInterface instance
*/
public function addCollector(DataCollectorInterface $collector)
{
@@ -290,6 +285,6 @@ class Profile
public function __sleep()
{
return array('token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time', 'statusCode');
return ['token', 'parent', 'children', 'collectors', 'ip', 'method', 'url', 'time', 'statusCode'];
}
}
+35 -37
View File
@@ -11,12 +11,12 @@
namespace Symfony\Component\HttpKernel\Profiler;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
use Psr\Log\LoggerInterface;
/**
* Profiler.
@@ -25,36 +25,25 @@ use Psr\Log\LoggerInterface;
*/
class Profiler
{
/**
* @var ProfilerStorageInterface
*/
private $storage;
/**
* @var DataCollectorInterface[]
*/
private $collectors = array();
private $collectors = [];
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var bool
*/
private $initiallyEnabled = true;
private $enabled = true;
/**
* Constructor.
*
* @param ProfilerStorageInterface $storage A ProfilerStorageInterface instance
* @param LoggerInterface $logger A LoggerInterface instance
* @param bool $enable The initial enabled state
*/
public function __construct(ProfilerStorageInterface $storage, LoggerInterface $logger = null)
public function __construct(ProfilerStorageInterface $storage, LoggerInterface $logger = null, $enable = true)
{
$this->storage = $storage;
$this->logger = $logger;
$this->initiallyEnabled = $this->enabled = (bool) $enable;
}
/**
@@ -76,14 +65,12 @@ class Profiler
/**
* Loads the Profile for the given Response.
*
* @param Response $response A Response instance
*
* @return Profile|false A Profile instance
* @return Profile|null A Profile instance
*/
public function loadProfileFromResponse(Response $response)
{
if (!$token = $response->headers->get('X-Debug-Token')) {
return false;
return null;
}
return $this->loadProfile($token);
@@ -94,7 +81,7 @@ class Profiler
*
* @param string $token A token
*
* @return Profile A Profile instance
* @return Profile|null A Profile instance
*/
public function loadProfile($token)
{
@@ -104,8 +91,6 @@ class Profiler
/**
* Saves a Profile.
*
* @param Profile $profile A Profile instance
*
* @return bool
*/
public function saveProfile(Profile $profile)
@@ -118,7 +103,7 @@ class Profiler
}
if (!($ret = $this->storage->write($profile)) && null !== $this->logger) {
$this->logger->warning('Unable to store the profiler information.', array('configured_storage' => get_class($this->storage)));
$this->logger->warning('Unable to store the profiler information.', ['configured_storage' => \get_class($this->storage)]);
}
return $ret;
@@ -145,7 +130,7 @@ class Profiler
*
* @return array An array of tokens
*
* @see http://php.net/manual/en/datetime.formats.php for the supported date/time formats
* @see https://php.net/datetime.formats for the supported date/time formats
*/
public function find($ip, $url, $limit, $method, $start, $end, $statusCode = null)
{
@@ -155,16 +140,12 @@ class Profiler
/**
* Collects data for the given Response.
*
* @param Request $request A Request instance
* @param Response $response A Response instance
* @param \Exception $exception An exception instance if the request threw one
*
* @return Profile|null A Profile instance or null if the profiler is disabled
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
if (false === $this->enabled) {
return;
return null;
}
$profile = new Profile(substr(hash('sha256', uniqid(mt_rand(), true)), 0, 6));
@@ -190,6 +171,18 @@ class Profiler
return $profile;
}
public function reset()
{
foreach ($this->collectors as $collector) {
if (!method_exists($collector, 'reset')) {
continue;
}
$collector->reset();
}
$this->enabled = $this->initiallyEnabled;
}
/**
* Gets the Collectors associated with this profiler.
*
@@ -205,9 +198,9 @@ class Profiler
*
* @param DataCollectorInterface[] $collectors An array of collectors
*/
public function set(array $collectors = array())
public function set(array $collectors = [])
{
$this->collectors = array();
$this->collectors = [];
foreach ($collectors as $collector) {
$this->add($collector);
}
@@ -215,11 +208,13 @@ class Profiler
/**
* Adds a Collector.
*
* @param DataCollectorInterface $collector A DataCollectorInterface instance
*/
public function add(DataCollectorInterface $collector)
{
if (!method_exists($collector, '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".', DataCollectorInterface::class, \get_class($collector)), \E_USER_DEPRECATED);
}
$this->collectors[$collector->getName()] = $collector;
}
@@ -253,16 +248,19 @@ class Profiler
return $this->collectors[$name];
}
/**
* @return int|null
*/
private function getTimestamp($value)
{
if (null === $value || '' == $value) {
return;
return null;
}
try {
$value = new \DateTime(is_numeric($value) ? '@'.$value : $value);
} catch (\Exception $e) {
return;
return null;
}
return $value->getTimestamp();
@@ -39,15 +39,13 @@ interface ProfilerStorageInterface
*
* @param string $token A token
*
* @return Profile The profile associated with token
* @return Profile|null The profile associated with token
*/
public function read($token);
/**
* Saves a Profile.
*
* @param Profile $profile A Profile instance
*
* @return bool Write operation successful
*/
public function write(Profile $profile);