1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of file-fixture. |
5
|
|
|
* |
6
|
|
|
* (c) Noritaka Horio <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace holyshared\fixture; |
13
|
|
|
|
14
|
|
|
use holyshared\fixture\Container; |
15
|
|
|
use Yosymfony\Toml\Toml; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
class FileFixture implements Loader |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \holyshared\fixture\Container |
23
|
|
|
*/ |
24
|
|
|
private $loaders; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \holyshared\fixture\Container |
28
|
|
|
*/ |
29
|
|
|
private $fixtures; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Create a new FileFixture |
33
|
|
|
* |
34
|
|
|
* @param \holyshared\fixture\Container $fixtures |
35
|
|
|
* @param \holyshared\fixture\Container $loaders |
36
|
|
|
*/ |
37
|
|
|
public function __construct(Container $fixtures, Container $loaders) |
38
|
|
|
{ |
39
|
|
|
$this->loaders = $loaders; |
40
|
|
|
$this->fixtures = $fixtures; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
public function load($name, array $arguments = []) |
47
|
|
|
{ |
48
|
|
|
$parts = explode(':', $name); |
49
|
|
|
$loader = array_shift($parts); |
50
|
|
|
|
51
|
|
|
$path = $this->resolveName($name); |
52
|
|
|
$loader = $this->loaders->get($loader); |
53
|
|
|
|
54
|
|
|
return $loader->load($path, $arguments); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the Path from the name of the fixture |
59
|
|
|
* |
60
|
|
|
* <code> |
61
|
|
|
* $path = $fixture->resolveName('text:ok'); //Return absolute path of fixture |
62
|
|
|
* </code> |
63
|
|
|
* |
64
|
|
|
* @param string $name name of fixture |
65
|
|
|
* @return string path of fixture |
66
|
|
|
*/ |
67
|
|
|
public function resolveName($name) |
68
|
|
|
{ |
69
|
|
|
$path = $this->fixtures->get($name); |
70
|
|
|
|
71
|
|
|
return $path; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|