10
10
11
11
namespace Sidus \EncryptionBundle \DependencyInjection ;
12
12
13
+ use Sidus \EncryptionBundle \Doctrine \Type \EncryptStringType ;
14
+ use Sidus \EncryptionBundle \Doctrine \Type \EncryptTextType ;
13
15
use Sidus \EncryptionBundle \Registry \EncryptionManagerRegistry ;
14
16
use Symfony \Component \DependencyInjection \ContainerBuilder ;
15
17
use Symfony \Component \Config \FileLocator ;
18
+ use Symfony \Component \DependencyInjection \Extension \PrependExtensionInterface ;
16
19
use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
17
20
use Symfony \Component \DependencyInjection \Loader ;
18
21
23
26
*
24
27
* @author Vincent Chalnot <[email protected] >
25
28
*/
26
- class SidusEncryptionExtension extends Extension
29
+ class SidusEncryptionExtension extends Extension implements PrependExtensionInterface
27
30
{
28
31
public function load (array $ configs , ContainerBuilder $ container ): void
29
32
{
30
33
$ loader = new Loader \YamlFileLoader ($ container , new FileLocator (__DIR__ .'/../Resources/config/services ' ));
31
34
$ loader ->load ('encryption.yml ' );
35
+ $ loader ->load ('doctrine.yml ' );
32
36
$ loader ->load ('registry.yml ' );
33
37
$ loader ->load ('security.yml ' );
34
38
$ loader ->load ('session.yml ' );
@@ -40,4 +44,22 @@ public function load(array $configs, ContainerBuilder $container): void
40
44
$ registry ->replaceArgument ('$defaultCode ' , $ config ['preferred_adapter ' ]);
41
45
$ container ->setParameter ('sidus.encryption.throw_exceptions ' , $ config ['throw_exception ' ]);
42
46
}
47
+
48
+ public function prepend (ContainerBuilder $ container )
49
+ {
50
+ $ doctrineConfiguration = $ container ->getExtensionConfig ('doctrine ' );
51
+
52
+ if (empty ($ doctrineConfiguration ['dbal ' ])) {
53
+ $ doctrineConfiguration ['dbal ' ] = [];
54
+ }
55
+
56
+ if (empty ($ doctrineConfiguration ['dbal ' ]['types ' ])) {
57
+ $ doctrineConfiguration ['dbal ' ]['types ' ] = [];
58
+ }
59
+ $ doctrineConfiguration ['dbal ' ]['types ' ] += [
60
+ 'encrypt_string ' => EncryptStringType::class,
61
+ 'encrypt_text ' => EncryptTextType::class
62
+ ];
63
+ $ container ->prependExtensionConfig ('doctrine ' , $ doctrineConfiguration );
64
+ }
43
65
}
0 commit comments