10
10
use Butschster \ContextGenerator \Config \Import \Source \Registry \ImportSourceRegistry ;
11
11
use Psr \Log \LoggerInterface ;
12
12
use Psr \Log \NullLogger ;
13
+ use Spiral \Core \Container ;
13
14
14
15
/**
15
16
* Service provider for accessing import sources
16
17
*/
17
18
final readonly class ImportSourceProvider
18
19
{
19
20
public function __construct (
20
- private ImportSourceRegistry $ sourceRegistry ,
21
+ private Container $ container ,
21
22
#[LoggerPrefix(prefix: 'import-sources ' )]
22
23
private ?LoggerInterface $ logger = null ,
23
24
) {}
@@ -31,7 +32,7 @@ public function __construct(
31
32
*/
32
33
public function getSource (string $ name ): ImportSourceInterface
33
34
{
34
- return $ this ->sourceRegistry ->get ($ name );
35
+ return $ this ->getSourceRegistry () ->get ($ name );
35
36
}
36
37
37
38
/**
@@ -44,15 +45,15 @@ public function findSourceForConfig(SourceConfigInterface $config): ?ImportSourc
44
45
{
45
46
// First try to find source by type
46
47
$ sourceName = $ config ->getType ();
47
- if ($ this ->sourceRegistry ->has ($ sourceName )) {
48
- $ source = $ this ->sourceRegistry ->get ($ sourceName );
48
+ if ($ this ->getSourceRegistry () ->has ($ sourceName )) {
49
+ $ source = $ this ->getSourceRegistry () ->get ($ sourceName );
49
50
if ($ source ->supports ($ config )) {
50
51
return clone $ source ;
51
52
}
52
53
}
53
54
54
55
// If not found by type, try all registered sources
55
- foreach ($ this ->sourceRegistry ->all () as $ source ) {
56
+ foreach ($ this ->getSourceRegistry () ->all () as $ source ) {
56
57
if ($ source ->supports ($ config )) {
57
58
return clone $ source ;
58
59
}
@@ -66,23 +67,8 @@ public function findSourceForConfig(SourceConfigInterface $config): ?ImportSourc
66
67
return null ;
67
68
}
68
69
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
70
+ private function getSourceRegistry (): ImportSourceRegistry
76
71
{
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 ;
72
+ return $ this ->container ->get (ImportSourceRegistry::class);
87
73
}
88
74
}
0 commit comments