ekino /
drupal-debug
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /* |
||
| 6 | * This file is part of the ekino Drupal Debug project. |
||
| 7 | * |
||
| 8 | * (c) ekino |
||
| 9 | * |
||
| 10 | * For the full copyright and license information, please view the LICENSE |
||
| 11 | * file that was distributed with this source code. |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace Ekino\Drupal\Debug\Configuration; |
||
| 15 | |||
| 16 | use Ekino\Drupal\Debug\Configuration\Model\ActionConfiguration; |
||
| 17 | use Ekino\Drupal\Debug\Configuration\Model\DefaultsConfiguration as DefaultsConfigurationModel; |
||
| 18 | use Ekino\Drupal\Debug\Logger\LoggerStack; |
||
| 19 | use Monolog\Logger; |
||
| 20 | use Symfony\Component\Config\Definition\Builder\NodeBuilder; |
||
| 21 | |||
| 22 | trait LoggerConfigurationTrait |
||
| 23 | { |
||
| 24 | 19 | private static function addLoggerConfigurationNode(NodeBuilder $nodeBuilder, string $defaultChannel, string $defaultFilePath): NodeBuilder |
|
| 25 | { |
||
| 26 | return $nodeBuilder |
||
| 27 | 19 | ->arrayNode('logger') |
|
| 28 | 19 | ->canBeDisabled() |
|
| 29 | 19 | ->children() |
|
| 30 | 19 | ->scalarNode('channel') |
|
| 31 | 19 | ->cannotBeEmpty() |
|
| 32 | 19 | ->defaultValue($defaultChannel) |
|
| 33 | 19 | ->end() |
|
| 34 | 19 | ->scalarNode('file_path') |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 35 | 19 | ->cannotBeEmpty() |
|
| 36 | 19 | ->defaultValue($defaultFilePath) |
|
| 37 | 19 | ->end() |
|
| 38 | 19 | ->end() |
|
| 39 | 19 | ->end(); |
|
| 40 | } |
||
| 41 | |||
| 42 | 19 | private static function addLoggerConfigurationNodeFromDefaultsConfiguration(NodeBuilder $nodeBuilder, DefaultsConfigurationModel $defaultsConfiguration): NodeBuilder |
|
| 43 | { |
||
| 44 | 19 | $defaultLoggerConfiguration = $defaultsConfiguration->getLogger(); |
|
| 45 | |||
| 46 | 19 | return self::addLoggerConfigurationNode($nodeBuilder, $defaultLoggerConfiguration['channel'], $defaultLoggerConfiguration['file_path']); |
|
| 47 | } |
||
| 48 | |||
| 49 | 2 | private static function getConfiguredLogger(ActionConfiguration $actionConfiguration): ?Logger |
|
| 50 | { |
||
| 51 | 2 | $processedConfiguration = $actionConfiguration->getProcessedConfiguration(); |
|
| 52 | 2 | if (!$processedConfiguration['logger']['enabled']) { |
|
| 53 | return null; |
||
| 54 | } |
||
| 55 | |||
| 56 | 2 | return LoggerStack::getInstance($processedConfiguration['logger']['channel'], $processedConfiguration['logger']['file_path']); |
|
| 57 | } |
||
| 58 | } |
||
| 59 |