1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Knp\RadBundle\DataFixtures\ORM; |
4
|
|
|
|
5
|
|
|
use Knp\RadBundle\DataFixtures\AbstractFixture; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Finder\Finder; |
8
|
|
|
|
9
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
10
|
|
|
|
11
|
|
|
use Nelmio\Alice\Fixtures; |
12
|
|
|
|
13
|
|
|
class LoadAliceFixtures extends AbstractFixture |
14
|
|
|
{ |
15
|
|
|
public function load(ObjectManager $manager) |
16
|
|
|
{ |
17
|
|
|
$env = $this->container->getParameter('kernel.environment'); |
18
|
|
|
$bundles = $this->container->getParameter('kernel.bundles'); |
19
|
|
|
if (!isset($bundles['App'])) { |
20
|
|
|
return; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
$refl = new \ReflectionClass($bundles['App']); |
24
|
|
|
if (class_exists($customClass = $refl->getNamespaceName().'\\DataFixtures\\ORM\\LoadAliceFixtures') && |
25
|
|
|
$customClass !== get_class($this)) { |
26
|
|
|
return; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$path = dirname($refl->getFileName()).DIRECTORY_SEPARATOR.'Resources'. |
30
|
|
|
DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.'orm'; |
31
|
|
|
|
32
|
|
|
foreach ($this->getAliceFiles($path, $env) as $file) { |
33
|
|
|
Fixtures::load($file, $manager, $this->getAliceOptions()); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function getAliceFiles($path, $environment) |
38
|
|
|
{ |
39
|
|
|
$paths = array(); |
40
|
|
|
if (is_dir($path)) { |
41
|
|
|
$paths[] = $path; |
42
|
|
|
} |
43
|
|
|
if (is_dir($path.DIRECTORY_SEPARATOR.$environment)) { |
44
|
|
|
$paths[] = $path.DIRECTORY_SEPARATOR.$environment; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (0 == count($paths)) { |
48
|
|
|
return array(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return Finder::create() |
52
|
|
|
->files() |
53
|
|
|
->name('*.yml') |
54
|
|
|
->depth(0) |
55
|
|
|
->sortByName() |
56
|
|
|
->in($paths) |
57
|
|
|
; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function getAliceOptions() |
61
|
|
|
{ |
62
|
|
|
return array('providers' => $this->getAliceProviders()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function getAliceProviders() |
66
|
|
|
{ |
67
|
|
|
return $this->container->get('knp_rad.alice.provider_collection')->getProviders(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|