forked from samsonasik/ErrorHeroModule
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransformerAbstract.php
More file actions
61 lines (50 loc) · 1.49 KB
/
TransformerAbstract.php
File metadata and controls
61 lines (50 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
namespace ErrorHeroModule\Transformer;
use Laminas\Db\Adapter\Adapter;
use Laminas\Log\Logger;
abstract class TransformerAbstract
{
/**
* @var string
*/
private const DB = 'db';
/**
* @return array{array{name: string, options: array}}
*/
private static function getWriterConfig(array $configuration): array
{
return $configuration['log']['ErrorHeroModuleLogger']['writers'];
}
/**
* @return mixed[]
*/
protected static function getDbAdapterConfig(array $configuration): array
{
$writers = self::getWriterConfig($configuration);
$config = $configuration[self::DB];
if (! isset($config['adapters'])) {
return $config;
}
foreach ($writers as $writer) {
if ($writer['name'] === self::DB) {
$adapterName = $writer['options'][self::DB];
break;
}
}
return isset($adapterName)
? ($config['adapters'][$adapterName] ?? $config)
: $config;
}
protected static function getLoggerInstance(array $configuration, array $dbConfig): Logger
{
$writers = self::getWriterConfig($configuration);
foreach ($writers as &$writer) {
if ($writer['name'] === self::DB) {
$writer['options'][self::DB] = new Adapter($dbConfig);
break;
}
}
return new Logger(['writers' => $writers]);
}
}