|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Knp\FriendlyContexts\Alice\Fixtures\Alice3; |
|
4
|
|
|
|
|
5
|
|
|
use Knp\FriendlyContexts\Alice\Fixtures\Loader as LoaderInterface; |
|
6
|
|
|
use Nelmio\Alice\DataLoaderInterface; |
|
7
|
|
|
use Nelmio\Alice\FilesLoaderInterface; |
|
8
|
|
|
use Nelmio\Alice\FixtureInterface; |
|
9
|
|
|
use Nelmio\Alice\FixtureSet; |
|
10
|
|
|
use Nelmio\Alice\Loader\NativeLoader; |
|
11
|
|
|
use Nelmio\Alice\Loader\SimpleFilesLoader; |
|
12
|
|
|
use Nelmio\Alice\Throwable\Exception\ObjectNotFoundException; |
|
13
|
|
|
|
|
14
|
|
|
class Loader extends NativeLoader implements |
|
15
|
|
|
LoaderInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var null|FixtureSet |
|
19
|
|
|
*/ |
|
20
|
|
|
private $fixtureSet = null; |
|
21
|
|
|
private $objects = null; |
|
22
|
|
|
private $loader; |
|
23
|
|
|
private $dataLoader; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct() |
|
26
|
|
|
{ |
|
27
|
|
|
parent::__construct(); |
|
28
|
|
|
|
|
29
|
|
|
$this->loader = $this->createFilesLoader(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getCache() |
|
33
|
|
|
{ |
|
34
|
|
|
if (null === $this->fixtureSet) { |
|
35
|
|
|
return array(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$cache = array(); |
|
39
|
|
|
$fixtures = $this->fixtureSet->getFixtures(); |
|
40
|
|
|
/** @var FixtureInterface $fixture */ |
|
41
|
|
|
foreach ($fixtures as $fixture) { |
|
42
|
|
|
$spec = array(); |
|
43
|
|
|
|
|
44
|
|
|
$properties = $fixture->getSpecs()->getProperties(); |
|
45
|
|
|
foreach ($properties->getIterator() as $property) { |
|
46
|
|
|
$spec[] = $property->getValue(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$cache[] = array($spec, $this->objects[$fixture->getId()]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $cache; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function clearCache() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->fixtureSet = null; |
|
58
|
|
|
$this->objects = null; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function load($filename) |
|
62
|
|
|
{ |
|
63
|
|
|
if ( ! is_array($filename)) { |
|
64
|
|
|
$filename = array($filename); |
|
65
|
|
|
} |
|
66
|
|
|
$this->objects = $this->loader->loadFiles($filename)->getObjects(); |
|
67
|
|
|
$this->fixtureSet = $this->dataLoader->getLastFixtureSet(); |
|
68
|
|
|
return $this->objects; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function createDataLoader() : DataLoaderInterface |
|
72
|
|
|
{ |
|
73
|
|
|
return new DataLoader( |
|
74
|
|
|
$this->getFixtureBuilder(), |
|
75
|
|
|
$this->getGenerator() |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
protected function createFilesLoader(): FilesLoaderInterface |
|
80
|
|
|
{ |
|
81
|
|
|
if (null === $this->dataLoader) { |
|
82
|
|
|
$this->dataLoader = $this->createDataLoader(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return new SimpleFilesLoader( |
|
86
|
|
|
$this->getParser(), |
|
87
|
|
|
$this->dataLoader |
|
|
|
|
|
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|