15
15
namespace Berlioz \Package \Hector \Container ;
16
16
17
17
use Berlioz \Core \Core ;
18
+ use Berlioz \Package \Hector \Debug \HectorSection ;
18
19
use Berlioz \Package \Hector \DefaultCacheDriver ;
20
+ use Berlioz \Package \Hector \Event \EventSubscriber ;
19
21
use Berlioz \Package \Hector \Exception \HectorException ;
20
22
use Berlioz \Package \Hector \HectorAwareInterface ;
21
23
use Berlioz \ServiceContainer \Container ;
@@ -50,7 +52,13 @@ function (Core $core) {
50
52
$ options = $ core ->getConfig ()->get ('hector ' );
51
53
$ options ['log ' ] = $ options ['log ' ] ?? $ core ->getDebug ()->isEnabled ();
52
54
53
- return OrmFactory::connection ($ options );
55
+ $ connection = OrmFactory::connection ($ options );
56
+
57
+ if (true === $ core ->getDebug ()->isEnabled ()) {
58
+ $ core ->getDebug ()->addSection (new HectorSection ($ connection ->getLogger ()));
59
+ }
60
+
61
+ return $ connection ;
54
62
}
55
63
);
56
64
@@ -67,6 +75,11 @@ function (Core $core, Connection $connection) {
67
75
68
76
$ this ->setOrmTypes ($ orm , $ core );
69
77
78
+ // Dynamic events
79
+ if ($ core ->getConfig ()->get ('hector.dynamic_events ' , true )) {
80
+ $ core ->getEventDispatcher ()->addSubscriber (new EventSubscriber ($ core ->getContainer ()));
81
+ }
82
+
70
83
return $ orm ;
71
84
}
72
85
)
@@ -92,30 +105,9 @@ public function boot(Container $container): void
92
105
protected function setOrmTypes (Orm $ orm , Core $ core ): void
93
106
{
94
107
try {
95
- foreach ((array )$ core ->getConfig ()->get ('hector.types ' , []) as $ typeConfig ) {
96
- if (is_string ($ typeConfig )) {
97
- $ orm ->getDataTypes ()->addGlobalType ($ core ->getContainer ()->get ($ typeConfig ));
98
- continue ;
99
- }
100
-
101
- if (false === is_array ($ typeConfig )) {
102
- continue ;
103
- }
104
-
105
- $ columnInfo = explode ('. ' , $ typeConfig ['column ' ]);
106
- $ column = match (count ($ columnInfo )) {
107
- 2 => $ orm ->getSchemaContainer ()->getColumn ($ columnInfo [1 ], $ columnInfo [0 ]),
108
- 3 => $ orm ->getSchemaContainer ()->getColumn ($ columnInfo [2 ], $ columnInfo [1 ], $ columnInfo [0 ]),
109
- default => throw HectorException::typesConfig (),
110
- };
111
-
112
- $ orm ->getDataTypes ()->addColumnType (
113
- $ column ,
114
- $ core ->getContainer ()->get (($ typeConfig ['column ' ] ?? null ) ?: throw HectorException::typesConfig ())
115
- );
108
+ foreach ((array )$ core ->getConfig ()->get ('hector.types ' , []) as $ type => $ obj ) {
109
+ $ orm ->getTypes ()->add ($ type , $ core ->getContainer ()->get ($ obj ));
116
110
}
117
- } catch (HectorException $ exception ) {
118
- throw $ exception ;
119
111
} catch (Throwable $ exception ) {
120
112
throw HectorException::typesConfig ($ exception );
121
113
}
0 commit comments