|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the "elao/enum" package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) Elao |
|
7
|
|
|
* |
|
8
|
|
|
* @author Elao <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Elao\Enum\Bridge\Symfony\Bundle\DependencyInjection; |
|
12
|
|
|
|
|
13
|
|
|
use Elao\Enum\EnumInterface; |
|
14
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
15
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
16
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
|
17
|
|
|
|
|
18
|
|
|
class Configuration implements ConfigurationInterface |
|
19
|
|
|
{ |
|
20
|
|
|
public function getConfigTreeBuilder() |
|
21
|
|
|
{ |
|
22
|
|
|
$treeBuilder = new TreeBuilder('elao_enum'); |
|
23
|
|
|
$rootNode = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('elao_enum'); |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
$rootNode->children() |
|
26
|
|
|
->arrayNode('argument_value_resolver')->canBeDisabled()->end() |
|
27
|
|
|
->arrayNode('doctrine') |
|
28
|
|
|
->fixXmlConfig('type') |
|
29
|
|
|
->children() |
|
30
|
|
|
->arrayNode('types') |
|
31
|
|
|
->validate() |
|
32
|
|
|
->ifTrue(static function (array $v): bool { |
|
33
|
|
|
$classes = array_keys($v); |
|
34
|
|
|
foreach ($classes as $class) { |
|
35
|
|
|
if (!is_a($class, EnumInterface::class, true)) { |
|
36
|
|
|
return true; |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
return false; |
|
41
|
|
|
}) |
|
42
|
|
|
->then(static function (array $v) { |
|
43
|
|
|
$classes = array_keys($v); |
|
44
|
|
|
$invalids = []; |
|
45
|
|
|
foreach ($classes as $class) { |
|
46
|
|
|
if (!is_a($class, EnumInterface::class, true)) { |
|
47
|
|
|
$invalids[] = $class; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
throw new \InvalidArgumentException(sprintf( |
|
52
|
|
|
'Invalid classes %s. Expected instances of "%s"', |
|
53
|
|
|
json_encode($invalids), |
|
54
|
|
|
EnumInterface::class) |
|
55
|
|
|
); |
|
56
|
|
|
}) |
|
57
|
|
|
->end() |
|
58
|
|
|
->useAttributeAsKey('class') |
|
59
|
|
|
->arrayPrototype() |
|
60
|
|
|
->beforeNormalization() |
|
61
|
|
|
->ifString()->then(static function (string $v): array { return ['name' => $v]; }) |
|
62
|
|
|
->end() |
|
63
|
|
|
->children() |
|
64
|
|
|
->scalarNode('name')->cannotBeEmpty()->end() |
|
65
|
|
|
->enumNode('type')->values(['string', 'int'])->cannotBeEmpty()->defaultValue('string')->end() |
|
66
|
|
|
->end() |
|
67
|
|
|
->end() |
|
68
|
|
|
->end() |
|
69
|
|
|
->end() |
|
70
|
|
|
->end() |
|
71
|
|
|
->arrayNode('serializer') |
|
72
|
|
|
->{interface_exists(SerializerInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}() |
|
73
|
|
|
->end() |
|
74
|
|
|
->end(); |
|
75
|
|
|
|
|
76
|
|
|
return $treeBuilder; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.