Skip to content

Commit 711cbbd

Browse files
committed
[FrameworkBundle][PropertyInfo] Wire the ConstructorExtractor class
1 parent 42d9d7c commit 711cbbd

File tree

13 files changed

+65
-4
lines changed

13 files changed

+65
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ CHANGELOG
66

77
* Add native return type to `Translator` and to `Application::reset()`
88
* Deprecate the integration of Doctrine annotations, either uninstall the `doctrine/annotations` package or disable the integration by setting `framework.annotations` to `false`
9+
* Wire the `Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor` class
10+
* Add new `framework.property_info.with_constructor_extractor` option to
11+
allow enabling or disabling the constructor extractor integration
912

1013
6.3
1114
---

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,14 @@ private function addPropertyInfoSection(ArrayNodeDefinition $rootNode, callable
11501150
->children()
11511151
->arrayNode('property_info')
11521152
->info('Property info configuration')
1153+
->addDefaultsIfNotSet()
11531154
->{$enableIfStandalone('symfony/property-info', PropertyInfoExtractorInterface::class)}()
1155+
->children()
1156+
->booleanNode('with_constructor_extractor')
1157+
->info('Registers the constructor extractor.')
1158+
->defaultFalse()
1159+
->end()
1160+
->end()
11541161
->end()
11551162
->end()
11561163
;

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
use Symfony\Component\Notifier\TexterInterface;
131131
use Symfony\Component\Notifier\Transport\TransportFactoryInterface as NotifierTransportFactoryInterface;
132132
use Symfony\Component\PropertyAccess\PropertyAccessor;
133+
use Symfony\Component\PropertyInfo\Extractor\ConstructorArgumentTypeExtractorInterface;
133134
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
134135
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
135136
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
@@ -395,7 +396,7 @@ public function load(array $configs, ContainerBuilder $container)
395396
}
396397

397398
if ($propertyInfoEnabled) {
398-
$this->registerPropertyInfoConfiguration($container, $loader);
399+
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader);
399400
}
400401

401402
if ($this->readConfigEnabled('lock', $container, $config['lock'])) {
@@ -637,6 +638,8 @@ public function load(array $configs, ContainerBuilder $container)
637638
->addTag('property_info.list_extractor');
638639
$container->registerForAutoconfiguration(PropertyTypeExtractorInterface::class)
639640
->addTag('property_info.type_extractor');
641+
$container->registerForAutoconfiguration(ConstructorArgumentTypeExtractorInterface::class)
642+
->addTag('property_info.constructor_extractor');
640643
$container->registerForAutoconfiguration(PropertyDescriptionExtractorInterface::class)
641644
->addTag('property_info.description_extractor');
642645
$container->registerForAutoconfiguration(PropertyAccessExtractorInterface::class)
@@ -1957,26 +1960,32 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
19571960
}
19581961
}
19591962

1960-
private function registerPropertyInfoConfiguration(ContainerBuilder $container, PhpFileLoader $loader): void
1963+
private function registerPropertyInfoConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
19611964
{
19621965
if (!interface_exists(PropertyInfoExtractorInterface::class)) {
19631966
throw new LogicException('PropertyInfo support cannot be enabled as the PropertyInfo component is not installed. Try running "composer require symfony/property-info".');
19641967
}
19651968

19661969
$loader->load('property_info.php');
19671970

1971+
if (!$config['with_constructor_extractor']) {
1972+
$container->removeDefinition('property_info.constructor_extractor');
1973+
}
1974+
19681975
if (
19691976
ContainerBuilder::willBeAvailable('phpstan/phpdoc-parser', PhpDocParser::class, ['symfony/framework-bundle', 'symfony/property-info'])
19701977
&& ContainerBuilder::willBeAvailable('phpdocumentor/type-resolver', ContextFactory::class, ['symfony/framework-bundle', 'symfony/property-info'])
19711978
) {
19721979
$definition = $container->register('property_info.phpstan_extractor', PhpStanExtractor::class);
19731980
$definition->addTag('property_info.type_extractor', ['priority' => -1000]);
1981+
$definition->addTag('property_info.constructor_extractor', ['priority' => -1000]);
19741982
}
19751983

19761984
if (ContainerBuilder::willBeAvailable('phpdocumentor/reflection-docblock', DocBlockFactoryInterface::class, ['symfony/framework-bundle', 'symfony/property-info'], true)) {
19771985
$definition = $container->register('property_info.php_doc_extractor', PhpDocExtractor::class);
19781986
$definition->addTag('property_info.description_extractor', ['priority' => -1000]);
19791987
$definition->addTag('property_info.type_extractor', ['priority' => -1001]);
1988+
$definition->addTag('property_info.constructor_extractor', ['priority' => -1001]);
19801989
}
19811990

19821991
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
@@ -58,6 +58,7 @@
5858
use Symfony\Component\HttpKernel\KernelEvents;
5959
use Symfony\Component\Messenger\DependencyInjection\MessengerPass;
6060
use Symfony\Component\Mime\DependencyInjection\AddMimeTypeGuesserPass;
61+
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoConstructorPass;
6162
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
6263
use Symfony\Component\Routing\DependencyInjection\RoutingResolverPass;
6364
use Symfony\Component\Scheduler\DependencyInjection\AddScheduleMessengerPass;
@@ -163,6 +164,7 @@ public function build(ContainerBuilder $container)
163164
$container->addCompilerPass(new FragmentRendererPass());
164165
$this->addCompilerPassIfExists($container, SerializerPass::class);
165166
$this->addCompilerPassIfExists($container, PropertyInfoPass::class);
167+
$this->addCompilerPassIfExists($container, PropertyInfoConstructorPass::class);
166168
$container->addCompilerPass(new ControllerArgumentValueResolverPass());
167169
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
168170
$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
@@ -328,6 +328,7 @@
328328

329329
<xsd:complexType name="property_info">
330330
<xsd:attribute name="enabled" type="xsd:boolean" />
331+
<xsd:attribute name="with-constructor-extractor" type="xsd:boolean" />
331332
</xsd:complexType>
332333

333334
<xsd:complexType name="cache">

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ protected static function getBundleDefaultConfig()
578578
],
579579
'property_info' => [
580580
'enabled' => !class_exists(FullStack::class),
581+
'with_constructor_extractor' => false,
581582
],
582583
'router' => [
583584
'enabled' => false,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'http_method_override' => false,
5+
'property_info' => [
6+
'enabled' => true,
7+
'with_constructor_extractor' => true,
8+
],
9+
]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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">
9+
<framework:property-info enabled="true" with-constructor-extractor="true" />
10+
</framework:config>
11+
</container>

0 commit comments

Comments
 (0)