Skip to content

Commit 0aed9fa

Browse files
committed
feature symfony#50334 [FrameworkBundle][PropertyInfo] Wire the ConstructorExtractor class (HypeMC)
This PR was merged into the 7.3 branch. Discussion ---------- [FrameworkBundle][PropertyInfo] Wire the `ConstructorExtractor` class | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - A sort of followup to symfony#30335. The original PR removed the wiring to prevent creating a BC break, see symfony#30128 (comment) & symfony#30335 (comment). This PR proposes adding a new `framework.property_info.with_constructor_extractor` configuration to allow optionally enabling the framework integration. The configuration defaults to `false` to prevent creating a BC break. Only when it's set to `true` will the `ConstructorExtractor` be registered in the container. Commits ------- 2b392b1 [FrameworkBundle][PropertyInfo] Wire the `ConstructorExtractor` class
2 parents cd24b4b + 2b392b1 commit 0aed9fa

26 files changed

+113
-19
lines changed

UPGRADE-7.3.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ Read more about this in the [Symfony documentation](https://symfony.com/doc/7.3/
88

99
If you're upgrading from a version below 7.1, follow the [7.2 upgrade guide](UPGRADE-7.2.md) first.
1010

11+
FrameworkBundle
12+
---------------
13+
14+
* Not setting the `framework.property_info.with_constructor_extractor` option explicitly is deprecated
15+
because its default value will change in version 8.0
16+
1117
Serializer
1218
----------
1319

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Add support for assets pre-compression
88
* Rename `TranslationUpdateCommand` to `TranslationExtractCommand`
99
* Add JsonEncoder services and configuration
10+
* Add new `framework.property_info.with_constructor_extractor` option to allow enabling or disabling the constructor extractor integration
1011

1112
7.2
1213
---

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class UnusedTagsPass implements CompilerPassInterface
7373
'monolog.logger',
7474
'notifier.channel',
7575
'property_info.access_extractor',
76+
'property_info.constructor_extractor',
7677
'property_info.initializable_extractor',
7778
'property_info.list_extractor',
7879
'property_info.type_extractor',

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,8 +1226,23 @@ private function addPropertyInfoSection(ArrayNodeDefinition $rootNode, callable
12261226
->arrayNode('property_info')
12271227
->info('Property info configuration')
12281228
->{$enableIfStandalone('symfony/property-info', PropertyInfoExtractorInterface::class)}()
1229+
->children()
1230+
->booleanNode('with_constructor_extractor')
1231+
->info('Registers the constructor extractor.')
1232+
->end()
1233+
->end()
12291234
->end()
12301235
->end()
1236+
->validate()
1237+
->ifTrue(fn ($v) => $v['property_info']['enabled'] && !isset($v['property_info']['with_constructor_extractor']))
1238+
->then(function ($v) {
1239+
$v['property_info']['with_constructor_extractor'] = false;
1240+
1241+
trigger_deprecation('symfony/property-info', '7.3', 'Not setting the "with_constructor_extractor" option explicitly is deprecated because its default value will change in version 8.0.');
1242+
1243+
return $v;
1244+
})
1245+
->end()
12311246
;
12321247
}
12331248

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
use Symfony\Component\Notifier\Transport\TransportFactoryInterface as NotifierTransportFactoryInterface;
136136
use Symfony\Component\Process\Messenger\RunProcessMessageHandler;
137137
use Symfony\Component\PropertyAccess\PropertyAccessor;
138+
use Symfony\Component\PropertyInfo\Extractor\ConstructorArgumentTypeExtractorInterface;
138139
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
139140
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
140141
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
@@ -427,7 +428,7 @@ public function load(array $configs, ContainerBuilder $container): void
427428
}
428429

429430
if ($propertyInfoEnabled) {
430-
$this->registerPropertyInfoConfiguration($container, $loader);
431+
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader);
431432
}
432433

433434
if ($this->readConfigEnabled('json_encoder', $container, $config['json_encoder'])) {
@@ -657,6 +658,8 @@ public function load(array $configs, ContainerBuilder $container): void
657658
->addTag('property_info.list_extractor');
658659
$container->registerForAutoconfiguration(PropertyTypeExtractorInterface::class)
659660
->addTag('property_info.type_extractor');
661+
$container->registerForAutoconfiguration(ConstructorArgumentTypeExtractorInterface::class)
662+
->addTag('property_info.constructor_extractor');
660663
$container->registerForAutoconfiguration(PropertyDescriptionExtractorInterface::class)
661664
->addTag('property_info.description_extractor');
662665
$container->registerForAutoconfiguration(PropertyAccessExtractorInterface::class)
@@ -2040,26 +2043,32 @@ private function registerJsonEncoderConfiguration(array $config, ContainerBuilde
20402043
}
20412044
}
20422045

