|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* LoadUserData Données User de l'application GLSR. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @author Quétier Laurent <[email protected]> |
|
8
|
|
|
* @copyright 2014 Dev-Int GLSR |
|
9
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
10
|
|
|
* |
|
11
|
|
|
* @version GIT: <git_id> |
|
12
|
|
|
* |
|
13
|
|
|
* @link https://github.com/Dev-Int/glsr |
|
14
|
|
|
*/ |
|
15
|
|
|
namespace AppBundle\DataFixtures\ORM; |
|
16
|
|
|
|
|
17
|
|
|
use Doctrine\Common\DataFixtures\AbstractFixture; |
|
18
|
|
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; |
|
19
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
22
|
|
|
use AppBundle\Entity\Staff\User; |
|
23
|
|
|
use AppBundle\Entity\Staff\Group; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* LoadUser Data. |
|
27
|
|
|
* |
|
28
|
|
|
* @category DataFixtures |
|
29
|
|
|
*/ |
|
30
|
|
|
class LoadUserData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var ContainerInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
private $container; |
|
36
|
|
|
|
|
37
|
|
|
public function setContainer(ContainerInterface $container = null) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->container = $container; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function load(ObjectManager $manager) |
|
43
|
|
|
{ |
|
44
|
|
|
$userAdmin = new User(); |
|
45
|
|
|
$userAdmin->setUsername('Admin'); |
|
46
|
|
|
$userAdmin->setEmail('admin@localhost'); |
|
47
|
|
|
$userAdmin->setEnabled(true); |
|
48
|
|
|
$userAdmin->setSalt(md5(uniqid())); |
|
49
|
|
|
|
|
50
|
|
|
// the 'security.password_encoder' service requires Symfony 2.6 or higher |
|
51
|
|
|
$encoder = $this->container->get('security.password_encoder'); |
|
52
|
|
|
$password = $encoder->encodePassword($userAdmin, 'admin'); |
|
53
|
|
|
$userAdmin->setPassword($password); |
|
54
|
|
|
|
|
55
|
|
|
$group = new Group('admin', 'ROLE_SUPER_ADMIN'); |
|
|
|
|
|
|
56
|
|
|
var_dump($group); |
|
|
|
|
|
|
57
|
|
|
$userAdmin->setGroups($group->getId(1)); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
$manager->persist($userAdmin); |
|
60
|
|
|
$manager->flush(); |
|
61
|
|
|
|
|
62
|
|
|
$this->addReference('admin-user', $userAdmin); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getOrder() |
|
66
|
|
|
{ |
|
67
|
|
|
return 2; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: