1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Hautelook\AliceBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Baldur Rensch <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Hautelook\AliceBundle\Resolver\File; |
15
|
|
|
|
16
|
|
|
use Fidry\AliceDataFixtures\FileResolverInterface; |
17
|
|
|
use InvalidArgumentException; |
18
|
|
|
use Nelmio\Alice\IsAServiceTrait; |
19
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
20
|
|
|
|
21
|
|
|
final class KernelFileResolver implements FileResolverInterface |
22
|
|
|
{ |
23
|
|
|
use IsAServiceTrait; |
24
|
|
|
|
25
|
|
|
private $kernel; |
26
|
|
|
|
27
|
|
|
public function __construct(KernelInterface $kernel) |
28
|
|
|
{ |
29
|
|
|
$this->kernel = $kernel; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc |
34
|
|
|
*/ |
35
|
|
|
public function resolve(array $filePaths): array |
36
|
|
|
{ |
37
|
|
|
$resolvedFixtures = []; |
38
|
|
|
foreach ($filePaths as $file) { |
39
|
|
|
$resolvedFixtures[$this->resolveFile($file)] = true; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return array_keys($resolvedFixtures); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function resolveFile(string $file): string |
46
|
|
|
{ |
47
|
|
|
$realFile = ('@' === $file[0]) |
48
|
|
|
? $this->kernel->locateResource($file, null, true) |
49
|
|
|
: $file |
50
|
|
|
; |
51
|
|
|
|
52
|
|
|
$realFile = realpath($realFile); |
53
|
|
|
if (false === $realFile || false === file_exists($realFile)) { |
54
|
|
|
throw new InvalidArgumentException(sprintf('The file "%s" was not found.', $file)); |
55
|
|
|
} |
56
|
|
|
if (false === is_file($realFile)) { |
57
|
|
|
throw new InvalidArgumentException( |
58
|
|
|
sprintf('Expected "%s" to be a fixture file, got a directory instead.', $file) |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $realFile; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|