@@ -30,68 +30,11 @@ public static function initDomain(ContainerBuilder $container): void
30
30
return ;
31
31
}
32
32
33
- if (class_exists (ConsoleEvents::class)) {
34
- $ container ->register (ConsoleInfra \Context \ClassContextFactory::class)
35
- ->setPublic (false )
36
- ->setAbstract (true )
37
- ->setAutowired (true )
38
- ->setArgument ('$method ' , '__construct ' )
39
- ->setArgument ('$classMapping ' , '%msgphp.domain.class_mapping% ' );
40
-
41
- $ container ->register (ConsoleInfra \Context \ClassContextElementFactory::class)
42
- ->setPublic (false );
43
-
44
- $ container ->setAlias (ConsoleInfra \Context \ClassContextElementFactoryInterface::class, new Alias (ConsoleInfra \Context \ClassContextElementFactory::class, false ));
45
-
46
- $ container ->register (ConsoleInfra \Event \MessageSubscriber::class)
47
- ->setPublic (false )
48
- ->addTag ('kernel.event_listener ' , ['event ' => ConsoleEvents::COMMAND , 'method ' => 'onCommand ' ])
49
- ->addTag ('kernel.event_listener ' , ['event ' => ConsoleEvents::TERMINATE , 'method ' => 'onTerminate ' ]);
50
- if (interface_exists (MiddlewareInterface::class)) {
51
- $ container ->register (MessengerInfra \ConsoleMessageSubscriberMiddleware::class)
52
- ->setPublic (false )
53
- ->setAutowired (true )
54
- ->addTag ('message_bus_middleware ' );
55
- }
56
- if (interface_exists (MessageBusMiddleware::class)) {
57
- $ container ->register (SimpleBusInfra \ConsoleMessageSubscriberMiddleware::class)
58
- ->setPublic (false )
59
- ->setAutowired (true )
60
- ->addTag ('command_bus_middleware ' );
61
- }
62
- }
63
-
64
- if (class_exists (DoctrineOrmVersion::class)) {
65
- $ container ->addCompilerPass (new Compiler \DoctrineObjectFieldMappingPass ());
66
-
67
- $ container ->register (DoctrineInfra \Event \ObjectFieldMappingListener::class)
68
- ->setPublic (false )
69
- ->setArgument ('$mapping ' , [])
70
- ->addTag ('doctrine.event_listener ' , ['event ' => DoctrineOrmEvents::loadClassMetadata])
71
- ->addTag ('msgphp.domain.process_class_mapping ' , ['argument ' => '$mapping ' ]);
72
-
73
- if (ContainerHelper::hasBundle ($ container , DoctrineBundle::class)) {
74
- @mkdir ($ mappingDir = $ container ->getParameterBag ()->resolveValue ('%kernel.cache_dir%/msgphp/doctrine-mapping ' ), 0777 , true );
75
-
76
- $ container ->prependExtensionConfig ('doctrine ' , ['orm ' => [
77
- 'hydrators ' => [
78
- DoctrineInfra \Hydration \ScalarHydrator::NAME => DoctrineInfra \Hydration \ScalarHydrator::class,
79
- DoctrineInfra \Hydration \SingleScalarHydrator::NAME => DoctrineInfra \Hydration \SingleScalarHydrator::class,
80
- ],
81
- 'mappings ' => [
82
- 'msgphp ' => [
83
- 'dir ' => $ mappingDir ,
84
- 'type ' => 'xml ' ,
85
- 'prefix ' => 'MsgPhp ' ,
86
- 'is_bundle ' => false ,
87
- ],
88
- ],
89
- ]]);
90
- }
91
- }
92
-
93
33
$ container ->addCompilerPass (new Compiler \ResolveDomainPass ());
94
34
35
+ self ::initConsole ($ container );
36
+ self ::initDoctrineOrm ($ container );
37
+
95
38
$ initialized = true ;
96
39
}
97
40
@@ -111,6 +54,76 @@ public static function initDoctrineTypes(Container $container): void
111
54
$ initialized = true ;
112
55
}
113
56
57
+ private static function initConsole (ContainerBuilder $ container ): void
58
+ {
59
+ if (!class_exists (ConsoleEvents::class)) {
60
+ return ;
61
+ }
62
+
63
+ $ container ->register (ConsoleInfra \Context \ClassContextFactory::class)
64
+ ->setPublic (false )
65
+ ->setAbstract (true )
66
+ ->setAutowired (true )
67
+ ->setArgument ('$method ' , '__construct ' )
68
+ ->setArgument ('$classMapping ' , '%msgphp.domain.class_mapping% ' );
69
+
70
+ $ container ->register (ConsoleInfra \Context \ClassContextElementFactory::class)
71
+ ->setPublic (false );
72
+
73
+ $ container ->setAlias (ConsoleInfra \Context \ClassContextElementFactoryInterface::class, new Alias (ConsoleInfra \Context \ClassContextElementFactory::class, false ));
74
+
75
+ $ container ->register (ConsoleInfra \Event \MessageSubscriber::class)
76
+ ->setPublic (false )
77
+ ->addTag ('kernel.event_listener ' , ['event ' => ConsoleEvents::COMMAND , 'method ' => 'onCommand ' ])
78
+ ->addTag ('kernel.event_listener ' , ['event ' => ConsoleEvents::TERMINATE , 'method ' => 'onTerminate ' ]);
79
+
80
+ if (interface_exists (MiddlewareInterface::class)) {
81
+ $ container ->register (MessengerInfra \ConsoleMessageSubscriberMiddleware::class)
82
+ ->setPublic (false )
83
+ ->setAutowired (true )
84
+ ->addTag ('message_bus_middleware ' );
85
+ }
86
+ if (interface_exists (MessageBusMiddleware::class)) {
87
+ $ container ->register (SimpleBusInfra \ConsoleMessageSubscriberMiddleware::class)
88
+ ->setPublic (false )
89
+ ->setAutowired (true )
90
+ ->addTag ('command_bus_middleware ' );
91
+ }
92
+ }
93
+
94
+ private static function initDoctrineOrm (ContainerBuilder $ container ): void
95
+ {
96
+ if (!class_exists (DoctrineOrmVersion::class)) {
97
+ return ;
98
+ }
99
+
100
+ $ container ->addCompilerPass (new Compiler \DoctrineObjectFieldMappingPass ());
101
+
102
+ $ container ->register (DoctrineInfra \Event \ObjectFieldMappingListener::class)
103
+ ->setPublic (false )
104
+ ->setArgument ('$mapping ' , [])
105
+ ->addTag ('doctrine.event_listener ' , ['event ' => DoctrineOrmEvents::loadClassMetadata]);
106
+
107
+ if (ContainerHelper::hasBundle ($ container , DoctrineBundle::class)) {
108
+ @mkdir ($ mappingDir = $ container ->getParameterBag ()->resolveValue ('%kernel.cache_dir%/msgphp/doctrine-mapping ' ), 0777 , true );
109
+
110
+ $ container ->prependExtensionConfig ('doctrine ' , ['orm ' => [
111
+ 'hydrators ' => [
112
+ DoctrineInfra \Hydration \ScalarHydrator::NAME => DoctrineInfra \Hydration \ScalarHydrator::class,
113
+ DoctrineInfra \Hydration \SingleScalarHydrator::NAME => DoctrineInfra \Hydration \SingleScalarHydrator::class,
114
+ ],
115
+ 'mappings ' => [
116
+ 'msgphp ' => [
117
+ 'dir ' => $ mappingDir ,
118
+ 'type ' => 'xml ' ,
119
+ 'prefix ' => 'MsgPhp ' ,
120
+ 'is_bundle ' => false ,
121
+ ],
122
+ ],
123
+ ]]);
124
+ }
125
+ }
126
+
114
127
private static function &getInitialized (Container $ container , string $ key )
115
128
{
116
129
if (!isset (self ::$ initialized [$ hash = spl_object_hash ($ container )."\0" .$ key ])) {
0 commit comments