Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2fcfbc

Browse files
committed
[FrameworkBundle][PropertyInfo] Wire the ConstructorExtractor class
1 parent 73f8713 commit d2fcfbc

13 files changed

+74
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ CHANGELOG
1212
* Add `rate_limiter` tags to rate limiter services
1313
* Add `secrets:reveal` command
1414
* Add `rate_limiter` option to `http_client.default_options` and `http_client.scoped_clients`
15+
* Wire the `Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor` class
16+
* Add new `framework.property_info.with_constructor_extractor` option to
17+
allow enabling or disabling the constructor extractor integration
1518

1619
7.0
1720
---

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,14 @@ private function addPropertyInfoSection(ArrayNodeDefinition $rootNode, callable
11571157
->children()
11581158
->arrayNode('property_info')
11591159
->info('Property info configuration')
1160+
->addDefaultsIfNotSet()
11601161
->{$enableIfStandalone('symfony/property-info', PropertyInfoExtractorInterface::class)}()
1162+
->children()
1163+
->booleanNode('with_constructor_extractor')
1164+
->info('Registers the constructor extractor.')
1165+
->defaultFalse()
1166+
->end()
1167+
->end()
11611168
->end()
11621169
->end()
11631170
;

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
use Symfony\Component\Notifier\Transport\TransportFactoryInterface as NotifierTransportFactoryInterface;
127127
use Symfony\Component\Process\Messenger\RunProcessMessageHandler;
128128
use Symfony\Component\PropertyAccess\PropertyAccessor;
129+
use Symfony\Component\PropertyInfo\Extractor\ConstructorArgumentTypeExtractorInterface;
129130
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
130131
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
131132
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
@@ -398,7 +399,7 @@ public function load(array $configs, ContainerBuilder $container): void
398399
}
399400

400401
if ($propertyInfoEnabled) {
401-
$this->registerPropertyInfoConfiguration($container, $loader);
402+
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader);
402403
}
403404

404405
if ($this->readConfigEnabled('lock', $container, $config['lock'])) {
@@ -630,6 +631,8 @@ public function load(array $configs, ContainerBuilder $container): void
630631
->addTag('property_info.list_extractor');
631632
$container->registerForAutoconfiguration(PropertyTypeExtractorInterface::class)
632633
->addTag('property_info.type_extractor');
634+
$container->registerForAutoconfiguration(ConstructorArgumentTypeExtractorInterface::class)
635+
->addTag('property_info.constructor_extractor');
633636
$container->registerForAutoconfiguration(PropertyDescriptionExtractorInterface::class)
634637
->addTag('property_info.description_extractor');
635638
$container->registerForAutoconfiguration(PropertyAccessExtractorInterface::class)
@@ -1936,26 +1939,32 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
19361939
}
19371940
}
19381941

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

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

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

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

19611970
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
@@ -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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ protected static function getBundleDefaultConfig()
706706
],
707707
'property_info' => [
708708
'enabled' => !class_exists(FullStack::class),
709+
'with_constructor_extractor' => false,
709710
],
710711
'router' => [
711712
'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
@@ -1627,6 +1627,14 @@ public function testPropertyInfoEnabled()
16271627
{
16281628
$container = $this->createContainerFromFile('property_info');
16291629
$this->assertTrue($container->has('property_info'));
1630+
$this->assertFalse($container->has('property_info.constructor_extractor'));
1631+
}
1632+
1633+
public function testPropertyInfoWithConstructorExtractorEnabled()
1634+
{
1635+
$container = $this->createContainerFromFile('property_info_with_constructor_extractor');
1636+
$this->assertTrue($container->has('property_info'));
1637+
$this->assertTrue($container->has('property_info.constructor_extractor'));
16301638
}
16311639

16321640
public function testPropertyInfoCacheActivated()

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

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