|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2016 Francois-Xavier Soubirou. |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of eco4. |
|
7
|
|
|
* |
|
8
|
|
|
* eco4 is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU General Public License as published by |
|
10
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
11
|
|
|
* (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* eco4 is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License |
|
19
|
|
|
* along with eco4. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
*/ |
|
21
|
|
|
namespace AppBundle\DataFixtures\ORM; |
|
22
|
|
|
|
|
23
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture; |
|
24
|
|
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; |
|
25
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
26
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
27
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Load user data class. |
|
31
|
|
|
* |
|
32
|
|
|
* @category Eco4 App |
|
33
|
|
|
* |
|
34
|
|
|
* @author Francois-Xavier Soubirou <[email protected]> |
|
35
|
|
|
* @copyright 2016 Francois-Xavier Soubirou |
|
36
|
|
|
* @license http://www.gnu.org/licenses/ GPLv3 |
|
37
|
|
|
* |
|
38
|
|
|
* @link https://www.eco4.io |
|
39
|
|
|
*/ |
|
40
|
|
|
class Users extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* @var ContainerInterface Container |
|
44
|
|
|
*/ |
|
45
|
|
|
private $container; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Load data fixtures with the passed EntityManager. |
|
49
|
|
|
* |
|
50
|
|
|
* @param ObjectManager $manager The entity manager |
|
51
|
|
|
* |
|
52
|
|
|
* |
|
53
|
|
|
* @codeCoverageIgnore |
|
54
|
|
|
*/ |
|
55
|
|
|
public function load(ObjectManager $manager) |
|
56
|
|
|
{ |
|
57
|
|
|
$dataArray = array( |
|
58
|
|
|
array( |
|
59
|
|
|
'name' => 'user1', |
|
60
|
|
|
'superadmin' => true, |
|
61
|
|
|
'enabled' => true, |
|
62
|
|
|
'locked' => false, |
|
63
|
|
|
'mine' => 'mine1-mine', |
|
64
|
|
|
), |
|
65
|
|
|
array( |
|
66
|
|
|
'name' => 'user2', |
|
67
|
|
|
'superadmin' => false, |
|
68
|
|
|
'enabled' => true, |
|
69
|
|
|
'locked' => false, |
|
70
|
|
|
'mine' => 'mine2-mine', |
|
71
|
|
|
), |
|
72
|
|
|
array( |
|
73
|
|
|
'name' => 'lock', |
|
74
|
|
|
'superadmin' => false, |
|
75
|
|
|
'enabled' => true, |
|
76
|
|
|
'locked' => true, |
|
77
|
|
|
'mine' => 'mine3-mine', |
|
78
|
|
|
), |
|
79
|
|
|
array( |
|
80
|
|
|
'name' => 'disable', |
|
81
|
|
|
'superadmin' => false, |
|
82
|
|
|
'enabled' => false, |
|
83
|
|
|
'locked' => false, |
|
84
|
|
|
'mine' => 'mine4-mine', |
|
85
|
|
|
), |
|
86
|
|
|
array( |
|
87
|
|
|
'name' => 'super', |
|
88
|
|
|
'superadmin' => true, |
|
89
|
|
|
'enabled' => true, |
|
90
|
|
|
'locked' => false, |
|
91
|
|
|
'mine' => 'mine5-mine', |
|
92
|
|
|
), |
|
93
|
|
|
array( |
|
94
|
|
|
'name' => 'user6', |
|
95
|
|
|
'superadmin' => true, |
|
96
|
|
|
'enabled' => true, |
|
97
|
|
|
'locked' => false, |
|
98
|
|
|
'mine' => 'mine6-mine', |
|
99
|
|
|
), |
|
100
|
|
|
array( |
|
101
|
|
|
'name' => 'user7', |
|
102
|
|
|
'superadmin' => true, |
|
103
|
|
|
'enabled' => true, |
|
104
|
|
|
'locked' => false, |
|
105
|
|
|
'mine' => 'mine7-mine', |
|
106
|
|
|
), |
|
107
|
|
|
array( |
|
108
|
|
|
'name' => 'user8', |
|
109
|
|
|
'superadmin' => true, |
|
110
|
|
|
'enabled' => true, |
|
111
|
|
|
'locked' => false, |
|
112
|
|
|
'mine' => 'mine8-mine', |
|
113
|
|
|
), |
|
114
|
|
|
array( |
|
115
|
|
|
'name' => 'user9', |
|
116
|
|
|
'superadmin' => true, |
|
117
|
|
|
'enabled' => true, |
|
118
|
|
|
'locked' => false, |
|
119
|
|
|
'mine' => 'mine9-mine', |
|
120
|
|
|
), |
|
121
|
|
|
array( |
|
122
|
|
|
'name' => 'user10', |
|
123
|
|
|
'superadmin' => true, |
|
124
|
|
|
'enabled' => true, |
|
125
|
|
|
'locked' => false, |
|
126
|
|
|
'mine' => 'mine10-mine', |
|
127
|
|
|
), |
|
128
|
|
|
); |
|
129
|
|
|
$userManager = $this->container->get('fos_user.user_manager'); |
|
130
|
|
|
$objectList = array(); |
|
131
|
|
|
|
|
132
|
|
|
foreach ($dataArray as $i => $data) { |
|
133
|
|
|
$objectList[$i] = $userManager->createUser(); |
|
134
|
|
|
$objectList[$i]->setUsername($data['name']); |
|
135
|
|
|
$objectList[$i]->setEmail($data['name'].'@example.com'); |
|
136
|
|
|
$objectList[$i]->setEnabled($data['enabled']); |
|
137
|
|
|
$objectList[$i]->setPlainPassword('pass4'.$data['name']); |
|
138
|
|
|
$objectList[$i]->setEmail($data['name'].'@example.com'); |
|
139
|
|
|
$objectList[$i]->setSuperAdmin($data['superadmin']); |
|
140
|
|
|
$objectList[$i]->setLocked($data['locked']); |
|
141
|
|
|
$objectList[$i]->setMine($this->getReference($data['mine'])); |
|
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
$userManager->updateUser($objectList[$i]); |
|
144
|
|
|
|
|
145
|
|
|
$ref = $data['name'].'-user'; |
|
146
|
|
|
$this->addReference($ref, $objectList[$i]); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Sets the Container. |
|
152
|
|
|
* |
|
153
|
|
|
* @param ContainerInterface|null $container A ContainerInterface |
|
154
|
|
|
* |
|
155
|
|
|
* |
|
156
|
|
|
* @codeCoverageIgnore |
|
157
|
|
|
*/ |
|
158
|
|
|
public function setContainer(ContainerInterface $container = null) |
|
159
|
|
|
{ |
|
160
|
|
|
$this->container = $container; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Get the order of this fixture. |
|
165
|
|
|
* |
|
166
|
|
|
* @return int |
|
167
|
|
|
* |
|
168
|
|
|
* @codeCoverageIgnore |
|
169
|
|
|
*/ |
|
170
|
|
|
public function getOrder() |
|
171
|
|
|
{ |
|
172
|
|
|
return 20; |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.