2043-
private function registerPropertyInfoConfiguration(ContainerBuilder $container, PhpFileLoader $loader): void
2046+
private function registerPropertyInfoConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
20442047
{
20452048
if (!interface_exists(PropertyInfoExtractorInterface::class)) {
20462049
throw new LogicException('PropertyInfo support cannot be enabled as the PropertyInfo component is not installed. Try running "composer require symfony/property-info".');
20472050
}
20482051

20492052
$loader->load('property_info.php');
20502053

2054+
if (!$config['with_constructor_extractor']) {
2055+
$container->removeDefinition('property_info.constructor_extractor');
2056+
}
2057+
20512058
if (
20522059
ContainerBuilder::willBeAvailable('phpstan/phpdoc-parser', PhpDocParser::class, ['symfony/framework-bundle', 'symfony/property-info'])
20532060
&& ContainerBuilder::willBeAvailable('phpdocumentor/type-resolver', ContextFactory::class, ['symfony/framework-bundle', 'symfony/property-info'])
20542061
) {
20552062
$definition = $container->register('property_info.phpstan_extractor', PhpStanExtractor::class);
20562063
$definition->addTag('property_info.type_extractor', ['priority' => -1000]);
2064+
$definition->addTag('property_info.constructor_extractor', ['priority' => -1000]);
20572065
}
20582066

20592067
if (ContainerBuilder::willBeAvailable('phpdocumentor/reflection-docblock', DocBlockFactoryInterface::class, ['symfony/framework-bundle', 'symfony/property-info'], true)) {
20602068
$definition = $container->register('property_info.php_doc_extractor', PhpDocExtractor::class);
20612069
$definition->addTag('property_info.description_extractor', ['priority' => -1000]);
20622070
$definition->addTag('property_info.type_extractor', ['priority' => -1001]);
2071+
$definition->addTag('property_info.constructor_extractor', ['priority' => -1001]);
20632072
}
20642073

20652074
if ($container->getParameter('kernel.debug')) {

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
use Symfony\Component\HttpKernel\KernelEvents;
5757
use Symfony\Component\Messenger\DependencyInjection\MessengerPass;
5858
use Symfony\Component\Mime\DependencyInjection\AddMimeTypeGuesserPass;
59+
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoConstructorPass;
5960
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
6061
use Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass;
6162
use Symfony\Component\Routing\DependencyInjection\RoutingResolverPass;
@@ -164,6 +165,7 @@ public function build(ContainerBuilder $container): void
164165
$container->addCompilerPass(new FragmentRendererPass());
165166
$this->addCompilerPassIfExists($container, SerializerPass::class);
166167
$this->addCompilerPassIfExists($container, PropertyInfoPass::class);
168+
$this->addCompilerPassIfExists($container, PropertyInfoConstructorPass::class);
167169
$container->addCompilerPass(new ControllerArgumentValueResolverPass());
168170
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
169171
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);

src/Symfony/Bundle/FrameworkBundle/Resources/config/property_info.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

14+
use Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor;
1415
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
1516
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
1617
use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface;
@@ -43,9 +44,14 @@
4344
->set('property_info.reflection_extractor', ReflectionExtractor::class)
4445
->tag('property_info.list_extractor', ['priority' => -1000])
4546
->tag('property_info.type_extractor', ['priority' => -1002])
47+
->tag('property_info.constructor_extractor', ['priority' => -1002])
4648
->tag('property_info.access_extractor', ['priority' => -1000])
4749
->tag('property_info.initializable_extractor', ['priority' => -1000])
4850

51+
->set('property_info.constructor_extractor', ConstructorExtractor::class)
52+
->args([[]])
53+
->tag('property_info.type_extractor', ['priority' => -999])
54+
4955
->alias(PropertyReadInfoExtractorInterface::class, 'property_info.reflection_extractor')
5056
->alias(PropertyWriteInfoExtractorInterface::class, 'property_info.reflection_extractor')
5157
;

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@
370370

371371
<xsd:complexType name="property_info">
372372
<xsd:attribute name="enabled" type="xsd:boolean" />
373+
<xsd:attribute name="with-constructor-extractor" type="xsd:boolean" />
373374
</xsd:complexType>
374375

375376
<xsd:complexType name="cache">

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ protected static function getBundleDefaultConfig()
808808
],
809809
'property_info' => [
810810
'enabled' => !class_exists(FullStack::class),
811-
],
811+
] + (!class_exists(FullStack::class) ? ['with_constructor_extractor' => false] : []),
812812
'router' => [
813813
'enabled' => false,
814814
'default_uri' => null,

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@
7474
],
7575
],
7676
],
77-
'property_info' => true,
77+
'property_info' => [
78+
'enabled' => true,
79+
'with_constructor_extractor' => true,
80+
],
7881
'type_info' => true,
7982
'ide' => 'file%%link%%format',
8083
'request' => [

0 commit comments

Comments
 (0)