N°8834 - Add compatibility with PHP 8.4 (#819)

* N°8834 - Add compatibility with PHP 8.4

* Rollback of scssphp/scssphp version upgrade due to compilation error
This commit is contained in:
Lenaick
2026-02-26 10:36:32 +01:00
committed by GitHub
parent d4821b7edc
commit fc967c06ce
961 changed files with 12298 additions and 7130 deletions

View File

@@ -75,7 +75,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
protected function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null
{
if (!$this->container->has('parameter_bag')) {
throw new ServiceNotFoundException('parameter_bag.', null, null, [], sprintf('The "%s::getParameter()" method is missing a parameter bag to work properly. Did you forget to register your controller as a service subscriber? This can be fixed either by using autoconfiguration or by manually wiring a "parameter_bag" in the service locator passed to the controller.', static::class));
throw new ServiceNotFoundException('parameter_bag.', null, null, [], \sprintf('The "%s::getParameter()" method is missing a parameter bag to work properly. Did you forget to register your controller as a service subscriber? This can be fixed either by using autoconfiguration or by manually wiring a "parameter_bag" in the service locator passed to the controller.', static::class));
}
return $this->container->get('parameter_bag')->get($name);
@@ -157,13 +157,17 @@ abstract class AbstractController implements ServiceSubscriberInterface
return new JsonResponse($json, $status, $headers, true);
}
if (null === $data) {
return new JsonResponse('null', $status, $headers, true);
}
return new JsonResponse($data, $status, $headers);
}
/**
* Returns a BinaryFileResponse object with original or customized file name and disposition header.
*/
protected function file(\SplFileInfo|string $file, string $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT): BinaryFileResponse
protected function file(\SplFileInfo|string $file, ?string $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT): BinaryFileResponse
{
$response = new BinaryFileResponse($file);
$response->setContentDisposition($disposition, $fileName ?? $response->getFile()->getFilename());
@@ -248,7 +252,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
* If an invalid form is found in the list of parameters, a 422 status code is returned.
* Forms found in parameters are auto-cast to form views.
*/
protected function render(string $view, array $parameters = [], Response $response = null): Response
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
{
return $this->doRender($view, null, $parameters, $response, __FUNCTION__);
}
@@ -259,7 +263,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
* If an invalid form is found in the list of parameters, a 422 status code is returned.
* Forms found in parameters are auto-cast to form views.
*/
protected function renderBlock(string $view, string $block, array $parameters = [], Response $response = null): Response
protected function renderBlock(string $view, string $block, array $parameters = [], ?Response $response = null): Response
{
return $this->doRender($view, $block, $parameters, $response, __FUNCTION__);
}
@@ -271,7 +275,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
*
* @deprecated since Symfony 6.2, use render() instead
*/
protected function renderForm(string $view, array $parameters = [], Response $response = null): Response
protected function renderForm(string $view, array $parameters = [], ?Response $response = null): Response
{
trigger_deprecation('symfony/framework-bundle', '6.2', 'The "%s::renderForm()" method is deprecated, use "render()" instead.', get_debug_type($this));
@@ -281,7 +285,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
/**
* Streams a view.
*/
protected function stream(string $view, array $parameters = [], StreamedResponse $response = null): StreamedResponse
protected function stream(string $view, array $parameters = [], ?StreamedResponse $response = null): StreamedResponse
{
if (!$this->container->has('twig')) {
throw new \LogicException('You cannot use the "stream" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".');
@@ -309,7 +313,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
*
* throw $this->createNotFoundException('Page not found!');
*/
protected function createNotFoundException(string $message = 'Not Found', \Throwable $previous = null): NotFoundHttpException
protected function createNotFoundException(string $message = 'Not Found', ?\Throwable $previous = null): NotFoundHttpException
{
return new NotFoundHttpException($message, $previous);
}
@@ -323,7 +327,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
*
* @throws \LogicException If the Security component is not available
*/
protected function createAccessDeniedException(string $message = 'Access Denied.', \Throwable $previous = null): AccessDeniedException
protected function createAccessDeniedException(string $message = 'Access Denied.', ?\Throwable $previous = null): AccessDeniedException
{
if (!class_exists(AccessDeniedException::class)) {
throw new \LogicException('You cannot use the "createAccessDeniedException" method if the Security component is not available. Try running "composer require symfony/security-bundle".');
@@ -406,7 +410,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
/**
* @param LinkInterface[] $links
*/
protected function sendEarlyHints(iterable $links = [], Response $response = null): Response
protected function sendEarlyHints(iterable $links = [], ?Response $response = null): Response
{
if (!$this->container->has('web_link.http_header_serializer')) {
throw new \LogicException('You cannot use the "sendEarlyHints" method if the WebLink component is not available. Try running "composer require symfony/web-link".');
@@ -432,7 +436,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
private function doRenderView(string $view, ?string $block, array $parameters, string $method): string
{
if (!$this->container->has('twig')) {
throw new \LogicException(sprintf('You cannot use the "%s" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".', $method));
throw new \LogicException(\sprintf('You cannot use the "%s" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".', $method));
}
foreach ($parameters as $k => $v) {

View File

@@ -31,7 +31,7 @@ class ControllerResolver extends ContainerControllerResolver
}
if ($controller instanceof AbstractController) {
if (null === $previousContainer = $controller->setContainer($this->container)) {
throw new \LogicException(sprintf('"%s" has no container set, did you forget to define it as a service subscriber?', $class));
throw new \LogicException(\sprintf('"%s" has no container set, did you forget to define it as a service subscriber?', $class));
} else {
$controller->setContainer($previousContainer);
}

View File

@@ -31,7 +31,7 @@ class RedirectController
private ?int $httpPort;
private ?int $httpsPort;
public function __construct(UrlGeneratorInterface $router = null, int $httpPort = null, int $httpsPort = null)
public function __construct(?UrlGeneratorInterface $router = null, ?int $httpPort = null, ?int $httpsPort = null)
{
$this->router = $router;
$this->httpPort = $httpPort;
@@ -107,9 +107,9 @@ class RedirectController
*
* @throws HttpException In case the path is empty
*/
public function urlRedirectAction(Request $request, string $path, bool $permanent = false, string $scheme = null, int $httpPort = null, int $httpsPort = null, bool $keepRequestMethod = false): Response
public function urlRedirectAction(Request $request, string $path, bool $permanent = false, ?string $scheme = null, ?int $httpPort = null, ?int $httpsPort = null, bool $keepRequestMethod = false): Response
{
if ('' == $path) {
if ('' === $path) {
throw new HttpException($permanent ? 410 : 404);
}
@@ -119,13 +119,17 @@ class RedirectController
$statusCode = $permanent ? 301 : 302;
}
$scheme ??= $request->getScheme();
if (str_starts_with($path, '//')) {
$path = $scheme.':'.$path;
}
// redirect if the path is a full URL
if (parse_url($path, \PHP_URL_SCHEME)) {
return new RedirectResponse($path, $statusCode);
}
$scheme ??= $request->getScheme();
if ($qs = $request->server->get('QUERY_STRING') ?: $request->getQueryString()) {
if (!str_contains($path, '?')) {
$qs = '?'.$qs;
@@ -172,7 +176,7 @@ class RedirectController
if (\array_key_exists('route', $p)) {
if (\array_key_exists('path', $p)) {
throw new \RuntimeException(sprintf('Ambiguous redirection settings, use the "path" or "route" parameter, not both: "%s" and "%s" found respectively in "%s" routing configuration.', $p['path'], $p['route'], $request->attributes->get('_route')));
throw new \RuntimeException(\sprintf('Ambiguous redirection settings, use the "path" or "route" parameter, not both: "%s" and "%s" found respectively in "%s" routing configuration.', $p['path'], $p['route'], $request->attributes->get('_route')));
}
return $this->redirectAction($request, $p['route'], $p['permanent'] ?? false, $p['ignoreAttributes'] ?? false, $p['keepRequestMethod'] ?? false, $p['keepQueryParams'] ?? false);
@@ -182,6 +186,6 @@ class RedirectController
return $this->urlRedirectAction($request, $p['path'], $p['permanent'] ?? false, $p['scheme'] ?? null, $p['httpPort'] ?? null, $p['httpsPort'] ?? null, $p['keepRequestMethod'] ?? false);
}
throw new \RuntimeException(sprintf('The parameter "path" or "route" is required to configure the redirect action in "%s" routing configuration.', $request->attributes->get('_route')));
throw new \RuntimeException(\sprintf('The parameter "path" or "route" is required to configure the redirect action in "%s" routing configuration.', $request->attributes->get('_route')));
}
}

View File

@@ -25,7 +25,7 @@ class TemplateController
{
private ?Environment $twig;
public function __construct(Environment $twig = null)
public function __construct(?Environment $twig = null)
{
$this->twig = $twig;
}
@@ -40,7 +40,7 @@ class TemplateController
* @param array $context The context (arguments) of the template
* @param int $statusCode The HTTP status code to return with the response (200 "OK" by default)
*/
public function templateAction(string $template, int $maxAge = null, int $sharedAge = null, bool $private = null, array $context = [], int $statusCode = 200): Response
public function templateAction(string $template, ?int $maxAge = null, ?int $sharedAge = null, ?bool $private = null, array $context = [], int $statusCode = 200): Response
{
if (null === $this->twig) {
throw new \LogicException('You cannot use the TemplateController if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".');
@@ -68,7 +68,7 @@ class TemplateController
/**
* @param int $statusCode The HTTP status code (200 "OK" by default)
*/
public function __invoke(string $template, int $maxAge = null, int $sharedAge = null, bool $private = null, array $context = [], int $statusCode = 200): Response
public function __invoke(string $template, ?int $maxAge = null, ?int $sharedAge = null, ?bool $private = null, array $context = [], int $statusCode = 200): Response
{
return $this->templateAction($template, $maxAge, $sharedAge, $private, $context, $statusCode);
}