4
4
5
5
namespace Butschster \ContextGenerator \Config \Import \Source ;
6
6
7
- use Butschster \ContextGenerator \Application \Logger \HasPrefixLoggerInterface ;
8
7
use Butschster \ContextGenerator \Application \Logger \LoggerPrefix ;
9
8
use Butschster \ContextGenerator \Config \Import \Source \Config \SourceConfigInterface ;
10
9
use Butschster \ContextGenerator \Config \Import \Source \Registry \ImportSourceRegistry ;
11
10
use Psr \Log \LoggerInterface ;
12
- use Psr \ Log \ NullLogger ;
11
+ use Spiral \ Core \ Container ;
13
12
14
13
/**
15
14
* Service provider for accessing import sources
16
15
*/
17
16
final readonly class ImportSourceProvider
18
17
{
19
18
public function __construct (
20
- private ImportSourceRegistry $ sourceRegistry ,
19
+ private Container $ container ,
21
20
#[LoggerPrefix(prefix: 'import-sources ' )]
22
21
private ?LoggerInterface $ logger = null ,
23
22
) {}
@@ -31,7 +30,7 @@ public function __construct(
31
30
*/
32
31
public function getSource (string $ name ): ImportSourceInterface
33
32
{
34
- return $ this ->sourceRegistry ->get ($ name );
33
+ return $ this ->getSourceRegistry () ->get ($ name );
35
34
}
36
35
37
36
/**
@@ -44,15 +43,15 @@ public function findSourceForConfig(SourceConfigInterface $config): ?ImportSourc
44
43
{
45
44
// First try to find source by type
46
45
$ sourceName = $ config ->getType ();
47
- if ($ this ->sourceRegistry ->has ($ sourceName )) {
48
- $ source = $ this ->sourceRegistry ->get ($ sourceName );
46
+ if ($ this ->getSourceRegistry () ->has ($ sourceName )) {
47
+ $ source = $ this ->getSourceRegistry () ->get ($ sourceName );
49
48
if ($ source ->supports ($ config )) {
50
49
return clone $ source ;
51
50
}
52
51
}
53
52
54
53
// If not found by type, try all registered sources
55
- foreach ($ this ->sourceRegistry ->all () as $ source ) {
54
+ foreach ($ this ->getSourceRegistry () ->all () as $ source ) {
56
55
if ($ source ->supports ($ config )) {
57
56
return clone $ source ;
58
57
}
@@ -66,23 +65,8 @@ public function findSourceForConfig(SourceConfigInterface $config): ?ImportSourc
66
65
return null ;
67
66
}
68
67
69
- /**
70
- * Get a logger with a source-specific prefix
71
- *
72
- * @param string $sourceName Name of the source for logger prefixing
73
- * @return LoggerInterface Logger with appropriate prefix
74
- */
75
- public function getSourceLogger (string $ sourceName ): LoggerInterface
68
+ private function getSourceRegistry (): ImportSourceRegistry
76
69
{
77
- if ($ this ->logger === null ) {
78
- return new NullLogger ();
79
- }
80
-
81
- // Check if logger supports prefixing
82
- if ($ this ->logger instanceof HasPrefixLoggerInterface) {
83
- return $ this ->logger ->withPrefix ("import- {$ sourceName }" );
84
- }
85
-
86
- return $ this ->logger ;
70
+ return $ this ->container ->get (ImportSourceRegistry::class);
87
71
}
88
72
}
0 commit comments