Skip to content

Commit e9a3bca

Browse files
committed
Add basic symfony bundle
1 parent 8be45c2 commit e9a3bca

File tree

5 files changed

+895
-1
lines changed

5 files changed

+895
-1
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"symfony/stopwatch": "^6.4|^7.0",
4343
"symfony/var-dumper": "^6.4|^7.0",
4444
"symfony/yaml": "^6.4|^7.0",
45+
"symfony/framework-bundle": "^6.4|^7.0",
4546
"type-lang/phpdoc": "^1.0",
4647
"type-lang/phpdoc-standard-tags": "^1.0"
4748
},
@@ -56,7 +57,9 @@
5657
"nette/neon": "(^3.0) Required for NEON mapping configuration files",
5758
"symfony/yaml": "(^6.4|^7.0) Required for YAML mapping configuration files",
5859
"type-lang/phpdoc-standard-tags": "(^1.0) Required for PhpDoc mapping configuration",
59-
"justinrainbow/json-schema": "(^6.0) Required for file-based configuration validation"
60+
"justinrainbow/json-schema": "(^6.0) Required for file-based configuration validation",
61+
"symfony/framework-bundle": "(^6.4|^7.0) Required for the Symfony Bundle support (see: ./Extension/Symfony/)",
62+
"phpstan/phpstan": "(^2.1) Required for PHPStan Extension support (see: ./Extension/PHPStan/)"
6063
},
6164
"extra": {
6265
"branch-alias": {
Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Extension\Symfony\DependencyInjection;
6+
7+
use Psr\Log\LoggerInterface;
8+
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
9+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
10+
use Symfony\Component\Config\Definition\ConfigurationInterface;
11+
use TypeLang\Mapper\Kernel\Extractor\Factory\DefaultTypeExtractorFactory;
12+
use TypeLang\Mapper\Kernel\Parser\Factory\DefaultTypeParserFactory;
13+
use TypeLang\Mapper\Kernel\Repository\Factory\DefaultTypeRepositoryFactory;
14+
use TypeLang\Mapper\Kernel\Tracing\TracerInterface;
15+
use TypeLang\Mapper\Mapping\Reader\PhpDocReader;
16+
use TypeLang\Mapper\Mapping\Reader\YamlConfigReader;
17+
use TypeLang\Printer\PrinterInterface;
18+
19+
final class TypeLangConfiguration implements ConfigurationInterface
20+
{
21+
public function getConfigTreeBuilder(): TreeBuilder
22+
{
23+
$tree = new TreeBuilder('type_lang');
24+
25+
$root = $tree->getRootNode();
26+
27+
/** @phpstan-ignore-next-line : Known Symfony's issue */
28+
$config = $root->children();
29+
30+
/** @phpstan-ignore-next-line : Known Symfony's issue */
31+
$config = $this->withLoggerConfiguration($config);
32+
$config = $this->withTracingConfiguration($config);
33+
$config = $this->withMemoizationConfiguration($config);
34+
$config = $this->withCacheConfiguration($config);
35+
$config = $this->withMetadataConfiguration($config);
36+
$config = $this->withTypesConfiguration($config);
37+
$config = $this->withTypeCoercionsConfiguration($config);
38+
39+
/** @phpstan-ignore-next-line : Known Symfony's issue */
40+
$config
41+
->booleanNode('object_as_array')
42+
->defaultNull()
43+
->end()
44+
->booleanNode('strict_types')
45+
->defaultNull()
46+
->end()
47+
->end();
48+
49+
return $tree;
50+
}
51+
52+
private function withTypesConfiguration(NodeBuilder $config): NodeBuilder
53+
{
54+
/** @phpstan-ignore-next-line : Known Symfony's issue */
55+
return $config->arrayNode('types')
56+
->stringPrototype()
57+
->cannotBeEmpty()
58+
->end()
59+
->defaultValue([])
60+
->end();
61+
}
62+
63+
private function withTypeCoercionsConfiguration(NodeBuilder $config): NodeBuilder
64+
{
65+
/** @phpstan-ignore-next-line : Known Symfony's issue */
66+
return $config->arrayNode('coercions')
67+
->stringPrototype()
68+
->cannotBeEmpty()
69+
->end()
70+
->useAttributeAsKey('type')
71+
->defaultValue([])
72+
->end();
73+
}
74+
75+
private function withMetadataConfiguration(NodeBuilder $config): NodeBuilder
76+
{
77+
/** @phpstan-ignore-next-line : Known Symfony's issue */
78+
return $config->arrayNode('meta')
79+
->children()
80+
->arrayNode('attributes')
81+
->children()
82+
->booleanNode('enabled')
83+
->defaultValue(null)
84+
->end()
85+
->end()
86+
->addDefaultsIfNotSet()
87+
->end()
88+
->arrayNode('phpdoc')
89+
->children()
90+
->booleanNode('enabled')
91+
->defaultValue(null)
92+
->end()
93+
->stringNode('param_tag_name')
94+
->defaultValue(PhpDocReader::DEFAULT_PARAM_TAG_NAME)
95+
->cannotBeEmpty()
96+
->end()
97+
->stringNode('var_tag_name')
98+
->defaultValue(PhpDocReader::DEFAULT_VAR_TAG_NAME)
99+
->cannotBeEmpty()
100+
->end()
101+
->stringNode('return_tag_name')
102+
->defaultValue(PhpDocReader::DEFAULT_RETURN_TAG_NAME)
103+
->cannotBeEmpty()
104+
->end()
105+
->end()
106+
->addDefaultsIfNotSet()
107+
->end()
108+
->arrayNode('yaml')
109+
->children()
110+
->booleanNode('enabled')
111+
->defaultValue(null)
112+
->end()
113+
->arrayNode('directories')
114+
->stringPrototype()
115+
->cannotBeEmpty()
116+
->end()
117+
->defaultValue(['%kernel.project_dir%/config/mapper'])
118+
->end()
119+
->arrayNode('extensions')
120+
->stringPrototype()
121+
->cannotBeEmpty()
122+
->end()
123+
->defaultValue(YamlConfigReader::DEFAULT_YAML_FILE_EXTENSIONS)
124+
->end()
125+
->end()
126+
->addDefaultsIfNotSet()
127+
->end()
128+
->end()
129+
->addDefaultsIfNotSet()
130+
->end();
131+
}
132+
133+
private function withCacheConfiguration(NodeBuilder $config): NodeBuilder
134+
{
135+
/** @phpstan-ignore-next-line : Known Symfony's issue */
136+
return $config->arrayNode('cache')
137+
->children()
138+
->booleanNode('enabled')
139+
->defaultNull()
140+
->end()
141+
->stringNode('service')
142+
->defaultValue('cache.app')
143+
->cannotBeEmpty()
144+
->end()
145+
->enumNode('driver')
146+
->values(['psr6', 'psr16'])
147+
->cannotBeEmpty()
148+
->defaultValue('psr6')
149+
->end()
150+
->stringNode('prefix')
151+
->defaultValue('tlm_')
152+
->end()
153+
->integerNode('ttl')
154+
->defaultNull()
155+
->end()
156+
->end()
157+
->addDefaultsIfNotSet()
158+
->end();
159+
}
160+
161+
private function withMemoizationConfiguration(NodeBuilder $config): NodeBuilder
162+
{
163+
/** @phpstan-ignore-next-line : Known Symfony's issue */
164+
return $config->arrayNode('memoization')
165+
->children()
166+
->arrayNode('parser')
167+
->children()
168+
->booleanNode('enabled')
169+
->defaultNull()
170+
->end()
171+
->integerNode('min_types')
172+
->defaultValue(DefaultTypeParserFactory::DEFAULT_MIN_IN_MEMORY_TYPES)
173+
->min(0)
174+
->end()
175+
->integerNode('max_types')
176+
->defaultValue(DefaultTypeParserFactory::DEFAULT_MAX_IN_MEMORY_TYPES)
177+
->min(1)
178+
->end()
179+
->end()
180+
->addDefaultsIfNotSet()
181+
->end()
182+
->end()
183+
->children()
184+
->arrayNode('types')
185+
->children()
186+
->booleanNode('enabled')
187+
->defaultNull()
188+
->end()
189+
->end()
190+
->addDefaultsIfNotSet()
191+
->end()
192+
->end()
193+
->children()
194+
->arrayNode('meta')
195+
->children()
196+
->booleanNode('enabled')
197+
->defaultNull()
198+
->end()
199+
->end()
200+
->addDefaultsIfNotSet()
201+
->end()
202+
->end()
203+
->addDefaultsIfNotSet()
204+
->end();
205+
}
206+
207+
private function withTracingConfiguration(NodeBuilder $config): NodeBuilder
208+
{
209+
/** @phpstan-ignore-next-line : Known Symfony's issue */
210+
return $config->arrayNode('tracing')
211+
->children()
212+
->booleanNode('enabled')
213+
->defaultNull()
214+
->end()
215+
->stringNode('service')
216+
->defaultValue(TracerInterface::class)
217+
->cannotBeEmpty()
218+
->end()
219+
->stringNode('printer')
220+
->defaultValue(PrinterInterface::class)
221+
->cannotBeEmpty()
222+
->end()
223+
->booleanNode('trace_type_extraction')
224+
->defaultValue(DefaultTypeExtractorFactory::DEFAULT_TRACING_OPTION)
225+
->end()
226+
->booleanNode('trace_type_parse')
227+
->defaultValue(DefaultTypeParserFactory::DEFAULT_TRACING_OPTION)
228+
->end()
229+
->booleanNode('trace_type_fetch')
230+
->defaultValue(DefaultTypeRepositoryFactory::DEFAULT_TRACING_OPTION)
231+
->end()
232+
->booleanNode('trace_type_cast')
233+
->defaultValue(DefaultTypeRepositoryFactory::DEFAULT_TYPE_CAST_TRACING_OPTION)
234+
->end()
235+
->booleanNode('trace_type_match')
236+
->defaultValue(DefaultTypeRepositoryFactory::DEFAULT_TYPE_MATCH_TRACING_OPTION)
237+
->end()
238+
->end()
239+
->addDefaultsIfNotSet()
240+
->end();
241+
}
242+
243+
private function withLoggerConfiguration(NodeBuilder $config): NodeBuilder
244+
{
245+
/** @phpstan-ignore-next-line : Known Symfony's issue */
246+
return $config->arrayNode('logger')
247+
->children()
248+
->booleanNode('enabled')
249+
->defaultNull()
250+
->end()
251+
->stringNode('service')
252+
->defaultValue(LoggerInterface::class)
253+
->cannotBeEmpty()
254+
->end()
255+
->booleanNode('log_type_extraction')
256+
->defaultValue(DefaultTypeExtractorFactory::DEFAULT_LOGGING_OPTION)
257+
->end()
258+
->booleanNode('log_type_parse')
259+
->defaultValue(DefaultTypeParserFactory::DEFAULT_LOGGING_OPTION)
260+
->end()
261+
->booleanNode('log_type_fetch')
262+
->defaultValue(DefaultTypeRepositoryFactory::DEFAULT_LOGGING_OPTION)
263+
->end()
264+
->booleanNode('log_type_cast')
265+
->defaultValue(DefaultTypeRepositoryFactory::DEFAULT_TYPE_CAST_LOGGING_OPTION)
266+
->end()
267+
->booleanNode('log_type_match')
268+
->defaultValue(DefaultTypeRepositoryFactory::DEFAULT_TYPE_MATCH_LOGGING_OPTION)
269+
->end()
270+
->end()
271+
->addDefaultsIfNotSet()
272+
->end();
273+
}
274+
}

0 commit comments

Comments
 (0)