1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @link http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html |
5
|
|
|
* @link https://github.com/nelmio/alice |
6
|
|
|
* @link https://github.com/fzaninotto/Faker |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace AppBundle\DataFixtures\ORM; |
10
|
|
|
|
11
|
|
|
use Doctrine\Common\DataFixtures\FixtureInterface; |
12
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
13
|
|
|
use Nelmio\Alice\Fixtures; |
14
|
|
|
|
15
|
|
|
class LoadUserData implements FixtureInterface |
16
|
|
|
{ |
17
|
|
|
public function load(ObjectManager $manager) |
18
|
|
|
{ |
19
|
|
|
Fixtures::load($this->getFixtures(), $manager, ['providers' => [$this]]); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function getFixtures() |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
$kernel = $GLOBALS['kernel']; |
25
|
|
|
$env = $kernel->getEnvironment(); |
26
|
|
|
|
27
|
|
|
echo "\nEnvironment is: " . $env . "\n\n"; |
28
|
|
|
|
29
|
|
|
if ($env == 'test') { |
30
|
|
|
return [ |
31
|
|
|
__DIR__.'/test/role.yml', |
32
|
|
|
__DIR__.'/test/tag.yml', |
33
|
|
|
__DIR__.'/test/category.yml', |
34
|
|
|
__DIR__.'/test/user.yml', |
35
|
|
|
__DIR__.'/test/article.yml', |
36
|
|
|
__DIR__.'/test/comment.yml', |
37
|
|
|
]; |
38
|
|
|
} |
39
|
|
|
return [ |
40
|
|
|
__DIR__.'/dev/role.yml', |
41
|
|
|
__DIR__.'/dev/tag.yml', |
42
|
|
|
__DIR__.'/dev/category.yml', |
43
|
|
|
__DIR__.'/dev/user.yml', |
44
|
|
|
__DIR__.'/dev/article.yml', |
45
|
|
|
__DIR__.'/dev/comment.yml', |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function role($count) |
50
|
|
|
{ |
51
|
|
|
$roles = [ |
52
|
|
|
'admin', |
53
|
|
|
'moderator', |
54
|
|
|
'user', |
55
|
|
|
'anonymous', |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
return $roles[$count-1]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function picture() |
62
|
|
|
{ |
63
|
|
|
$picture = [ |
64
|
|
|
'balloon', |
65
|
|
|
'buildings', |
66
|
|
|
'people', |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
return $picture[array_rand($picture)]; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function photo() |
73
|
|
|
{ |
74
|
|
|
$photo = [ |
75
|
|
|
'user1.png', |
76
|
|
|
'user2.png', |
77
|
|
|
'user3.png', |
78
|
|
|
'user4.png', |
79
|
|
|
'user5.png', |
80
|
|
|
]; |
81
|
|
|
|
82
|
|
|
return $photo[array_rand($photo)]; |
83
|
|
|
} |
84
|
|
|
} |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: