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

Skip to content

[FrameworkBundle] Remove obsolete feature detection #51620

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
Sep 11, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
use Symfony\Component\Cache\Adapter\ChainAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
use Symfony\Component\Cache\Marshaller\MarshallerInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Clock\ClockInterface;
Expand Down Expand Up @@ -75,7 +74,6 @@
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\Glob;
use Symfony\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
use Symfony\Component\Form\Extension\HtmlSanitizer\Type\TextTypeHtmlSanitizerExtension;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormTypeExtensionInterface;
Expand All @@ -95,8 +93,6 @@
use Symfony\Component\HttpKernel\Attribute\AsTargetedValueResolver;
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
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;
Expand All @@ -113,7 +109,6 @@
use Symfony\Component\Mercure\HubRegistry;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Bridge as MessengerBridge;
use Symfony\Component\Messenger\Command\StatsCommand;
use Symfony\Component\Messenger\EventListener\StopWorkerOnSignalsListener;
use Symfony\Component\Messenger\Handler\BatchHandlerInterface;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
Expand Down Expand Up @@ -150,7 +145,6 @@
use Symfony\Component\RemoteEvent\Attribute\AsRemoteEventConsumer;
use Symfony\Component\RemoteEvent\RemoteEvent;
use Symfony\Component\Routing\Loader\AnnotationClassLoader;
use Symfony\Component\Routing\Loader\Psr4DirectoryLoader;
use Symfony\Component\Scheduler\Attribute\AsSchedule;
use Symfony\Component\Scheduler\Messenger\SchedulerTransportFactory;
use Symfony\Component\Security\Core\AuthenticationEvents;
Expand All @@ -167,10 +161,7 @@
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ProblemNormalizer;
use Symfony\Component\Serializer\Normalizer\UnwrappingDenormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerAwareInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\String\LazyString;
use Symfony\Component\String\Slugger\SluggerInterface;
Expand All @@ -182,7 +173,6 @@
use Symfony\Component\Translation\Translator;
use Symfony\Component\Uid\Factory\UuidFactory;
use Symfony\Component\Uid\UuidV4;
use Symfony\Component\Validator\Constraints\WhenValidator;
use Symfony\Component\Validator\ConstraintValidatorInterface;
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
use Symfony\Component\Validator\ObjectInitializerInterface;
Expand Down Expand Up @@ -227,11 +217,6 @@ public function load(array $configs, ContainerBuilder $container)
}

$loader->load('web.php');

if (!class_exists(BackedEnumValueResolver::class)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to symfony/http-kernel with #44831 (6.1). FrameworkBundle requires v6.4+

$container->removeDefinition('argument_resolver.backed_enum_resolver');
}

$loader->load('services.php');
$loader->load('fragment_renderer.php');
$loader->load('error_renderer.php');
Expand Down Expand Up @@ -775,11 +760,6 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
if (!ContainerBuilder::willBeAvailable('symfony/translation', Translator::class, ['symfony/framework-bundle', 'symfony/form'])) {
$container->removeDefinition('form.type_extension.upload.validator');
}
if (!method_exists(CachingFactoryDecorator::class, 'reset')) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method was added in #30597 (Symfony 4.2)

$container->getDefinition('form.choice_list_factory.cached')
->clearTag('kernel.reset')
;
}
}

private function registerHttpCacheConfiguration(array $config, ContainerBuilder $container, bool $httpMethodOverride): void
Expand Down Expand Up @@ -1219,10 +1199,6 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co
->replaceArgument(0, $config['default_uri']);
}

if (!class_exists(Psr4DirectoryLoader::class)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to symfony/routing with #47916 (6.2). FrameworkBundle requires v6.4+.

$container->removeDefinition('routing.loader.psr4');
}

if ($this->isInitializedConfigEnabled('annotations') && (new \ReflectionClass(AnnotationClassLoader::class))->hasProperty('reader')) {
$container->getDefinition('routing.loader.annotation')->setArguments([
new Reference('annotation_reader'),
Expand Down Expand Up @@ -1688,10 +1664,6 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
if (!class_exists(ExpressionLanguage::class)) {
$container->removeDefinition('validator.expression_language');
}

if (!class_exists(WhenValidator::class)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to symfony/validator with #42593 (6.2). FrameworkBundle requires v6.4+.

$container->removeDefinition('validator.when');
}
}

private function registerValidatorMapping(ContainerBuilder $container, array $config, array &$files): void
Expand Down Expand Up @@ -1911,7 +1883,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
$container->removeDefinition('serializer.encoder.yaml');
}

if (!class_exists(UnwrappingDenormalizer::class) || !$this->isInitializedConfigEnabled('property_access')) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class was added in #31390 (Symfony 5.1).

if (!$this->isInitializedConfigEnabled('property_access')) {
$container->removeDefinition('serializer.denormalizer.unwrapping');
}

Expand All @@ -1923,12 +1895,6 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
$container->removeDefinition('serializer.normalizer.translatable');
}

// compat with Symfony < 6.3
if (!is_subclass_of(ProblemNormalizer::class, SerializerAwareInterface::class)) {
$container->getDefinition('serializer.normalizer.problem')
->setArguments(['%kernel.debug%']);
}

