8000 [FrameworkBundle][PropertyInfo] Wire the `ConstructorExtractor` class · symfony/symfony@c17cfc3 · GitHub
[go: up one dir, main page]

Skip to content

Commit c17cfc3

Browse files
committed
[FrameworkBundle][PropertyInfo] Wire the ConstructorExtractor class
1 parent cf3dfb6 commit c17cfc3

13 files changed

+73
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ CHANGELOG
99
* Make the `config/` directory optional in `MicroKernelTrait`, add support for service arguments in the
1010
invokable Kernel class, and register `FrameworkBundle` by default when the `bundles.php` file is missing
1111
* [BC BREAK] The `secrets:decrypt-to-local` command terminates with a non-zero exit code when a secret could not be read
12+
* Wire the `Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor` class
13+
* Add new `framework.property_info.with_constructor_extractor` option to allow enabling or disabling the constructor extractor integration
1214

1315
7.1
1416
---

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

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class UnusedTagsPass implements CompilerPassInterface
7070
'monolog.logger',
7171
'notifier.channel',
7272
'property_info.access_extractor',
73+
'property_info.constructor_extractor',
7374
'property_info.initializable_extractor',
7475
'property_info.list_extractor',
7576
'property_info.type_extractor',

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

+7
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,14 @@ private function addPropertyInfoSection(ArrayNodeDefinition $rootNode, callable
11581158
->children()
11591159
->arrayNode('property_info')
11601160
->info('Property info configuration')
1161+
->addDefaultsIfNotSet()
11611162
->{$enableIfStandalone('symfony/property-info', PropertyInfoExtractorInterface::class)}()
1163+
->children()
1164+
->booleanNode('with_constructor_extractor')
1165+
->info('Registers the constructor extractor.')
1166+
->defaultFalse()
1167+
->end()
1168+
->end()
11621169
->end()
11631170
->end()
11641171
;

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
use Symfony\Component\Notifier\Transport\TransportFactoryInterface as NotifierTransportFactoryInterface;
128128
use Symfony\Component\Process\Messenger\RunProcessMessageHandler;
129129
use Symfony\Component\PropertyAccess\PropertyAccessor;
130+
use Symfony\Component\PropertyInfo\Extractor\ConstructorArgumentTypeExtractorInterface;
130131
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
131132
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
132133
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
@@ -405,7 +406,7 @@ public function load(array $configs, ContainerBuilder $container): void
405406
}
406407

407408
if ($propertyInfoEnabled) {
408-
$this->registerPropertyInfoConfiguration($container, $loader);
409+
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader);
409410
}
410411

411412
if ($this->readConfigEnabled('lock', $container, $config['lock'])) {
@@ -637,6 +638,8 @@ public function load(array $configs, ContainerBuilder $container): void
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)
@@ -1937,26 +1940,32 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
19371940
$container->getDefinition('serializer.normalizer.property')->setArgument(5, $defaultContext);
19381941
}
19391942

1940-
private function registerPropertyInfoConfiguration(ContainerBuilder $container, PhpFileLoader $loader): void
1943+
private function registerPropertyInfoConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
19411944
{
19421945
if (!interface_exists(PropertyInfoExtractorInterface::class)) {
19431946
throw new LogicException('PropertyInfo support cannot be enabled as the PropertyInfo component is not installed. Try running "composer require symfony/property-info".');
19441947
}
19451948

19461949
$loader->load('property_info.php');
19471950

1951+
if (!$config['with_constructor_extractor']) {
1952+
$container->removeDefinition('property_info.constructor_extractor');
1953+
}
1954+
19481955
if (
19491956
ContainerBuilder::willBeAvailable('phpstan/phpdoc-parser', PhpDocParser::class, ['symfony/framework-bundle', 'symfony/property-info'])
19501957
&& ContainerBuilder::willBeAvailable('phpdocumentor/type-resolver', ContextFactory::class, ['symfony/framework-bundle', 'symfony/property-info'])
19511958
) {
19521959
$definition = $container->register('property_info.phpstan_extractor', PhpStanExtractor::class);
19531960
$definition->addTag('property_info.type_extractor', ['priority' => -1000]);
1961+
$definition->addTag('property_info.constructor_extractor', ['priority' => -1000]);
19541962
}
19551963

19561964
if (ContainerBuilder::willBeAvailable('phpdocumentor/reflection-docblock', DocBlockFactoryInterface::class, ['symfony/framework-bundle', 'symfony/property-info'], true)) {
19571965
$definition = $container->register('property_info.php_doc_extractor', PhpDocExtractor::class);
19581966
$definition->addTag('property_info.description_extractor', ['priority' => -1000]);
19591967
$definition->addTag('property_info.type_extractor', ['priority' => -1001]);
1968+
$definition->addTag('property_info.constructor_extractor', ['priority' => -1001]);
19601969
}
19611970

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

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
use Symfony\Component\HttpKernel\KernelEvents;
5555
use Symfony\Component\Messenger\DependencyInjection\MessengerPass;
5656
use Symfony\Component\Mime\DependencyInjection\AddMimeTypeGuesserPass;
57+
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoConstructorPass;
5758
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
5859
use Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass;
5960
use Symfony\Component\Routing\DependencyInjection\RoutingResolverPass;
@@ -152,6 +153,7 @@ public function build(ContainerBuilder $container): void
152153
$container->addCompilerPass(new FragmentRendererPass());
153154
$this->addCompilerPassIfExists($container, SerializerPass::class);
154155
$this->addCompilerPassIfExists($container, PropertyInfoPass::class);
156+
$this->addCompilerPassIfExists($container, PropertyInfoConstructorPass::class);
155157
$container->addCompilerPass(new ControllerArgumentValueResolverPass());
156158
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
157159
$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
@@ -334,6 +334,7 @@
334334

335335
<xsd:complexType name="property_info">
336336
<xsd:attribute name="enabled" type="xsd:boolean" />
337+
<xsd:attribute name="with-constructor-extractor" type="xsd:boolean" />
337338
</xsd:complexType>
338339

339340
<xsd:complexType name="cache">

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

+1
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ protected static function getBundleDefaultConfig()
772772
],
773773
'property_info' => [
774774
'enabled' => !class_exists(FullStack::class),
775+
'with_constructor_extractor' => false,
775776
],
776777
'router' => [
777778
'enabled' => false,
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+
]);
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>
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/FrameworkExtensionTestCase.php

+8
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,14 @@ public function testPropertyInfoEnabled()
16561656
{
16571657
$container = $this->createContainerFromFile('property_info');
16581658
$this->assertTrue($container->has('property_info'));
1659+
$this->assertFalse($container->has('property_info.constructor_extractor'));
1660+
}
1661+
1662+
public function testPropertyInfoWithConstructorExtractorEnabled()
1663+
{
1664+
$container = $this->createContainerFromFile('property_info_with_constructor_extractor');
1665+
$this->assertTrue($container->has('property_info'));
1666+
$this->assertTrue($container->has('property_info.constructor_extractor'));
16591667
}
16601668

16611669
public function testPropertyInfoCacheActivated()

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

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
* Infers the constructor argument type.
1919
*
2020
* @author Dmitrii Poddubnyi <dpoddubny@gmail.com>
21-
*
22-
* @internal
2321
*/
2422
interface ConstructorArgumentTypeExtractorInterface
2523
{

0 commit comments

Comments
 (0)
0