Skip to content

Commit a50e8c9

Browse files
committed
[FrameworkBundle][PropertyInfo] Wire the ConstructorExtractor class
1 parent 4813d66 commit a50e8c9

13 files changed

+69
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
6.4
5+
---
6+
7+
* Wire the `Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor` class
8+
* Add new `framework.property_info.with_constructor_extractor` option to
9+
allow enabling or disabling the constructor extractor integration
10+
411
6.3
512
---
613

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

+7
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

+11-2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
use Symfony\Component\Notifier\TexterInterface;
130130
use Symfony\Component\Notifier\Transport\TransportFactoryInterface as NotifierTransportFactoryInterface;
131131
use Symfony\Component\PropertyAccess\PropertyAccessor;
132+
use Symfony\Component\PropertyInfo\Extractor\ConstructorArgumentTypeExtractorInterface;
132133
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
133134
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
134135
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
@@ -390,7 +391,7 @@ public function load(array $configs, ContainerBuilder $container)
390391
}
391392

392393
if ($propertyInfoEnabled) {
393-
$this->registerPropertyInfoConfiguration($container, $loader);
394+
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader);
394395
}
395396

396397
if ($this->readConfigEnabled('lock', $container, $config['lock'])) {
@@ -631,6 +632,8 @@ public function load(array $configs, ContainerBuilder $container)
631632
->addTag('property_info.list_extractor');
632633
$container->registerForAutoconfiguration(PropertyTypeExtractorInterface::class)
633634
->addTag('property_info.type_extractor');
635+
$container->registerForAutoconfiguration(ConstructorArgumentTypeExtractorInterface::class)
636+
->addTag('property_info.constructor_extractor');
634637
$container->registerForAutoconfiguration(PropertyDescriptionExtractorInterface::class)
635638
->addTag('property_info.description_extractor');
636639
$container->registerForAutoconfiguration(PropertyAccessExtractorInterface::class)
@@ -1942,26 +1945,32 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
19421945
}
19431946
}
19441947

1945-
private function registerPropertyInfoConfiguration(ContainerBuilder $container, PhpFileLoader $loader): void
1948+
private function registerPropertyInfoConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
19461949
{
19471950
if (!interface_exists(PropertyInfoExtractorInterface::class)) {
19481951
throw new LogicException('PropertyInfo support cannot be enabled as the PropertyInfo component is not installed. Try running "composer require symfony/property-info".');
19491952
}
19501953

19511954
$loader->load('property_info.php');
19521955

1956+
if (!$config['with_constructor_extractor']) {
1957+
$container->removeDefinition('property_info.constructor_extractor');
1958+
}
1959+
19531960
if (
19541961
ContainerBuilder::willBeAvailable('phpstan/phpdoc-parser', PhpDocParser::class, ['symfony/framework-bundle', 'symfony/property-info'])
19551962
&& ContainerBuilder::willBeAvailable('phpdocumentor/type-resolver', ContextFactory::class, ['symfony/framework-bundle', 'symfony/property-info'])
19561963
) {
19571964
$definition = $container->register('property_info.phpstan_extractor', PhpStanExtractor::class);
19581965
$definition->addTag('property_info.type_extractor', ['priority' => -1000]);
1966+
$definition->addTag('property_info.constructor_extractor', ['priority' => -1000]);
19591967
}
19601968

19611969
if (ContainerBuilder::willBeAvailable('phpdocumentor/reflection-docblock', DocBlockFactoryInterface::class, ['symfony/framework-bundle', 'symfony/property-info'], true)) {
19621970
$definition = $container->register('property_info.php_doc_extractor', PhpDocExtractor::class);
19631971
$definition->addTag('property_info.description_extractor', ['priority' => -1000]);
19641972
$definition->addTag('property_info.type_extractor', ['priority' => -1001]);
1973+
$definition->addTag('property_info.constructor_extractor', ['priority' => -1001]);
19651974
}
19661975

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

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

+2
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;
@@ -155,6 +156,7 @@ public function build(ContainerBuilder $container)
155156
$container->addCompilerPass(new FragmentRendererPass());
156157
$this->addCompilerPassIfExists($container, SerializerPass::class);
157158
$this->addCompilerPassIfExists($container, PropertyInfoPass::class);
159+
$this->addCompilerPassIfExists($container, PropertyInfoConstructorPass::class);
158160
$container->addCompilerPass(new ControllerArgumentValueResolverPass());
159161
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
160162
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);

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

+1
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

+1
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
framework:
2+
http_method_override: false
3+
property_info:
4+
enabled: true
5+
with_constructor_extractor: true

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

+8
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,14 @@ public function testPropertyInfoEnabled()
16311631
{
16321632
$container = $this->createContainerFromFile('property_info');
16331633
$this->assertTrue($container->has('property_info'));
1634+
$this->assertFalse($container->has('property_info.constructor_extractor'));
1635+
}
1636+
1637+
public function testPropertyInfoWithConstructorExtractorEnabled()
1638+
{
1639+
$container = $this->createContainerFromFile('property_info_with_constructor_extractor');
1640+
$this->assertTrue($container->has('property_info'));
1641+
$this->assertTrue($container->has('property_info.constructor_extractor'));
16341642
}
16351643

16361644
public function testPropertyInfoCacheActivated()

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

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* Infers the constructor argument type.
1818
*
1919
* @author Dmitrii Poddubnyi <[email protected]>
20-
*
21-
* @internal
2220
*/
2321
interface ConstructorArgumentTypeExtractorInterface
2422
{

0 commit comments

Comments
 (0)