$serializerLoaders = [];
if (isset($config['enable_attributes']) && $config['enable_attributes']) {
if ($container->getParameter('kernel.debug')) {
Expand Down Expand Up @@ -2125,7 +2091,7 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder
throw new LogicException('Messenger support cannot be enabled as the Messenger component is not installed. Try running "composer require symfony/messenger".');
}

if (!$this->hasConsole() || !class_exists(StatsCommand::class)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class was added to symfony/messenger with #46571 (6.2), FrameworkBundle requires 6.3+.

if (!$this->hasConsole()) {
$container->removeDefinition('console.command.messenger_stats');
}

Expand Down Expand Up @@ -2370,10 +2336,6 @@ private function registerMessengerConfiguration(array $config, ContainerBuilder

private function registerCacheConfiguration(array $config, ContainerBuilder $container): void
{
if (!class_exists(DefaultMarshaller::class)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class exists since #27645 (Symfony 4.2).

$container->removeDefinition('cache.default_marshaller');
}

$version = new Parameter('container.build_id');
$container->getDefinition('cache.adapter.apcu')->replaceArgument(2, $version);
$container->getDefinition('cache.adapter.system')->replaceArgument(2, $version);
Expand Down Expand Up @@ -2434,16 +2396,10 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
$container->register($name, TagAwareAdapter::class)
->addArgument(new Reference('.'.$name.'.inner'))
->addArgument(true !== $pool['tags'] ? new Reference($pool['tags']) : null)
->addMethodCall('setLogger', [new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)])
->setPublic($pool['public'])
->addTag('cache.taggable', ['pool' => $name])
;

if (method_exists(TagAwareAdapter::class, 'setLogger')) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method has been added in #40740 (Symfony 4.4).

$container
->getDefinition($name)
->addMethodCall('setLogger', [new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)])
->addTag('monolog.logger', ['channel' => 'cache']);
}
->addTag('monolog.logger', ['channel' => 'cache']);

$pool['name'] = $tagAwareId = $name;
$pool['public'] = false;
Expand All @@ -2469,7 +2425,7 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
$container->setDefinition($name, $definition);
}

if (method_exists(PropertyAccessor::class, 'createCache')) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method exists since #16838 (Symfony 3.2).

if (class_exists(PropertyAccessor::class)) {
$propertyAccessDefinition = $container->register('cache.property_access', AdapterInterface::class);

if (!$container->getParameter('kernel.debug')) {
Expand Down Expand Up @@ -2514,20 +2470,16 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
$this->registerRetryableHttpClient($retryOptions, 'http_client', $container);
}

if ($hasUriTemplate = class_exists(UriTemplateHttpClient::class)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class was added to symfony/http-client with #49302 (6.3), FrameworkBundle requires 6.3+.

if (ContainerBuilder::willBeAvailable('guzzlehttp/uri-template', \GuzzleHttp\UriTemplate\UriTemplate::class, [])) {
$container->setAlias('http_client.uri_template_expander', 'http_client.uri_template_expander.guzzle');
} elseif (ContainerBuilder::willBeAvailable('rize/uri-template', \Rize\UriTemplate::class, [])) {
$container->setAlias('http_client.uri_template_expander', 'http_client.uri_template_expander.rize');
}

$container
->getDefinition('http_client.uri_template')
->setArgument(2, $defaultUriTemplateVars);
} elseif ($defaultUriTemplateVars) {
throw new LogicException('Support for URI template requires symfony/http-client 6.3 or higher, try upgrading.');
if (ContainerBuilder::willBeAvailable('guzzlehttp/uri-template', \GuzzleHttp\UriTemplate\UriTemplate::class, [])) {
$container->setAlias('http_client.uri_template_expander', 'http_client.uri_template_expander.guzzle');
} elseif (ContainerBuilder::willBeAvailable('rize/uri-template', \Rize\UriTemplate::class, [])) {
$container->setAlias('http_client.uri_template_expander', 'http_client.uri_template_expander.rize');
}

$container
->getDefinition('http_client.uri_template')
->setArgument(2, $defaultUriTemplateVars);

foreach ($config['scoped_clients'] as $name => $scopeConfig) {
if ($container->has($name)) {
throw new InvalidArgumentException(sprintf('Invalid scope name: "%s" is reserved.', $name));
Expand Down Expand Up @@ -2558,16 +2510,14 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
$this->registerRetryableHttpClient($retryOptions, $name, $container);
}

if ($hasUriTemplate) {
$container
->register($name.'.uri_template', UriTemplateHttpClient::class)
->setDecoratedService($name, null, 7) // Between TraceableHttpClient (5) and RetryableHttpClient (10)
->setArguments([
new Reference($name.'.uri_template.inner'),
new Reference('http_client.uri_template_expander', ContainerInterface::NULL_ON_INVALID_REFERENCE),
$defaultUriTemplateVars,
]);
}
$container
->register($name.'.uri_template', UriTemplateHttpClient::class)
->setDecoratedService($name, null, 7) // Between TraceableHttpClient (5) and RetryableHttpClient (10)
->setArguments([
new Reference($name.'.uri_template.inner'),
new Reference('http_client.uri_template_expander', ContainerInterface::NULL_ON_INVALID_REFERENCE),
$defaultUriTemplateVars,
]);

$container->registerAliasForArgument($name, HttpClientInterface::class);

Expand Down Expand Up @@ -3021,10 +2971,6 @@ private function registerUidConfiguration(array $config, ContainerBuilder $conta
$container->getDefinition('name_based_uuid.factory')
->setArguments([$config['name_based_uuid_namespace']]);
}

if (!class_exists(UidValueResolver::class)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class was added to symfony/http-kernel with #44665 (6.1), FrameworkBundle requires 6.4+

$container->removeDefinition('argument_resolver.uid');
}
}

private function registerHtmlSanitizerConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
Expand Down