|
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\Bridge\Doctrine\DBAL\Types\TypesDumper; |
|
14
|
|
|
use Elao\Enum\Bridge\Symfony\HttpKernel\Controller\ArgumentResolver\EnumValueResolver; |
|
15
|
|
|
use Elao\Enum\Bridge\Symfony\Serializer\Normalizer\EnumNormalizer; |
|
16
|
|
|
use Symfony\Component\Config\FileLocator; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
20
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
21
|
|
|
|
|
22
|
|
|
class ElaoEnumExtension extends Extension implements PrependExtensionInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public function prepend(ContainerBuilder $container) |
|
25
|
|
|
{ |
|
26
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
|
27
|
|
|
if (!isset($bundles['DoctrineBundle'])) { |
|
28
|
|
|
return; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$configs = $container->getExtensionConfig($this->getAlias()); |
|
32
|
|
|
$config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs); |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
if (!($types = $config['doctrine']['types'] ?? false)) { |
|
35
|
|
|
return; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$doctrineTypesConfig = []; |
|
39
|
|
|
foreach ($types as $class => $value) { |
|
40
|
|
|
$doctrineTypesConfig[$value['name']] = TypesDumper::getTypeClassname($class); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$container->prependExtensionConfig('doctrine', [ |
|
44
|
|
|
'dbal' => [ |
|
45
|
|
|
'types' => $doctrineTypesConfig, |
|
46
|
|
|
], |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
51
|
|
|
{ |
|
52
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
|
53
|
|
|
$loader->load('services.xml'); |
|
54
|
|
|
|
|
55
|
|
|
$config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
if (!$this->isConfigEnabled($container, $config['argument_value_resolver'])) { |
|
58
|
|
|
$container->removeDefinition(EnumValueResolver::class); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (!$this->isConfigEnabled($container, $config['serializer'])) { |
|
62
|
|
|
$container->removeDefinition(EnumNormalizer::class); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if ($types = $config['doctrine']['types'] ?? false) { |
|
66
|
|
|
$container->setParameter('.elao_enum.doctrine_types', array_map(static function (string $k, array $v): array { |
|
67
|
|
|
return [$k, $v['type'], $v['name']]; |
|
68
|
|
|
}, array_keys($types), $types)); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function getNamespace() |
|
73
|
|
|
{ |
|
74
|
|
|
return 'http://elao.com/schema/dic/elao_enum'; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getXsdValidationBasePath() |
|
78
|
|
|
{ |
|
79
|
|
|
return __DIR__ . '/../Resources/config/schema'; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: