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

Skip to content

Commit f764050

Browse files
committed
[FrameworkBundle][PropertyInfo] Wire the ConstructorExtractor class
1 parent 04ee771 commit f764050

13 files changed

+72
-8
lines changed

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,14 @@ private function addPropertyInfoSection(ArrayNodeDefinition $rootNode, callable
12251225
->children()
12261226
->arrayNode('property_info')
12271227
->info('Property info configuration')
1228+
->addDefaultsIfNotSet()
12281229
->{$enableIfStandalone('symfony/property-info', PropertyInfoExtractorInterface::class)}()
1230+
->children()
1231+
->booleanNode('with_constructor_extractor')
1232+
->info('Registers the constructor extractor.')
1233+
->defaultFalse()
1234+
->end()
1235+
->end()
12291236
->end()
12301237
->end()
12311238
;

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ protected static function getBundleDefaultConfig()
808808
],
809809
'property_info' => [
810810
'enabled' => !class_exists(FullStack::class),
811+
'with_constructor_extractor' => false,
811812
],
812813
'router' => [
813814
'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

Lines changed: 8 additions & 0 deletions
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/Component/PropertyInfo/Extractor/ConstructorArgumentTypeExtractorInterface.php

Lines changed: 0 additions & 6 deletions
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