55
66use FD \LogViewer \Entity \Config \FinderConfig ;
77use FD \LogViewer \Entity \Config \LogFilesConfig ;
8- use FD \LogViewer \Service \JsonManifestVersionStrategy ;
98use Symfony \Component \Config \FileLocator ;
109use Symfony \Component \DependencyInjection \ContainerBuilder ;
1110use Symfony \Component \DependencyInjection \Extension \Extension as BaseExtension ;
12- use Symfony \Component \DependencyInjection \Extension \PrependExtensionInterface ;
1311use Symfony \Component \DependencyInjection \Loader \PhpFileLoader ;
1412use Symfony \Component \DependencyInjection \Reference ;
1513use Throwable ;
1816 * @codeCoverageIgnore
1917 * @internal
2018 */
21- final class Extension extends BaseExtension implements PrependExtensionInterface
19+ final class Extension extends BaseExtension
2220{
2321 /**
2422 * @inheritDoc
@@ -32,19 +30,8 @@ public function load(array $configs, ContainerBuilder $container): void
3230 $ mergedConfigs = $ this ->processConfiguration (new Configuration (), $ configs );
3331
3432 // add defaults
35- if (count ($ mergedConfigs ['log_files ' ]) === 0 ) {
36- $ mergedConfigs ['log_files ' ]['monolog ' ] = [
37- 'type ' => 'monolog ' ,
38- 'name ' => 'Monolog ' ,
39- 'finder ' => [
40- 'in ' => '%kernel.logs_dir% ' ,
41- 'name ' => '*.log ' ,
42- 'ignoreUnreadableDirs ' => true ,
43- 'followLinks ' => false
44- ],
45- 'downloadable ' => false ,
46- 'deletable ' => false ,
47- ];
33+ if ($ mergedConfigs ['enable_default_monolog ' ]) {
34+ $ mergedConfigs = self ::addMonologDefault ($ mergedConfigs );
4835 }
4936
5037 foreach ($ mergedConfigs ['log_files ' ] as $ key => $ config ) {
@@ -76,22 +63,25 @@ public function getAlias(): string
7663 }
7764
7865 /**
79- * @inheritdoc
66+ * @template T of array
67+ * @phpstan-param T $configs
68+ *
69+ * @phpstan-return T
8070 */
81- public function prepend ( ContainerBuilder $ container ): void
71+ private static function addMonologDefault ( array $ configs ): array
8272 {
83- $ container -> prependExtensionConfig (
84- ' framework ' ,
85- [
86- ' assets ' => [
87- ' enabled ' => true ,
88- ' packages ' => [
89- ' fd_symfony_log_viewer ' => [
90- ' version_strategy ' => JsonManifestVersionStrategy::class
91- ],
92- ],
93- ],
94- ]
95- ) ;
73+ // monolog
74+ $ configs [ ' log_files ' ][ ' monolog ' ][ ' type ' ] ??= ' monolog ' ;
75+ $ configs [ ' log_files ' ][ ' monolog ' ][ ' name ' ] ??= ' Monolog ' ;
76+ $ configs [ ' log_files ' ][ ' monolog ' ][ ' downloadable ' ] ??= false ;
77+ $ configs [ ' log_files ' ][ ' monolog ' ][ ' deletable ' ] ??= false ;
78+
79+ // finder
80+ $ configs [ ' log_files ' ][ ' monolog ' ][ ' finder ' ][ ' in ' ] ??= ' %kernel.logs_dir% ' ;
81+ $ configs [ ' log_files ' ][ ' monolog ' ][ ' finder ' ][ ' name ' ] ??= ' *.log ' ;
82+ $ configs [ ' log_files ' ][ ' monolog ' ][ ' finder ' ][ ' ignoreUnreadableDirs ' ] ??= true ;
83+ $ configs [ ' log_files ' ][ ' monolog ' ][ ' finder ' ][ ' followLinks ' ] ??= false ;
84+
85+ return $ configs ;
9686 }
9787}
0 commit comments