Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 31ef132

Browse filesBrowse files
committed
[FrameworkBundle][PropertyInfo] Wire the ConstructorExtractor class
1 parent 9d89e05 commit 31ef132
Copy full SHA for 31ef132

13 files changed

+72
-8
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CHANGELOG
2020
* Add the ability to use an existing service as a lock/semaphore resource
2121
* Add support for configuring multiple serializer instances via the configuration
2222
* Add support for `SYMFONY_TRUSTED_PROXIES`, `SYMFONY_TRUSTED_HEADERS`, `SYMFONY_TRUST_X_SENDFILE_TYPE_HEADER` and `SYMFONY_TRUSTED_HOSTS` env vars
23+
* Add new `framework.property_info.with_constructor_extractor` option to allow enabling or disabling the constructor extractor integration
2324

2425
7.1
2526
---

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

Copy file name to clipboardExpand all lines: 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+7
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,14 @@ private function addPropertyInfoSection(ArrayNodeDefinition $rootNode, callable
11991199
->children()
12001200
->arrayNode('property_info')
12011201
->info('Property info configuration')
1202+
->addDefaultsIfNotSet()
12021203
->{$enableIfStandalone('symfony/property-info', PropertyInfoExtractorInterface::class)}()
1204+
->children()
1205+
->booleanNode('with_constructor_extractor')
1206+
->info('Registers the constructor extractor.')
1207+
->defaultFalse()
1208+
->end()
1209+
->end()
12031210
->end()
12041211
->end()
12051212
;

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

Copy file name to clipboardExpand all lines: 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;
@@ -407,7 +408,7 @@ public function load(array $configs, ContainerBuilder $container): void
407408
}
408409

409410
if ($propertyInfoEnabled) {
410-
$this->registerPropertyInfoConfiguration($container, $loader);
411+
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader);
411412
}
412413

413414
if ($this->readConfigEnabled('lock', $container, $config['lock'])) {
@@ -631,6 +632,8 @@ public function load(array $configs, ContainerBuilder $container): void
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)
@@ -1960,26 +1963,32 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
19601963
$container->setParameter('.serializer.named_serializers', $config['named_serializers'] ?? []);
19611964
}
19621965

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

19691972
$loader->load('property_info.php');
19701973

1974+
if (!$config['with_constructor_extractor']) {
1975+
$container->removeDefinition('property_info.constructor_extractor');
1976+
}
1977+
19711978
if (
19721979
ContainerBuilder::willBeAvailable('phpstan/phpdoc-parser', PhpDocParser::class, ['symfony/framework-bundle', 'symfony/property-info'])
19731980
&& ContainerBuilder::willBeAvailable('phpdocumentor/type-resolver', ContextFactory::class, ['symfony/framework-bundle', 'symfony/property-info'])
19741981
) {
19751982
$definition = $container->register('property_info.phpstan_extractor', PhpStanExtractor::class);
19761983
$definition->addTag('property_info.type_extractor', ['priority' => -1000]);
1984+
$definition->addTag('property_info.constructor_extractor', ['priority' => -1000]);
19771985
}
19781986

19791987
if (ContainerBuilder::willBeAvailable('phpdocumentor/reflection-docblock', DocBlockFactoryInterface::class, ['symfony/framework-bundle', 'symfony/property-info'], true)) {
19801988
$definition = $container->register('property_info.php_doc_extractor', PhpDocExtractor::class);
19811989
$definition->addTag('property_info.description_extractor', ['priority' => -1000]);
19821990
$definition->addTag('property_info.type_extractor', ['priority' => -1001]);
1991+
$definition->addTag('property_info.constructor_extractor', ['priority' => -1001]);
19831992
}
19841993

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

‎src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Copy file name to clipboardExpand all lines: 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;
@@ -160,6 +161,7 @@ public function build(ContainerBuilder $container): void
160161
$container->addCompilerPass(new FragmentRendererPass());
161162
$this->addCompilerPassIfExists($container, SerializerPass::class);
162163
$this->addCompilerPassIfExists($container, PropertyInfoPass::class);
164+
$this->addCompilerPassIfExists($container, PropertyInfoConstructorPass::class);
163165
$container->addCompilerPass(new ControllerArgumentValueResolverPass());
164166
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);
165167
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/property_info.php

Copy file name to clipboardExpand all lines: 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
+1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@
358358

359359
<xsd:complexType name="property_info">
360360
<xsd:attribute name="enabled" type="xsd:boolean" />
361+
<xsd:attribute name="with-constructor-extractor" type="xsd:boolean" />
361362
</xsd:complexType>
362363

363364
<xsd:complexType name="cache">

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+1
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ protected static function getBundleDefaultConfig()
801801
],
802802
'property_info' => [
803803
'enabled' => !class_exists(FullStack::class),
804+
'with_constructor_extractor' => false,
804805
],
805806
'router' => [
806807
'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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php
+8
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,14 @@ public function testPropertyInfoEnabled()
16791679
{
16801680
$container = $this->createContainerFromFile('property_info');
16811681
$this->assertTrue($container->has('property_info'));
1682+
$this->assertFalse($container->has('property_info.constructor_extractor'));
1683+
}
1684+
1685+
public function testPropertyInfoWithConstructorExtractorEnabled()
1686+
{
1687+
$container = $this->createContainerFromFile('property_info_with_constructor_extractor');
1688+
$this->assertTrue($container->has('property_info'));
1689+
$this->assertTrue($container->has('property_info.constructor_extractor'));
16821690
}
16831691

16841692
public function testPropertyInfoCacheActivated()

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Extractor/ConstructorArgumentTypeExtractorInterface.php
-6
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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.