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

Skip to content

Commit 6de7d7d

Browse files
mtarldKorbeil
andcommitted
[TypeInfo] Introduce component
Co-authored-by: Baptiste Leduc <[email protected]>
1 parent b004c3c commit 6de7d7d

File tree

78 files changed

+4295
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4295
-0
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"symfony/translation": "self.version",
110110
"symfony/twig-bridge": "self.version",
111111
"symfony/twig-bundle": "self.version",
112+
"symfony/type-info": "self.version",
112113
"symfony/uid": "self.version",
113114
"symfony/validator": "self.version",
114115
"symfony/var-dumper": "self.version",

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

+14
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use Symfony\Component\Serializer\Encoder\JsonDecode;
4545
use Symfony\Component\Serializer\Serializer;
4646
use Symfony\Component\Translation\Translator;
47+
use Symfony\Component\TypeInfo\Type;
4748
use Symfony\Component\Uid\Factory\UuidFactory;
4849
use Symfony\Component\Validator\Validation;
4950
use Symfony\Component\Webhook\Controller\WebhookController;
@@ -164,6 +165,7 @@ public function getConfigTreeBuilder(): TreeBuilder
164165
$this->addAnnotationsSection($rootNode);
165166
$this->addSerializerSection($rootNode, $enableIfStandalone);
166167
$this->addPropertyAccessSection($rootNode, $willBeAvailable);
168+
$this->addTypeInfoSection($rootNode, $enableIfStandalone);
167169
$this->addPropertyInfoSection($rootNode, $enableIfStandalone);
168170
$this->addCacheSection($rootNode, $willBeAvailable);
169171
$this->addPhpErrorsSection($rootNode);
@@ -1162,6 +1164,18 @@ private function addPropertyInfoSection(ArrayNodeDefinition $rootNode, callable
11621164
;
11631165
}
11641166

1167+
private function addTypeInfoSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone): void
1168+
{
1169+
$rootNode
1170+
->children()
1171+
->arrayNode('type_info')
1172+
->info('Type info configuration')
1173+
->{$enableIfStandalone('symfony/type-info', Type::class)}()
1174+
->end()
1175+
->end()
1176+
;
1177+
}
1178+
11651179
private function addCacheSection(ArrayNodeDefinition $rootNode, callable $willBeAvailable): void
11661180
{
11671181
$rootNode

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

+26
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
use Symfony\Component\Console\Debug\CliRequest;
5454
use Symfony\Component\Console\Messenger\RunCommandMessageHandler;
5555
use Symfony\Component\DependencyInjection\Alias;
56+
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
5657
use Symfony\Component\DependencyInjection\ChildDefinition;
5758
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
5859
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -167,6 +168,8 @@
167168
use Symfony\Component\Translation\LocaleSwitcher;
168169
use Symfony\Component\Translation\PseudoLocalizationTranslator;
169170
use Symfony\Component\Translation\Translator;
171+
use Symfony\Component\TypeInfo\Type;
172+
use Symfony\Component\TypeInfo\TypeResolver\StringTypeResolver;
170173
use Symfony\Component\Uid\Factory\UuidFactory;
171174
use Symfony\Component\Uid\UuidV4;
172175
use Symfony\Component\Validator\Constraints\ExpressionLanguageProvider;
@@ -388,6 +391,10 @@ public function load(array $configs, ContainerBuilder $container): void
388391
$container->removeDefinition('console.command.serializer_debug');
389392
}
390393

394+
if ($this->readConfigEnabled('type_info', $container, $config['type_info'])) {
395+
$this->registerTypeInfoConfiguration($container, $loader);
396+
}
397+
391398
if ($propertyInfoEnabled) {
392399
$this->registerPropertyInfoConfiguration($container, $loader);
393400
}
@@ -1953,6 +1960,25 @@ private function registerPropertyInfoConfiguration(ContainerBuilder $container,
19531960
}
19541961
}
19551962

