Skip to content

[HttpKernel] remove deprecated features #41963

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, 2021
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
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/Test/TestContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function has(string $id): bool
/**
* {@inheritdoc}
*/
public function get(string $id, int $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1): ?object
public function get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE): ?object
{
return $this->getPrivateContainer()->has($id) ? $this->getPrivateContainer()->get($id) : $this->getPublicContainer()->get($id, $invalidBehavior);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/DependencyInjection/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private function make(string $id, int $invalidBehavior)
unset($this->loading[$id]);
}

if (/* self::EXCEPTION_ON_INVALID_REFERENCE */ 1 === $invalidBehavior) {
if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
if (!$id) {
throw new ServiceNotFoundException($id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,7 @@ private function getServiceCall(string $id, Reference $reference = null): string
return 'null';
}
if (null !== $reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE < $reference->getInvalidBehavior()) {
$code = sprintf('$this->get(%s, /* ContainerInterface::NULL_ON_INVALID_REFERENCE */ %d)', $this->doExport($id), ContainerInterface::NULL_ON_INVALID_REFERENCE);
$code = sprintf('$this->get(%s, ContainerInterface::NULL_ON_INVALID_REFERENCE)', $this->doExport($id));
} else {
$code = sprintf('$this->get(%s)', $this->doExport($id));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,8 @@
<xsd:complexType name="deprecated">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<!-- In Symfony 6, make these attributes required -->
<xsd:attribute name="package" type="xsd:string" />
<xsd:attribute name="version" type="xsd:string" />
<xsd:attribute name="package" type="xsd:string" use="required" />
<xsd:attribute name="version" type="xsd:string" use="required" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -466,16 +466,6 @@ public function testDeprecatedAliases()
$this->assertSame($message, $container->getAlias('alias_for_foobar')->getDeprecation('alias_for_foobar')['message']);
}

public function testDeprecatedAliaseWithoutPackageAndVersion()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/^Missing attribute "package" at node "deprecated" in "[^"]*".$/');
$loader->load('deprecated_alias_definitions_without_package_and_version.xml');
}

