Skip to content

Commit f08b442

Browse files
committed
feat: Refactor URL import handling and add comprehensive tests for various scenarios
1 parent b8f1f94 commit f08b442

File tree

3 files changed

+645
-23
lines changed

3 files changed

+645
-23
lines changed

src/Config/Import/Source/ImportSourceProvider.php

+8-22
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
use Butschster\ContextGenerator\Config\Import\Source\Registry\ImportSourceRegistry;
1111
use Psr\Log\LoggerInterface;
1212
use Psr\Log\NullLogger;
13+
use Spiral\Core\Container;
1314

1415
/**
1516
* Service provider for accessing import sources
1617
*/
1718
final readonly class ImportSourceProvider
1819
{
1920
public function __construct(
20-
private ImportSourceRegistry $sourceRegistry,
21+
private Container $container,
2122
#[LoggerPrefix(prefix: 'import-sources')]
2223
private ?LoggerInterface $logger = null,
2324
) {}
@@ -31,7 +32,7 @@ public function __construct(
3132
*/
3233
public function getSource(string $name): ImportSourceInterface
3334
{
34-
return $this->sourceRegistry->get($name);
35+
return $this->getSourceRegistry()->get($name);
3536
}
3637

3738
/**
@@ -44,15 +45,15 @@ public function findSourceForConfig(SourceConfigInterface $config): ?ImportSourc
4445
{
4546
// First try to find source by type
4647
$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);
4950
if ($source->supports($config)) {
5051
return clone $source;
5152
}
5253
}
5354

5455
// If not found by type, try all registered sources
55-
foreach ($this->sourceRegistry->all() as $source) {
56+
foreach ($this->getSourceRegistry()->all() as $source) {
5657
if ($source->supports($config)) {
5758
return clone $source;
5859
}
@@ -66,23 +67,8 @@ public function findSourceForConfig(SourceConfigInterface $config): ?ImportSourc
6667
return null;
6768
}
6869

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
7671
{
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);
8773
}
8874
}

src/Config/Import/Source/Url/UrlImportSource.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function load(SourceConfigInterface $config): array
6161
}
6262

6363
try {
64-
$url = $config->url;
64+
$url = $this->container->get(VariableResolver::class)->resolve($config->url);
6565
$headers = $this->container->get(VariableResolver::class)->resolve($config->headers);
6666

6767
$this->logger->debug('Loading URL import', [

0 commit comments

Comments
 (0)