1963+
private function registerTypeInfoConfiguration(ContainerBuilder $container, PhpFileLoader $loader): void
1964+
{
1965+
if (!class_exists(Type::class)) {
1966+
throw new LogicException('TypeInfo support cannot be enabled as the TypeInfo component is not installed. Try running "composer require symfony/type-info".');
1967+
}
1968+
1969+
$loader->load('type_info.php');
1970+
1971+
if (ContainerBuilder::willBeAvailable('phpstan/phpdoc-parser', PhpDocParser::class, ['symfony/framework-bundle', 'symfony/type-info'])) {
1972+
$container->register('type_info.resolver.string', StringTypeResolver::class);
1973+
1974+
/** @var ServiceLocatorArgument $resolversLocator */
1975+
$resolversLocator = $container->getDefinition('type_info.resolver')->getArgument(0);
1976+
$resolversLocator->setValues($resolversLocator->getValues() + [
1977+
'string' => new Reference('type_info.resolver.string'),
1978+
]);
1979+
}
1980+
}
1981+
19561982
private function registerLockConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
19571983
{
19581984
$loader->load('lock.php');

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<xsd:element name="property-access" type="property_access" minOccurs="0" maxOccurs="1" />
2828
<xsd:element name="scheduler" type="scheduler" minOccurs="0" maxOccurs="1" />
2929
<xsd:element name="serializer" type="serializer" minOccurs="0" maxOccurs="1" />
30+
<xsd:element name="type-info" type="type_info" minOccurs="0" maxOccurs="1" />
3031
<xsd:element name="property-info" type="property_info" minOccurs="0" maxOccurs="1" />
3132
<xsd:element name="cache" type="cache" minOccurs="0" maxOccurs="1" />
3233
<xsd:element name="workflow" type="workflow" minOccurs="0" maxOccurs="unbounded" />
@@ -327,6 +328,10 @@
327328
<xsd:attribute name="max-depth-handler" type="xsd:string" />
328329
</xsd:complexType>
329330

331+
<xsd:complexType name="type_info">
332+
<xsd:attribute name="enabled" type="xsd:boolean" />
333+
</xsd:complexType>
334+
330335
<xsd:complexType name="property_info">
331336
<xsd:attribute name="enabled" type="xsd:boolean" />
332337
</xsd:complexType>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\TypeInfo\TypeContext\TypeContextFactory;
15+
use Symfony\Component\TypeInfo\TypeResolver\ReflectionParameterTypeResolver;
16+
use Symfony\Component\TypeInfo\TypeResolver\ReflectionPropertyTypeResolver;
17+
use Symfony\Component\TypeInfo\TypeResolver\ReflectionReturnTypeResolver;
18+
use Symfony\Component\TypeInfo\TypeResolver\ReflectionTypeResolver;
19+
use Symfony\Component\TypeInfo\TypeResolver\TypeResolver;
20+
use Symfony\Component\TypeInfo\TypeResolver\TypeResolverInterface;
21+
22+
return static function (ContainerConfigurator $container) {
23+
$container->services()
24+
// type context
25+
->set('type_info.type_context_factory', TypeContextFactory::class)
26+
->args([service('type_info.resolver.string')->nullOnInvalid()])
27+
28+
// type resolvers
29+
->set('type_info.resolver', TypeResolver::class)
30+
->args([service_locator([
31+
\ReflectionType::class => service('type_info.resolver.reflection_type'),
32+
\ReflectionParameter::class => service('type_info.resolver.reflection_parameter'),
33+
\ReflectionProperty::class => service('type_info.resolver.reflection_property'),
34+
\ReflectionFunctionAbstract::class => service('type_info.resolver.reflection_return'),
35+
])])
36+
->alias(TypeResolverInterface::class, 'type_info.resolver')
37+
38+
->set('type_info.resolver.reflection_type', ReflectionTypeResolver::class)
39+
->args([service('type_info.type_context_factory')])
40+
41+
->set('type_info.resolver.reflection_parameter', ReflectionParameterTypeResolver::class)
42+
->args([service('type_info.resolver.reflection_type'), service('type_info.type_context_factory')])
43+
44+
->set('type_info.resolver.reflection_property', ReflectionPropertyTypeResolver::class)
45+
->args([service('type_info.resolver.reflection_type'), service('type_info.type_context_factory')])
46+
47+
->set('type_info.resolver.reflection_return', ReflectionReturnTypeResolver::class)
48+
->args([service('type_info.resolver.reflection_type'), service('type_info.type_context_factory')])
49+
;
50+
};

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

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Symfony\Component\RateLimiter\Policy\TokenBucketLimiter;
2929
use Symfony\Component\Scheduler\Messenger\SchedulerTransportFactory;
3030
use Symfony\Component\Serializer\Encoder\JsonDecode;
31+
use Symfony\Component\TypeInfo\Type;
3132
use Symfony\Component\Uid\Factory\UuidFactory;
3233

3334
class ConfigurationTest extends TestCase
@@ -624,6 +625,9 @@ protected static function getBundleDefaultConfig()
624625
'throw_exception_on_invalid_index' => false,
625626
'throw_exception_on_invalid_property_path' => true,
626627
],
628+
'type_info' => [
629+
'enabled' => !class_exists(FullStack::class) && class_exists(Type::class),
630+
],
627631
'property_info' => [
628632
'enabled' => !class_exists(FullStack::class),
629633
],

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
'default_context' => ['enable_max_depth' => true],
7171
],
7272
'property_info' => true,
73+
'type_info' => true,
7374
'ide' => 'file%%link%%format',
7475
'request' => [
7576
'formats' => [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
'type_info' => [
9+
'enabled' => true,
10+
],
11+
]);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml

