Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel] Remove deprecated code paths #50858

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

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ HttpKernel
----------

* Add argument `$reflector` to `ArgumentResolverInterface::getArguments()` and `ArgumentMetadataFactoryInterface::createArgumentMetadata()`
* Remove `ArgumentValueResolverInterface`, use `ValueResolverInterface` instead
* Remove `StreamedResponseListener`
* Remove `AbstractSurrogate::$phpEscapeMap`
* Remove `HttpKernelInterface::MASTER_REQUEST`
* Remove `terminate_on_cache_hit` option from `HttpCache`

Lock
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\BackedEnumValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\UidValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
Expand Down Expand Up @@ -596,8 +595,6 @@ public function load(array $configs, ContainerBuilder $container): void
->addTag('container.service_locator');
$container->registerForAutoconfiguration(ServiceSubscriberInterface::class)
->addTag('container.service_subscriber');
$container->registerForAutoconfiguration(ArgumentValueResolverInterface::class)
->addTag('controller.argument_value_resolver');
$container->registerForAutoconfiguration(ValueResolverInterface::class)
->addTag('controller.argument_value_resolver');
$container->registerForAutoconfiguration(AbstractController::class)
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ CHANGELOG
---

* Add argument `$reflector` to `ArgumentResolverInterface::getArguments()` and `ArgumentMetadataFactoryInterface::createArgumentMetadata()`
* Remove `ArgumentValueResolverInterface`, use `ValueResolverInterface` instead
* Remove `StreamedResponseListener`
* Remove `AbstractSurrogate::$phpEscapeMap`
* Remove `HttpKernelInterface::MASTER_REQUEST`
* Remove `terminate_on_cache_hit` option from `HttpCache`

6.4
---
Expand Down
12 changes: 2 additions & 10 deletions src/Symfony/Component/HttpKernel/Controller/ArgumentResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestAttributeValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\RequestValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\SessionValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\TraceableValueResolver;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\VariadicValueResolver;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactoryInterface;
Expand All @@ -37,7 +36,7 @@ final class ArgumentResolver implements ArgumentResolverInterface
private ?ContainerInterface $namedResolvers;

