Skip to content

Commit 67845f9

Browse files
committed
Deport debug options in service provider
Fix data types declaration
1 parent dc26ce1 commit 67845f9

File tree

2 files changed

+17
-40
lines changed

2 files changed

+17
-40
lines changed

src/BerliozPackage.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616

1717
use Berlioz\Config\Adapter\JsonAdapter;
1818
use Berlioz\Config\ConfigInterface;
19-
use Berlioz\Config\Exception\ConfigException;
2019
use Berlioz\Core\Core;
2120
use Berlioz\Core\Package\AbstractPackage;
2221
use Berlioz\Package\Hector\Container\ServiceProvider;
23-
use Berlioz\Package\Hector\Debug\HectorSection;
24-
use Berlioz\Package\Hector\Event\EventSubscriber;
2522
use Berlioz\ServiceContainer\Container;
2623
use Hector\Orm\Orm;
2724

@@ -48,21 +45,9 @@ public static function register(Container $container): void
4845

4946
/**
5047
* @inheritDoc
51-
* @throws ConfigException
5248
*/
5349
public static function boot(Core $core): void
5450
{
55-
/** @var Orm $orm */
56-
$orm = $core->getContainer()->get(Orm::class);
57-
58-
if (true === $core->getDebug()->isEnabled()) {
59-
$loggers = iterator_to_array($orm->getConnections()->getLoggers(), false);
60-
$core->getDebug()->addSection(new HectorSection(...$loggers));
61-
}
62-
63-
// Dynamic events
64-
if ($core->getConfig()->get('hector.dynamic_events', true)) {
65-
$core->getEventDispatcher()->addSubscriber(new EventSubscriber($core->getContainer()));
66-
}
51+
$core->getContainer()->get(Orm::class);
6752
}
6853
}

src/Container/ServiceProvider.php

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
namespace Berlioz\Package\Hector\Container;
1616

1717
use Berlioz\Core\Core;
18+
use Berlioz\Package\Hector\Debug\HectorSection;
1819
use Berlioz\Package\Hector\DefaultCacheDriver;
20+
use Berlioz\Package\Hector\Event\EventSubscriber;
1921
use Berlioz\Package\Hector\Exception\HectorException;
2022
use Berlioz\Package\Hector\HectorAwareInterface;
2123
use Berlioz\ServiceContainer\Container;
@@ -50,7 +52,13 @@ function (Core $core) {
5052
$options = $core->getConfig()->get('hector');
5153
$options['log'] = $options['log'] ?? $core->getDebug()->isEnabled();
5254

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;
5462
}
5563
);
5664

@@ -67,6 +75,11 @@ function (Core $core, Connection $connection) {
6775

6876
$this->setOrmTypes($orm, $core);
6977

78+
// Dynamic events
79+
if ($core->getConfig()->get('hector.dynamic_events', true)) {
80+
$core->getEventDispatcher()->addSubscriber(new EventSubscriber($core->getContainer()));
81+
}
82+
7083
return $orm;
7184
}
7285
)
@@ -92,30 +105,9 @@ public function boot(Container $container): void
92105
protected function setOrmTypes(Orm $orm, Core $core): void
93106
{
94107
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));
116110
}
117-
} catch (HectorException $exception) {
118-
throw $exception;
119111
} catch (Throwable $exception) {
120112
throw HectorException::typesConfig($exception);
121113
}

0 commit comments

Comments
 (0)