public function testConvertDomElementToArray()
{
$doc = new \DOMDocument('1.0');
Expand Down
23 changes: 0 additions & 23 deletions src/Symfony/Component/HttpKernel/Attribute/ArgumentInterface.php

This file was deleted.

9 changes: 9 additions & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
CHANGELOG
=========

6.0
---

* Remove `ArgumentInterface`
* Remove `ArgumentMetadata::getAttribute()`, use `getAttributes()` instead
* Remove support for returning a `ContainerBuilder` from `KernelInterface::registerContainerConfiguration()`
* Remove `KernelEvent::isMasterRequest()`, use `isMainRequest()` instead
* Remove support for `service:action` syntax to reference controllers, use `serviceOrFqcn::method` instead

5.4
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ public function __construct(ContainerInterface $container, LoggerInterface $logg
parent::__construct($logger);
}

protected function createController(string $controller)
{
if (1 === substr_count($controller, ':')) {
$controller = str_replace(':', '::', $controller);
trigger_deprecation('symfony/http-kernel', '5.1', 'Referencing controllers with a single colon is deprecated. Use "%s" instead.', $controller);
}

return parent::createController($controller);
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,8 @@ public function getController(Request $request)
try {
$controller[0] = $this->instantiateController($controller[0]);
} catch (\Error | \LogicException $e) {
try {
// We cannot just check is_callable but have to use reflection because a non-static method
// can still be called statically in PHP but we don't want that. This is deprecated in PHP 7, so we
// could simplify this with PHP 8.
if ((new \ReflectionMethod($controller[0], $controller[1]))->isStatic()) {
return $controller;
}
} catch (\ReflectionException $reflectionException) {
throw $e;
if (\is_callable($controller)) {
return $controller;
}

throw $e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Symfony\Component\HttpKernel\ControllerMetadata;

use Symfony\Component\HttpKernel\Attribute\ArgumentInterface;

/**
* Responsible for storing metadata of an argument.
*
Expand Down Expand Up @@ -114,20 +112,6 @@ public function getDefaultValue()
return $this->defaultValue;
}

/**
* Returns the attribute (if any) that was set on the argument.
*/
public function getAttribute(): ?ArgumentInterface
{
trigger_deprecation('symfony/http-kernel', '5.3', 'Method "%s()" is deprecated, use "getAttributes()" instead.', __METHOD__);

if (!$this->attributes) {
return null;
}

return $this->attributes[0] instanceof ArgumentInterface ? $this->attributes[0] : null;
}

/**
* @return object[]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,25 @@ class ControllerArgumentValueResolverPass implements CompilerPassInterface
{
use PriorityTaggedServiceTrait;

private $argumentResolverService;
private $argumentValueResolverTag;
private $traceableResolverStopwatch;

public function __construct(string $argumentResolverService = 'argument_resolver', string $argumentValueResolverTag = 'controller.argument_value_resolver', string $traceableResolverStopwatch = 'debug.stopwatch')
{
if (0 < \func_num_args()) {
trigger_deprecation('symfony/http-kernel', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
}

$this->argumentResolverService = $argumentResolverService;
$this->argumentValueResolverTag = $argumentValueResolverTag;
$this->traceableResolverStopwatch = $traceableResolverStopwatch;
}

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition($this->argumentResolverService)) {
if (!$container->hasDefinition('argument_resolver')) {
return;
}

$resolvers = $this->findAndSortTaggedServices($this->argumentValueResolverTag, $container);
$resolvers = $this->findAndSortTaggedServices('controller.argument_value_resolver', $container);

if ($container->getParameter('kernel.debug') && class_exists(Stopwatch::class) && $container->has($this->traceableResolverStopwatch)) {
if ($container->getParameter('kernel.debug') && class_exists(Stopwatch::class) && $container->has('debug.stopwatch')) {
foreach ($resolvers as $resolverReference) {
$id = (string) $resolverReference;
$container->register("debug.$id", TraceableValueResolver::class)
->setDecoratedService($id)
->setArguments([new Reference("debug.$id.inner"), new Reference($this->traceableResolverStopwatch)]);
->setArguments([new Reference("debug.$id.inner"), new Reference('debug.stopwatch')]);
}
}

$container
->getDefinition($this->argumentResolverService)
->getDefinition('argument_resolver')
->replaceArgument(1, new IteratorArgument($resolvers))
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,15 @@
*/
class FragmentRendererPass implements CompilerPassInterface
{
private $handlerService;
private $rendererTag;

public function __construct(string $handlerService = 'fragment.handler', string $rendererTag = 'kernel.fragment_renderer')
{
if (0 < \func_num_args()) {
trigger_deprecation('symfony/http-kernel', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
}

$this->handlerService = $handlerService;
$this->rendererTag = $rendererTag;
}

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition($this->handlerService)) {
if (!$container->hasDefinition('fragment.handler')) {
return;
}

$definition = $container->getDefinition($this->handlerService);
$definition = $container->getDefinition('fragment.handler');
$renderers = [];
foreach ($container->findTaggedServiceIds($this->rendererTag, true) as $id => $tags) {
foreach ($container->findTaggedServiceIds('kernel.fragment_renderer', true) as $id => $tags) {
$def = $container->getDefinition($id);
$class = $container->getParameterBag()->resolveValue($def->getClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,9 @@
*/
class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface
{
private $resolverServiceId;
private $controllerTag;
private $controllerLocator;
private $notTaggedControllerResolverServiceId;

public function __construct(string $resolverServiceId = 'argument_resolver.service', string $controllerTag = 'controller.service_arguments', string $controllerLocator = 'argument_resolver.controller_locator', string $notTaggedControllerResolverServiceId = 'argument_resolver.not_tagged_controller')
{
if (0 < \func_num_args()) {
trigger_deprecation('symfony/http-kernel', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
}

$this->resolverServiceId = $resolverServiceId;
$this->controllerTag = $controllerTag;
$this->controllerLocator = $controllerLocator;
$this->notTaggedControllerResolverServiceId = $notTaggedControllerResolverServiceId;
}

public function process(ContainerBuilder $container)
{
if (false === $container->hasDefinition($this->resolverServiceId) && false === $container->hasDefinition($this->notTaggedControllerResolverServiceId)) {
if (!$container->hasDefinition('argument_resolver.service') && !$container->hasDefinition('argument_resolver.not_tagged_controller')) {
return;
}

Expand All @@ -66,7 +49,7 @@ public function process(ContainerBuilder $container)
}
}

foreach ($container->findTaggedServiceIds($this->controllerTag, true) as $id => $tags) {
foreach ($container->findTaggedServiceIds('controller.service_arguments', true) as $id => $tags) {
$def = $container->getDefinition($id);
$def->setPublic(true);
$class = $def->getClass();
Expand Down Expand Up @@ -106,11 +89,11 @@ public function process(ContainerBuilder $container)
}
foreach (['action', 'argument', 'id'] as $k) {
if (!isset($attributes[$k][0])) {
throw new InvalidArgumentException(sprintf('Missing "%s" attribute on tag "%s" %s for service "%s".', $k, $this->controllerTag, json_encode($attributes, \JSON_UNESCAPED_UNICODE), $id));
throw new InvalidArgumentException(sprintf('Missing "%s" attribute on tag "controller.service_arguments" %s for service "%s".', $k, json_encode($attributes, \JSON_UNESCAPED_UNICODE), $id));
}
}
if (!isset($methods[$action = strtolower($attributes['action'])])) {
throw new InvalidArgumentException(sprintf('Invalid "action" attribute on tag "%s" for service "%s": no public "%s()" method found on class "%s".', $this->controllerTag, $id, $attributes['action'], $class));
throw new InvalidArgumentException(sprintf('Invalid "action" attribute on tag "controller.service_arguments" for service "%s": no public "%s()" method found on class "%s".', $id, $attributes['action'], $class));
}
[$r, $parameters] = $methods[$action];
$found = false;
Expand All @@ -126,7 +109,7 @@ public function process(ContainerBuilder $container)
}

if (!$found) {
throw new InvalidArgumentException(sprintf('Invalid "%s" tag for service "%s": method "%s()" has no "%s" argument on class "%s".', $this->controllerTag, $id, $r->name, $attributes['argument'], $class));
throw new InvalidArgumentException(sprintf('Invalid "controller.service_arguments" tag for service "%s": method "%s()" has no "%s" argument on class "%s".', $id, $r->name, $attributes['argument'], $class));
}
}

Expand All @@ -145,7 +128,7 @@ public function process(ContainerBuilder $container)
if ('?' !== $target[0]) {
$invalidBehavior = ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE;
} elseif ('' === $target = (string) substr($target, 1)) {
throw new InvalidArgumentException(sprintf('A "%s" tag must have non-empty "id" attributes for service "%s".', $this->controllerTag, $id));
throw new InvalidArgumentException(sprintf('A "controller.service_arguments" tag must have non-empty "id" attributes for service "%s".', $id));
} elseif ($p->allowsNull() && !$p->isOptional()) {
$invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
}
Expand Down Expand Up @@ -205,16 +188,16 @@ public function process(ContainerBuilder $container)

$controllerLocatorRef = ServiceLocatorTagPass::register($container, $controllers);

if ($container->hasDefinition($this->resolverServiceId)) {
$container->getDefinition($this->resolverServiceId)
if ($container->hasDefinition('argument_resolver.service')) {
$container->getDefinition('argument_resolver.service')
->replaceArgument(0, $controllerLocatorRef);
}

if ($container->hasDefinition($this->notTaggedControllerResolverServiceId)) {
$container->getDefinition($this->notTaggedControllerResolverServiceId)
if ($container->hasDefinition('argument_resolver.not_tagged_controller')) {
$container->getDefinition('argument_resolver.not_tagged_controller')
->replaceArgument(0, $controllerLocatorRef);
}

$container->setAlias($this->controllerLocator, (string) $controllerLocatorRef);
$container->setAlias('argument_resolver.controller_locator', (string) $controllerLocatorRef);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,26 @@
*/
class RegisterLocaleAwareServicesPass implements CompilerPassInterface
{
private $listenerServiceId;
private $localeAwareTag;

public function __construct(string $listenerServiceId = 'locale_aware_listener', string $localeAwareTag = 'kernel.locale_aware')
{
if (0 < \func_num_args()) {
trigger_deprecation('symfony/http-kernel', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
}

$this->listenerServiceId = $listenerServiceId;
$this->localeAwareTag = $localeAwareTag;
}

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition($this->listenerServiceId)) {
if (!$container->hasDefinition('locale_aware_listener')) {
return;
}

$services = [];

foreach ($container->findTaggedServiceIds($this->localeAwareTag) as $id => $tags) {
foreach ($container->findTaggedServiceIds('kernel.locale_aware') as $id => $tags) {
$services[] = new Reference($id);
}

if (!$services) {
$container->removeDefinition($this->listenerServiceId);
$container->removeDefinition('locale_aware_listener');

return;
}

$container
->getDefinition($this->listenerServiceId)
->getDefinition('locale_aware_listener')
->setArgument(0, new IteratorArgument($services))
;
}
Expand Down
Loading