Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

Commit24ccbc5

Browse files
mtarldKorbeil
andcommitted
[TypeInfo] Introduce component
Co-authored-by: Baptiste Leduc <baptiste.leduc@gmail.com>
1 parent7269a3d commit24ccbc5

File tree

78 files changed

+4283
-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

+4283
-0
lines changed

‎composer.json

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
useSymfony\Component\Serializer\Encoder\JsonDecode;
4545
useSymfony\Component\Serializer\Serializer;
4646
useSymfony\Component\Translation\Translator;
47+
useSymfony\Component\TypeInfo\Type;
4748
useSymfony\Component\Uid\Factory\UuidFactory;
4849
useSymfony\Component\Validator\Validation;
4950
useSymfony\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+
privatefunctionaddTypeInfoSection(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
privatefunctionaddCacheSection(ArrayNodeDefinition$rootNode,callable$willBeAvailable):void
11661180
{
11671181
$rootNode

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
useSymfony\Component\Console\Debug\CliRequest;
5454
useSymfony\Component\Console\Messenger\RunCommandMessageHandler;
5555
useSymfony\Component\DependencyInjection\Alias;
56+
useSymfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
5657
useSymfony\Component\DependencyInjection\ChildDefinition;
5758
useSymfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
5859
useSymfony\Component\DependencyInjection\ContainerBuilder;
@@ -167,6 +168,8 @@
167168
useSymfony\Component\Translation\LocaleSwitcher;
168169
useSymfony\Component\Translation\PseudoLocalizationTranslator;
169170
useSymfony\Component\Translation\Translator;
171+
useSymfony\Component\TypeInfo\Type;
172+
useSymfony\Component\TypeInfo\TypeResolver\StringTypeResolver;
170173
useSymfony\Component\Uid\Factory\UuidFactory;
171174
useSymfony\Component\Uid\UuidV4;
172175
useSymfony\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+
privatefunctionregisterTypeInfoConfiguration(ContainerBuilder$container,PhpFileLoader$loader):void
1964+
{
1965+
if (!class_exists(Type::class)) {
1966+
thrownewLogicException('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' =>newReference('type_info.resolver.string'),
1978+
]);
1979+
}
1980+
}
1981+
19561982
privatefunctionregisterLockConfiguration(array$config,ContainerBuilder$container,PhpFileLoader$loader):void
19571983
{
19581984
$loader->load('lock.php');

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

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

331+
<xsd:complexTypename="type_info">
332+
<xsd:attributename="enabled"type="xsd:boolean" />
333+
</xsd:complexType>
334+
330335
<xsd:complexTypename="property_info">
331336
<xsd:attributename="enabled"type="xsd:boolean" />
332337
</xsd:complexType>
Lines changed: 50 additions & 0 deletions
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 <fabien@symfony.com>
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+
namespaceSymfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
useSymfony\Component\TypeInfo\TypeContext\TypeContextFactory;
15+
useSymfony\Component\TypeInfo\TypeResolver\ReflectionParameterTypeResolver;
16+
useSymfony\Component\TypeInfo\TypeResolver\ReflectionPropertyTypeResolver;
17+
useSymfony\Component\TypeInfo\TypeResolver\ReflectionReturnTypeResolver;
18+
useSymfony\Component\TypeInfo\TypeResolver\ReflectionTypeResolver;
19+
useSymfony\Component\TypeInfo\TypeResolver\TypeResolver;
20+
useSymfony\Component\TypeInfo\TypeResolver\TypeResolverInterface;
21+
22+
returnstaticfunction (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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
useSymfony\Component\RateLimiter\Policy\TokenBucketLimiter;
2929
useSymfony\Component\Scheduler\Messenger\SchedulerTransportFactory;
3030
useSymfony\Component\Serializer\Encoder\JsonDecode;
31+
useSymfony\Component\TypeInfo\Type;
3132
useSymfony\Component\Uid\Factory\UuidFactory;
3233

3334
class ConfigurationTestextends 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

Lines changed: 1 addition & 0 deletions
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' => [
Lines changed: 11 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<containerxmlns="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:confighttp-method-override="false"handle-all-throwables="true">
9+
<framework:annotationsenabled="false" />
10+
<framework:php-errorslog="true" />
11+
<framework:type-infoenabled="true" />
12+
</framework:config>
13+
</container>

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

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

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

1619+
publicfunctiontestTypeInfoEnabled()
1620+
{
1621+
$container =$this->createContainerFromFile('type_info');
1622+
$this->assertTrue($container->has('type_info.resolver'));
1623+
}
1624+
16191625
publicfunctiontestPropertyInfoEnabled()
16201626
{
16211627
$container =$this->createContainerFromFile('property_info');
Lines changed: 32 additions & 0 deletions
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 <fabien@symfony.com>
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+
namespaceSymfony\Bundle\FrameworkBundle\Tests\Functional;
13+
14+
usePHPStan\PhpDocParser\Parser\PhpDocParser;
15+
useSymfony\Bundle\FrameworkBundle\Tests\Functional\app\TypeInfo\Dummy;
16+
useSymfony\Component\TypeInfo\Type;
17+
18+
class TypeInfoTestextends AbstractWebTestCase
19+
{
20+
publicfunctiontestComponent()
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+
}
Lines changed: 21 additions & 0 deletions
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 <fabien@symfony.com>
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+
namespaceSymfony\Bundle\FrameworkBundle\Tests\Functional\app\TypeInfo;
13+
14+
/**
15+
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
16+
* @author Baptiste Leduc <baptiste.leduc@gmail.com>
17+
*/
18+
class Dummy
19+
{
20+
publicstring$name;
21+
}
Lines changed: 18 additions & 0 deletions
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 <fabien@symfony.com>
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+
useSymfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
useSymfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
14+
15+
return [
16+
newFrameworkBundle(),
17+
newTestBundle(),
18+
];
Lines changed: 11 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/Testsexport-ignore
2+
/phpunit.xml.distexport-ignore
3+
/.gitattributesexport-ignore
4+
/.gitignoreexport-ignore
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
Lines changed: 7 additions & 0 deletions
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
Lines changed: 20 additions & 0 deletions
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 <fabien@symfony.com>
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+
namespaceSymfony\Component\TypeInfo\Exception;
13+
14+
/**
15+
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
16+
* @author Baptiste Leduc <baptiste.leduc@gmail.com>
17+
*/
18+
interface ExceptionInterfaceextends \Throwable
19+
{
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp