Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0aed9fa

Browse filesBrowse files
committed
feature #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 #30335. The original PR removed the wiring to prevent creating a BC break, see #30128 (comment) & #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
Copy full SHA for 0aed9fa

26 files changed

+113
-19
lines changed

‎UPGRADE-7.3.md

Copy file name to clipboardExpand all lines: UPGRADE-7.3.md
+6
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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1
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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php
+1
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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+15
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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+11-2
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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
+2
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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/property_info.php
+6
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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
+1
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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+1-1
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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php
+4-1
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' => [

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/property_info.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/property_info.php
+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
'php_errors' => ['log' => true],
88
'property_info' => [
99
'enabled' => true,
10+
'with_constructor_extractor' => false,
1011
],
1112
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'annotations' => false,
5+
'http_method_override' => false,
6+
'handle_all_throwables' => true,
7+
'php_errors' => ['log' => true],
8+
'property_info' => [
9+
'enabled' => true,
10+
'with_constructor_extractor' => true,
11+
],
12+
]);

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_auto_mapping.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_auto_mapping.php
+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
'http_method_override' => false,
66
'handle_all_throwables' => true,
77
'php_errors' => ['log' => true],
8-
'property_info' => ['enabled' => true],
8+
'property_info' => [
9+
'enabled' => true,
10+
'with_constructor_extractor' => true,
11+
],
912
'validation' => [
1013
'email_validation_mode' => 'html5',
1114
'auto_mapping' => [

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml
+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</framework:default-context>
4545
</framework:named-serializer>
4646
</framework:serializer>
47-
<framework:property-info />
47+
<framework:property-info with-constructor-extractor="true" />
4848
<framework:type-info />
4949
<framework:json-encoder />
5050
</framework:config>

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/property_info.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/property_info.xml
+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
<framework:config http-method-override="false" handle-all-throwables="true">
99
<framework:annotations enabled="false" />
1010
<framework:php-errors log="true" />
11-
<framework:property-info enabled="true" />
11+
<framework:property-info enabled="true" with-constructor-extractor="false" />
1212
</framework:config>
1313
</container>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config http-method-override="false" handle-all-throwables="true">
9+
<framework:annotations enabled="false" />
10+
<framework:php-errors log="true" />
11+
<framework:property-info enabled="true" with-constructor-extractor="true" />
12+
</framework:config>
13+
</container>

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_auto_mapping.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_auto_mapping.xml
+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<framework:config http-method-override="false" handle-all-throwables="true">
77
<framework:annotations enabled="false" />
88
<framework:php-errors log="true" />
9-
<framework:property-info enabled="true" />
9+
<framework:property-info enabled="true" with-constructor-extractor="true" />
1010
<framework:validation email-validation-mode="html5">
1111
<framework:auto-mapping namespace="App\">
1212
<framework:service>foo</framework:service>

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml
+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ framework:
6464
default_context:
6565
enable_max_depth: false
6666
type_info: ~
67-
property_info: ~
67+
property_info:
68+
with_constructor_extractor: true
6869
ide: file%%link%%format
6970
request:
7071
formats:

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/property_info.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/property_info.yml
+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ framework:
66
log: true
77
property_info:
88
enabled: true
9+
with_constructor_extractor: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
framework:
2+
annotations: false
3+
http_method_override: false
4+
handle_all_throwables: true
5+
php_errors:
6+
log: true
7+
property_info:
8+
enabled: true
9+
with_constructor_extractor: true

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_auto_mapping.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_auto_mapping.yml
+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ framework:
44
handle_all_throwables: true
55
php_errors:
66
log: true
7-
property_info: { enabled: true }
7+
property_info:
8+
enabled: true
9+
with_constructor_extractor: true
810
validation:
911
email_validation_mode: html5
1012
auto_mapping:

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php
+8
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,14 @@ public function testPropertyInfoEnabled()
16761676
{
16771677
$container = $this->createContainerFromFile('property_info');
16781678
$this->assertTrue($container->has('property_info'));
1679+
$this->assertFalse($container->has('property_info.constructor_extractor'));
1680+
}
1681+
1682+
public function testPropertyInfoWithConstructorExtractorEnabled()
1683+
{
1684+
$container = $this->createContainerFromFile('property_info_with_constructor_extractor');
1685+
$this->assertTrue($container->has('property_info'));
1686+
$this->assertTrue($container->has('property_info.constructor_extractor'));
16791687
}
16801688

16811689
public function testPropertyInfoCacheActivated()

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ApiAttributesTest/config.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ApiAttributesTest/config.yml
+3-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ framework:
55
serializer:
66
enabled: true
77
validation: true
8-
property_info: { enabled: true }
8+
property_info:
9+
enabled: true
10+
with_constructor_extractor: true

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ContainerDump/config.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ContainerDump/config.yml
+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ framework:
1515
translator: true
1616
validation: true
1717
serializer: true
18-
property_info: true
18+
property_info:
19+
enabled: true
20+
with_constructor_extractor: true
1921
csrf_protection: true
2022
form: true

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml
+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ framework:
1010
max_depth_handler: Symfony\Bundle\FrameworkBundle\Tests\Fixtures\Serializer\MaxDepthHandler
1111
default_context:
1212
enable_max_depth: true
13-
property_info: { enabled: true }
13+
property_info:
14+
enabled: true
15+
with_constructor_extractor: true
1416

1517
services:
1618
serializer.alias:

‎src/Symfony/Component/PropertyInfo/Extractor/ConstructorArgumentTypeExtractorInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Extractor/ConstructorArgumentTypeExtractorInterface.php
-6
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,20 @@
1818
* Infers the constructor argument type.
1919
*
2020
* @author Dmitrii Poddubnyi <dpoddubny@gmail.com>
21-
*
22-
* @internal
2321
*/
2422
interface ConstructorArgumentTypeExtractorInterface
2523
{
2624
/**
2725
* Gets types of an argument from constructor.
2826
*
2927
* @return LegacyType[]|null
30-
*
31-
* @internal
3228
*/
3329
public function getTypesFromConstructor(string $class, string $property): ?array;
3430

3531
/**
3632
* Gets type of an argument from constructor.
3733
*
3834
* @param class-string $class
39-
*
40-
* @internal
4135
*/
4236
public function getTypeFromConstructor(string $class, string $property): ?Type;
4337
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.