/**
* @param iterable<mixed, ArgumentValueResolverInterface|ValueResolverInterface> $argumentValueResolvers
* @param iterable<mixed, ValueResolverInterface> $argumentValueResolvers
*/
public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, iterable $argumentValueResolvers = [], ContainerInterface $namedResolvers = null)
{
Expand Down Expand Up @@ -79,9 +78,6 @@ public function getArguments(Request $request, callable $controller, \Reflection
}

foreach ($argumentValueResolvers as $name => $resolver) {
if ((!$resolver instanceof ValueResolverInterface || $resolver instanceof TraceableValueResolver) && !$resolver->supports($request, $metadata)) {
continue;
}
if (isset($disabledResolvers[\is_int($name) ? $resolver::class : $name])) {
continue;
}
Expand All @@ -100,10 +96,6 @@ public function getArguments(Request $request, callable $controller, \Reflection
// continue to the next controller argument
continue 2;
}

if (!$resolver instanceof ValueResolverInterface) {
throw new \InvalidArgumentException(sprintf('"%s::resolve()" must yield at least one value.', get_debug_type($resolver)));
}
}

throw new \RuntimeException(sprintf('Controller "%s" requires that you provide a value for the "$%s" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or there is a non-optional argument after this one.', $this->getPrettyName($controller), $metadata->getName()));
Expand All @@ -113,7 +105,7 @@ public function getArguments(Request $request, callable $controller, \Reflection
}

/**
* @return iterable<int, ArgumentValueResolverInterface>
* @return iterable<int, ValueResolverInterface>
*/
public static function getDefaultArgumentValueResolvers(): iterable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\HttpKernel\Controller\ArgumentResolver;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Expand All @@ -23,30 +22,8 @@
*
* @author Maxime Steinhausser <[email protected]>
*/
final class BackedEnumValueResolver implements ArgumentValueResolverInterface, ValueResolverInterface
final class BackedEnumValueResolver implements ValueResolverInterface
{
/**
* @deprecated since Symfony 6.2, use resolve() instead
*/
public function supports(Request $request, ArgumentMetadata $argument): bool
{
@trigger_deprecation('symfony/http-kernel', '6.2', 'The "%s()" method is deprecated, use "resolve()" instead.', __METHOD__);

if (!is_subclass_of($argument->getType(), \BackedEnum::class)) {
return false;
}

if ($argument->isVariadic()) {
// only target route path parameters, which cannot be variadic.
return false;
}

// do not support if no value can be resolved at all
// letting the \Symfony\Component\HttpKernel\Controller\ArgumentResolver\DefaultValueResolver be used
// or \Symfony\Component\HttpKernel\Controller\ArgumentResolver fail with a meaningful error.
return $request->attributes->has($argument->getName());
}

public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
if (!is_subclass_of($argument->getType(), \BackedEnum::class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Psr\Clock\ClockInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Attribute\MapDateTime;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Expand All @@ -25,23 +24,13 @@
* @author Benjamin Eberlei <[email protected]>
* @author Tim Goudriaan <[email protected]>
*/
final class DateTimeValueResolver implements ArgumentValueResolverInterface, ValueResolverInterface
final class DateTimeValueResolver implements ValueResolverInterface
{
public function __construct(
private readonly ?ClockInterface $clock = null,
) {
}

/**
* @deprecated since Symfony 6.2, use resolve() instead
*/
public function supports(Request $request, ArgumentMetadata $argument): bool
{
@trigger_deprecation('symfony/http-kernel', '6.2', 'The "%s()" method is deprecated, use "resolve()" instead.', __METHOD__);

return is_a($argument->getType(), \DateTimeInterface::class, true) && $request->attributes->has($argument->getName());
}

public function resolve(Request $request, ArgumentMetadata $argument): array
{
if (!is_a($argument->getType(), \DateTimeInterface::class, true) || !$request->attributes->has($argument->getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\HttpKernel\Controller\ArgumentResolver;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

Expand All @@ -21,18 +20,8 @@
*
* @author Iltar van der Berg <[email protected]>
*/
final class DefaultValueResolver implements ArgumentValueResolverInterface, ValueResolverInterface
final class DefaultValueResolver implements ValueResolverInterface
{
/**
* @deprecated since Symfony 6.2, use resolve() instead
*/
public function supports(Request $request, ArgumentMetadata $argument): bool
{
@trigger_deprecation('symfony/http-kernel', '6.2', 'The "%s()" method is deprecated, use "resolve()" instead.', __METHOD__);

return $argument->hasDefaultValue() || (null !== $argument->getType() && $argument->isNullable() && !$argument->isVariadic());
}

public function resolve(Request $request, ArgumentMetadata $argument): array
{
if ($argument->hasDefaultValue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

Expand All @@ -23,39 +22,11 @@
*
* @author Simeon Kolev <[email protected]>
*/
final class NotTaggedControllerValueResolver implements ArgumentValueResolverInterface, ValueResolverInterface
final class NotTaggedControllerValueResolver implements ValueResolverInterface
{
private ContainerInterface $container;

public function __construct(ContainerInterface $container)
{
$this->container = $container;
}

/**
* @deprecated since Symfony 6.2, use resolve() instead
*/
public function supports(Request $request, ArgumentMetadata $argument): bool
{
@trigger_deprecation('symfony/http-kernel', '6.2', 'The "%s()" method is deprecated, use "resolve()" instead.', __METHOD__);

$controller = $request->attributes->get('_controller');

if (\is_array($controller) && \is_callable($controller, true) && \is_string($controller[0])) {
$controller = $controller[0].'::'.$controller[1];
} elseif (!\is_string($controller) || '' === $controller) {
return false;
}

if ('\\' === $controller[0]) {
$controller = ltrim($controller, '\\');
}

if (!$this->container->has($controller) && false !== $i = strrpos($controller, ':')) {
$controller = substr($controller, 0, $i).strtolower(substr($controller, $i));
}

return false === $this->container->has($controller);
public function __construct(
private ContainerInterface $container,
) {
}

public function resolve(Request $request, ArgumentMetadata $argument): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\HttpKernel\Controller\ArgumentResolver;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

Expand All @@ -21,18 +20,8 @@
*
* @author Iltar van der Berg <[email protected]>
*/
final class RequestAttributeValueResolver implements ArgumentValueResolverInterface, ValueResolverInterface
final class RequestAttributeValueResolver implements ValueResolverInterface
{
/**
* @deprecated since Symfony 6.2, use resolve() instead
*/
public function supports(Request $request, ArgumentMetadata $argument): bool
{
@trigger_deprecation('symfony/http-kernel', '6.2', 'The "%s()" method is deprecated, use "resolve()" instead.', __METHOD__);

return !$argument->isVariadic() && $request->attributes->has($argument->getName());
}

public function resolve(Request $request, ArgumentMetadata $argument): array
{
return !$argument->isVariadic() && $request->attributes->has($argument->getName()) ? [$request->attributes->get($argument->getName())] : [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\HttpKernel\Controller\ArgumentResolver;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

Expand All @@ -21,18 +20,8 @@
*
* @author Iltar van der Berg <[email protected]>
*/
final class RequestValueResolver implements ArgumentValueResolverInterface, ValueResolverInterface
final class RequestValueResolver implements ValueResolverInterface
{
/**
* @deprecated since Symfony 6.2, use resolve() instead
*/
public function supports(Request $request, ArgumentMetadata $argument): bool
{
@trigger_deprecation('symfony/http-kernel', '6.2', 'The "%s()" method is deprecated, use "resolve()" instead.', __METHOD__);

return Request::class === $argument->getType() || is_subclass_of($argument->getType(), Request::class);
}

public function resolve(Request $request, ArgumentMetadata $argument): array
{
return Request::class === $argument->getType() || is_subclass_of($argument->getType(), Request::class) ? [$request] : [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

Expand All @@ -23,7 +22,7 @@
*
* @author Nicolas Grekas <[email protected]>
*/
final class ServiceValueResolver implements ArgumentValueResolverInterface, ValueResolverInterface
final class ServiceValueResolver implements ValueResolverInterface
{
private ContainerInterface $container;

Expand All @@ -32,32 +31,6 @@ public function __construct(ContainerInterface $container)
$this->container = $container;
}

/**
* @deprecated since Symfony 6.2, use resolve() instead
*/
public function supports(Request $request, ArgumentMetadata $argument): bool
{
@trigger_deprecation('symfony/http-kernel', '6.2', 'The "%s()" method is deprecated, use "resolve()" instead.', __METHOD__);

$controller = $request->attributes->get('_controller');

if (\is_array($controller) && \is_callable($controller, true) && \is_string($controller[0])) {
$controller = $controller[0].'::'.$controller[1];
} elseif (!\is_string($controller) || '' === $controller) {
return false;
}

if ('\\' === $controller[0]) {
$controller = ltrim($controller, '\\');
}

if (!$this->container->has($controller) && false !== $i = strrpos($controller, ':')) {
$controller = substr($controller, 0, $i).strtolower(substr($controller, $i));
}

return $this->container->has($controller) && $this->container->get($controller)->has($argument->getName());
}

public function resolve(Request $request, ArgumentMetadata $argument): array
{
$controller = $request->attributes->get('_controller');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;

Expand All @@ -22,27 +21,8 @@
*
* @author Iltar van der Berg <[email protected]>
*/
final class SessionValueResolver implements ArgumentValueResolverInterface, ValueResolverInterface
final class SessionValueResolver implements ValueResolverInterface
{
/**
* @deprecated since Symfony 6.2, use resolve() instead
*/
public function supports(Request $request, ArgumentMetadata $argument): bool
{
@trigger_deprecation('symfony/http-kernel', '6.2', 'The "%s()" method is deprecated, use "resolve()" instead.', __METHOD__);

if (!$request->hasSession()) {
return false;
}

$type = $argument->getType();
if (SessionInterface::class !== $type && !is_subclass_of($type, SessionInterface::class)) {
return false;
}

return $request->getSession() instanceof $type;
}

public function resolve(Request $request, ArgumentMetadata $argument): array
{
if (!$request->hasSession()) {
Expand Down
Loading