upgrade to laravel 8.0

This commit is contained in:
Attila Kerekes
2022-11-13 17:05:03 +01:00
committed by Attila Jozsef Kerekes
parent 43f894b58d
commit 27f58c0866
3895 changed files with 150576 additions and 124482 deletions

View File

@@ -60,8 +60,8 @@ class ConfigDataCollector extends DataCollector implements LateDataCollectorInte
'php_intl_locale' => class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a',
'php_timezone' => date_default_timezone_get(),
'xdebug_enabled' => \extension_loaded('xdebug'),
'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),
'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' => [],
'sapi_name' => \PHP_SAPI,
];

View File

@@ -49,9 +49,10 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
*/
public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, $dumper = null)
{
$fileLinkFormat = $fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
$this->stopwatch = $stopwatch;
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
$this->charset = $charset ?: ini_get('php.output_encoding') ?: ini_get('default_charset') ?: 'UTF-8';
$this->fileLinkFormat = $fileLinkFormat instanceof FileLinkFormatter && false === $fileLinkFormat->format('', 0) ? false : $fileLinkFormat;
$this->charset = $charset ?: \ini_get('php.output_encoding') ?: \ini_get('default_charset') ?: 'UTF-8';
$this->requestStack = $requestStack;
$this->dumper = $dumper;
@@ -232,7 +233,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
$h = headers_list();
$i = \count($h);
array_unshift($h, 'Content-Type: '.ini_get('default_mimetype'));
array_unshift($h, 'Content-Type: '.\ini_get('default_mimetype'));
while (0 !== stripos($h[$i], 'Content-Type:')) {
--$i;
}

View File

@@ -144,7 +144,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
$allChannels = [];
foreach ($this->getProcessedLogs() as $log) {
if ('' === trim($log['channel'])) {
if ('' === trim($log['channel'] ?? '')) {
continue;
}

View File

@@ -41,7 +41,7 @@ class MemoryDataCollector extends DataCollector implements LateDataCollectorInte
{
$this->data = [
'memory' => 0,
'memory_limit' => $this->convertToBytes(ini_get('memory_limit')),
'memory_limit' => $this->convertToBytes(\ini_get('memory_limit')),
];
}
@@ -100,8 +100,11 @@ class MemoryDataCollector extends DataCollector implements LateDataCollectorInte
switch (substr($memoryLimit, -1)) {
case 't': $max *= 1024;
// no break
case 'g': $max *= 1024;
// no break
case 'm': $max *= 1024;
// no break
case 'k': $max *= 1024;
}

View File

@@ -110,7 +110,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
'session_metadata' => $sessionMetadata,
'session_attributes' => $sessionAttributes,
'session_usages' => array_values($this->sessionUsages),
'stateless_check' => $this->requestStack && $this->requestStack->getMainRequest()->attributes->get('_stateless', false),
'stateless_check' => $this->requestStack && ($mainRequest = $this->requestStack->getMainRequest()) && $mainRequest->attributes->get('_stateless', false),
'flashes' => $flashes,
'path_info' => $request->getPathInfo(),
'controller' => 'n/a',

View File

@@ -40,12 +40,12 @@ class FileLinkFormatter
private $urlFormat;
/**
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
* @param string|array|null $fileLinkFormat
* @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand
*/
public function __construct(string $fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null)
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null)
{
$fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
if ($fileLinkFormat && !\is_array($fileLinkFormat)) {
if (!\is_array($fileLinkFormat) && $fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')) {
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f);
$fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE);
}

View File

@@ -158,6 +158,11 @@ abstract class AbstractSessionListener implements EventSubscriberInterface, Rese
$isSessionEmpty = $session->isEmpty() && empty($_SESSION); // checking $_SESSION to keep compatibility with native sessions
if ($requestSessionCookieId && $isSessionEmpty) {
// PHP internally sets the session cookie value to "deleted" when setcookie() is called with empty string $value argument
// which happens in \Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler::destroy
// when the session gets invalidated (for example on logout) so we must handle this case here too
// otherwise we would send two Set-Cookie headers back with the response
SessionUtils::popSessionCookie($sessionName, 'deleted');
$response->headers->clearCookie(
$sessionName,
$sessionCookiePath,

View File

@@ -57,7 +57,7 @@ class DebugHandlersListener implements EventSubscriberInterface
$deprecationLogger = $fileLinkFormat;
}
$handler = set_exception_handler('var_dump');
$handler = set_exception_handler('is_int');
$this->earlyHandler = \is_array($handler) ? $handler[0] : null;
restore_exception_handler();
@@ -83,7 +83,7 @@ class DebugHandlersListener implements EventSubscriberInterface
}
$this->firstCall = $this->hasTerminatedWithException = false;
$handler = set_exception_handler('var_dump');
$handler = set_exception_handler('is_int');
$handler = \is_array($handler) ? $handler[0] : null;
restore_exception_handler();

View File

@@ -33,8 +33,14 @@ class ErrorListener implements EventSubscriberInterface
protected $controller;
protected $logger;
protected $debug;
/**
* @var array<class-string, array{log_level: string|null, status_code: int<100,599>|null}>
*/
protected $exceptionsMapping;
/**
* @param array<class-string, array{log_level: string|null, status_code: int<100,599>|null}> $exceptionsMapping
*/
public function __construct($controller, LoggerInterface $logger = null, bool $debug = false, array $exceptionsMapping = [])
{
$this->controller = $controller;

View File

@@ -89,9 +89,11 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
private function containsNonScalars(array $values): bool
{
foreach ($values as $value) {
if (\is_array($value)) {
return $this->containsNonScalars($value);
} elseif (!is_scalar($value) && null !== $value) {
if (\is_scalar($value) || null === $value) {
continue;
}
if (!\is_array($value) || $this->containsNonScalars($value)) {
return true;
}
}

View File

@@ -85,7 +85,7 @@ final class FragmentUriGenerator implements FragmentUriGeneratorInterface
foreach ($values as $key => $value) {
if (\is_array($value)) {
$this->checkNonScalar($value);
} elseif (!is_scalar($value) && null !== $value) {
} elseif (!\is_scalar($value) && null !== $value) {
throw new \LogicException(sprintf('Controller attributes cannot contain non-scalar/non-null values (value for key "%s" is not a scalar or null).', $key));
}
}

View File

@@ -95,7 +95,7 @@ abstract class AbstractSurrogate implements SurrogateInterface
try {
$response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
if (!$response->isSuccessful()) {
if (!$response->isSuccessful() && Response::HTTP_NOT_MODIFIED !== $response->getStatusCode()) {
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $subRequest->getUri(), $response->getStatusCode()));
}

View File

@@ -70,6 +70,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
{
$request->headers->set('X-Php-Ob-Level', (string) ob_get_level());
$this->requestStack->push($request);
try {
return $this->handleRaw($request, $type);
} catch (\Exception $e) {
@@ -83,6 +84,8 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
}
return $this->handleThrowable($e, $request, $type);
} finally {
$this->requestStack->pop();
}
}
@@ -103,7 +106,17 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
throw $exception;
}
$response = $this->handleThrowable($exception, $request, self::MAIN_REQUEST);
if ($pop = $request !== $this->requestStack->getMainRequest()) {
$this->requestStack->push($request);
}
try {
$response = $this->handleThrowable($exception, $request, self::MAIN_REQUEST);
} finally {
if ($pop) {
$this->requestStack->pop();
}
}
$response->sendHeaders();
$response->sendContent();
@@ -121,8 +134,6 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
*/
private function handleRaw(Request $request, int $type = self::MAIN_REQUEST): Response
{
$this->requestStack->push($request);
// request
$event = new RequestEvent($this, $request, $type);
$this->dispatcher->dispatch($event, KernelEvents::REQUEST);
@@ -199,7 +210,6 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
private function finishRequest(Request $request, int $type)
{
$this->dispatcher->dispatch(new FinishRequestEvent($this, $request, $type), KernelEvents::FINISH_REQUEST);
$this->requestStack->pop();
}
/**

View File

@@ -78,11 +78,11 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl
*/
private static $freshCache = [];
public const VERSION = '5.4.10';
public const VERSION_ID = 50410;
public const VERSION = '5.4.15';
public const VERSION_ID = 50415;
public const MAJOR_VERSION = 5;
public const MINOR_VERSION = 4;
public const RELEASE_VERSION = 10;
public const RELEASE_VERSION = 15;
public const EXTRA_VERSION = '';
public const END_OF_MAINTENANCE = '11/2024';

View File

@@ -49,10 +49,14 @@ class Logger extends AbstractLogger
if (isset($_ENV['SHELL_VERBOSITY']) || isset($_SERVER['SHELL_VERBOSITY'])) {
switch ((int) ($_ENV['SHELL_VERBOSITY'] ?? $_SERVER['SHELL_VERBOSITY'])) {
case -1: $minLevel = LogLevel::ERROR; break;
case 1: $minLevel = LogLevel::NOTICE; break;
case 2: $minLevel = LogLevel::INFO; break;
case 3: $minLevel = LogLevel::DEBUG; break;
case -1: $minLevel = LogLevel::ERROR;
break;
case 1: $minLevel = LogLevel::NOTICE;
break;
case 2: $minLevel = LogLevel::INFO;
break;
case 3: $minLevel = LogLevel::DEBUG;
break;
}
}
}
@@ -85,7 +89,7 @@ class Logger extends AbstractLogger
$formatter = $this->formatter;
if ($this->handle) {
@fwrite($this->handle, $formatter($level, $message, $context));
@fwrite($this->handle, $formatter($level, $message, $context).\PHP_EOL);
} else {
error_log($formatter($level, $message, $context, false));
}
@@ -96,7 +100,7 @@ class Logger extends AbstractLogger
if (str_contains($message, '{')) {
$replacements = [];
foreach ($context as $key => $val) {
if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) {
if (null === $val || \is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) {
$replacements["{{$key}}"] = $val;
} elseif ($val instanceof \DateTimeInterface) {
$replacements["{{$key}}"] = $val->format(\DateTime::RFC3339);
@@ -110,7 +114,7 @@ class Logger extends AbstractLogger
$message = strtr($message, $replacements);
}
$log = sprintf('[%s] %s', $level, $message).\PHP_EOL;
$log = sprintf('[%s] %s', $level, $message);
if ($prefixDate) {
$log = date(\DateTime::RFC3339).' '.$log;
}

View File

@@ -115,19 +115,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
*/
public function read(string $token): ?Profile
{
if (!$token || !file_exists($file = $this->getFilename($token))) {
return null;
}
if (\function_exists('gzcompress')) {
$file = 'compress.zlib://'.$file;
}
if (!$data = unserialize(file_get_contents($file))) {
return null;
}
return $this->createProfileFromData($token, $data);
return $this->doRead($token);
}
/**
@@ -169,14 +157,13 @@ class FileProfilerStorage implements ProfilerStorageInterface
'status_code' => $profile->getStatusCode(),
];
$context = stream_context_create();
$data = serialize($data);
if (\function_exists('gzcompress')) {
$file = 'compress.zlib://'.$file;
stream_context_set_option($context, 'zlib', 'level', 3);
if (\function_exists('gzencode')) {
$data = gzencode($data, 3);
}
if (false === file_put_contents($file, serialize($data), 0, $context)) {
if (false === file_put_contents($file, $data, \LOCK_EX)) {
return false;
}
@@ -291,21 +278,34 @@ class FileProfilerStorage implements ProfilerStorageInterface
}
foreach ($data['children'] as $token) {
if (!$token || !file_exists($file = $this->getFilename($token))) {
continue;
if (null !== $childProfile = $this->doRead($token, $profile)) {
$profile->addChild($childProfile);
}
if (\function_exists('gzcompress')) {
$file = 'compress.zlib://'.$file;
}
if (!$childData = unserialize(file_get_contents($file))) {
continue;
}
$profile->addChild($this->createProfileFromData($token, $childData, $profile));
}
return $profile;
}
private function doRead($token, Profile $profile = null): ?Profile
{
if (!$token || !file_exists($file = $this->getFilename($token))) {
return null;
}
$h = fopen($file, 'r');
flock($h, \LOCK_SH);
$data = stream_get_contents($h);
flock($h, \LOCK_UN);
fclose($h);
if (\function_exists('gzdecode')) {
$data = @gzdecode($data) ?: $data;
}
if (!$data = unserialize($data)) {
return null;
}
return $this->createProfileFromData($token, $data, $profile);
}
}