Repository navigation
Expand file tree
/
Copy pathPropertyInfoBundle.php
More file actions
110 lines (97 loc) · 4.92 KB
/
Copy pathPropertyInfoBundle.php
File metadata and controls
110 lines (97 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\PropertyInfo;
use phpDocumentor\Reflection\DocBlockFactoryInterface;
use phpDocumentor\Reflection\Types\ContextFactory;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Kernel\AbstractBundle;
use Symfony\Component\DependencyInjection\Kernel\RequiredBundle;
use Symfony\Component\DependencyInjection\Kernel\ServicesBundle;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoConstructorPass;
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
use Symfony\Component\PropertyInfo\DependencyInjection\RemovePropertyInfoCachePass;
use Symfony\Component\PropertyInfo\Extractor\ConstructorArgumentTypeExtractorInterface;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
/**
* Provides the property info services.
*/
#[RequiredBundle(ServicesBundle::class)]
class PropertyInfoBundle extends AbstractBundle
{
public function getPath(): string
{
return $this->path ??= __DIR__;
}
public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new PropertyInfoPass());
$container->addCompilerPass(new PropertyInfoConstructorPass());
$container->addCompilerPass(new RemovePropertyInfoCachePass());
}
public function configure(DefinitionConfigurator $definition): void
{
$definition->rootNode()
->info('Property info configuration')
->canBeDisabled()
->children()
->booleanNode('with_constructor_extractor')
->resolvesAtCompileTime()
->info('Registers the constructor extractor.')
->defaultTrue()
->end()
->end()
;
}
public function loadExtension(array $config, ContainerConfigurator $configurator, ContainerBuilder $container): void
{
if (!$config['enabled']) {
return;
}
$configurator->import('Resources/config/property_info.php');
$container->registerForAutoconfiguration(PropertyListExtractorInterface::class)
->addTag('property_info.list_extractor');
$container->registerForAutoconfiguration(PropertyTypeExtractorInterface::class)
->addTag('property_info.type_extractor');
$container->registerForAutoconfiguration(ConstructorArgumentTypeExtractorInterface::class)
->addTag('property_info.constructor_extractor');
$container->registerForAutoconfiguration(PropertyDescriptionExtractorInterface::class)
->addTag('property_info.description_extractor');
$container->registerForAutoconfiguration(PropertyAccessExtractorInterface::class)
->addTag('property_info.access_extractor');
$container->registerForAutoconfiguration(PropertyInitializableExtractorInterface::class)
->addTag('property_info.initializable_extractor');
if (!$config['with_constructor_extractor']) {
$container->removeDefinition('property_info.constructor_extractor');
}
if (
ContainerBuilder::willBeAvailable('phpstan/phpdoc-parser', PhpDocParser::class, ['symfony/framework-bundle', 'symfony/property-info'])
&& ContainerBuilder::willBeAvailable('phpdocumentor/type-resolver', ContextFactory::class, ['symfony/framework-bundle', 'symfony/property-info'])
) {
$container->register('property_info.phpstan_extractor', PhpStanExtractor::class)
->addTag('property_info.type_extractor', ['priority' => -1000])
->addTag('property_info.constructor_extractor', ['priority' => -1000]);
}
if (ContainerBuilder::willBeAvailable('phpdocumentor/reflection-docblock', DocBlockFactoryInterface::class, ['symfony/framework-bundle', 'symfony/property-info'])) {
$container->register('property_info.php_doc_extractor', PhpDocExtractor::class)
->addTag('property_info.description_extractor', ['priority' => -1000])
->addTag('property_info.type_extractor', ['priority' => -1001])
->addTag('property_info.constructor_extractor', ['priority' => -1001]);
}
if ($container->getParameter('kernel.debug')) {
$container->removeDefinition('property_info.cache');
$container->removeDefinition('property_info.cache.adapter');
$container->removeDefinition('property_info.cache_warmer');
}
}
}