-
Notifications
You must be signed in to change notification settings - Fork 0
/
PathMappingResolver.php
41 lines (34 loc) · 1 KB
/
PathMappingResolver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace Eventjet\AssetManager\Resolver;
use Eventjet\AssetManager\Asset\AssetFactoryInterface;
use Eventjet\AssetManager\Asset\AssetInterface;
use function file_exists;
final class PathMappingResolver implements ResolverInterface
{
/** @var array<array-key, string> */
private array $pathMapping;
private AssetFactoryInterface $factory;
/**
* @param array<array-key, string> $pathMapping
*/
public function __construct(array $pathMapping, AssetFactoryInterface $factory)
{
$this->pathMapping = $pathMapping;
$this->factory = $factory;
}
public function resolve(string $path): ?AssetInterface
{
if ($path === '/') {
return null;
}
foreach ($this->pathMapping as $current) {
$fullPath = $current . $path;
if (!file_exists($fullPath)) {
continue;
}
return $this->factory->create($fullPath);
}
return null;
}
}