+1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@
4040
</framework:default-context>
4141
</framework:serializer>
4242
<framework:property-info />
43+
<framework:type-info />
4344
</framework:config>
4445
</container>
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:type-info enabled="true" />
12+
</framework:config>
13+
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ framework:
5959
max_depth_handler: my.max.depth.handler
6060
default_context:
6161
enable_max_depth: true
62+
type_info: ~
6263
property_info: ~
6364
ide: file%%link%%format
6465
request:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
framework:
2+
annotations: false
3+
http_method_override: false
4+
handle_all_throwables: true
5+
php_errors:
6+
log: true
7+
type_info:
8+
enabled: true

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

+6
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,12 @@ public function testSerializerServiceIsNotRegisteredWhenDisabled()
16161616
$this->assertFalse($container->hasDefinition('serializer'));
16171617
}
16181618

1619+
public function testTypeInfoEnabled()
1620+
{
1621+
$container = $this->createContainerFromFile('type_info');
1622+
$this->assertTrue($container->has('type_info.resolver'));
1623+
}
1624+
16191625
public function testPropertyInfoEnabled()
16201626
{
16211627
$container = $this->createContainerFromFile('property_info');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
13+
14+
use PHPStan\PhpDocParser\Parser\PhpDocParser;
15+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\app\TypeInfo\Dummy;
16+
use Symfony\Component\TypeInfo\Type;
17+
18+
class TypeInfoTest extends AbstractWebTestCase
19+
{
20+
public function testComponent()
21+
{
22+
static::bootKernel(['test_case' => 'TypeInfo']);
23+
24+
$this->assertEquals(Type::string(), static::getContainer()->get('type_info.resolver')->resolve(new \ReflectionProperty(Dummy::class, 'name')));
25+
26+
if (!class_exists(PhpDocParser::class)) {
27+
$this->markTestSkipped('"phpstan/phpdoc-parser" dependency is required.');
28+
}
29+
30+
$this->assertEquals(Type::int(), static::getContainer()->get('type_info.resolver')->resolve('int'));
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\app\TypeInfo;
13+
14+
/**
15+
* @author Mathias Arlaud <[email protected]>
16+
* @author Baptiste Leduc <[email protected]>
17+
*/
18+
class Dummy
19+
{
20+
public string $name;
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
14+
15+
return [
16+
new FrameworkBundle(),
17+
new TestBundle(),
18+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
imports:
2+
- { resource: ../config/default.yml }
3+
4+
framework:
5+
http_method_override: false
6+
type_info: true
7+
8+
services:
9+
type_info.resolver.alias:
10+
alias: type_info.resolver
11+
public: true

src/Symfony/Bundle/FrameworkBundle/composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"symfony/string": "^6.4|^7.0",
6565
"symfony/translation": "^6.4|^7.0",
6666
"symfony/twig-bundle": "^6.4|^7.0",
67+
"symfony/type-info": "^7.1",
6768
"symfony/validator": "^6.4|^7.0",
6869
"symfony/workflow": "^6.4|^7.0",
6970
"symfony/yaml": "^6.4|^7.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/Tests export-ignore
2+
/phpunit.xml.dist export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
7.1
5+
---
6+
7+
* Add the component
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\TypeInfo\Exception;
13+
14+
/**
15+
* @author Mathias Arlaud <[email protected]>
16+
* @author Baptiste Leduc <[email protected]>
17+
*/
18+
interface ExceptionInterface extends \Throwable
19+
{
20+
}

0 commit comments

Comments
 (0)