|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Obblm\Core\DataFixtures; |
|
4
|
|
|
|
|
5
|
|
|
use Obblm\Core\Entity\Coach; |
|
6
|
|
|
use Doctrine\Bundle\FixturesBundle\Fixture; |
|
7
|
|
|
use Doctrine\Persistence\ObjectManager; |
|
8
|
|
|
use Obblm\Core\Security\Roles; |
|
9
|
|
|
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; |
|
10
|
|
|
|
|
11
|
|
|
class CoachFixtures extends Fixture |
|
12
|
|
|
{ |
|
13
|
|
|
private $encoder; |
|
14
|
|
|
public const ADMIN_USER_REFERENCE = 'admin-user'; |
|
15
|
|
|
public const MANAGER_USER_REFERENCE = 'manager-user'; |
|
16
|
|
|
public const COACH_USER_REFERENCE = 'coach-user'; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct(UserPasswordEncoderInterface $encoder) |
|
19
|
|
|
{ |
|
20
|
|
|
$this->encoder = $encoder; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function load(ObjectManager $em) |
|
24
|
|
|
{ |
|
25
|
|
|
$coach = (new Coach()) |
|
26
|
|
|
->setEmail('[email protected]') |
|
27
|
|
|
->setUsername('admin'); |
|
28
|
|
|
$password = $this->encoder->encodePassword($coach, 'admin'); |
|
29
|
|
|
$coach->setPassword($password); |
|
30
|
|
|
$coach->setRoles([ |
|
31
|
|
|
Roles::ADMIN |
|
32
|
|
|
]); |
|
33
|
|
|
$em->persist($coach); |
|
34
|
|
|
$this->addReference(self::ADMIN_USER_REFERENCE, $coach); |
|
35
|
|
|
$coach = (new Coach()) |
|
36
|
|
|
->setEmail('[email protected]') |
|
37
|
|
|
->setUsername('manager'); |
|
38
|
|
|
$password = $this->encoder->encodePassword($coach, 'manager'); |
|
39
|
|
|
$coach->setPassword($password); |
|
40
|
|
|
$coach->setRoles([ |
|
41
|
|
|
Roles::MANAGER |
|
42
|
|
|
]); |
|
43
|
|
|
$em->persist($coach); |
|
44
|
|
|
$this->addReference(self::MANAGER_USER_REFERENCE, $coach); |
|
45
|
|
|
$coach = (new Coach()) |
|
46
|
|
|
->setEmail('[email protected]') |
|
47
|
|
|
->setUsername('coach'); |
|
48
|
|
|
$password = $this->encoder->encodePassword($coach, 'coach'); |
|
49
|
|
|
$coach->setPassword($password); |
|
50
|
|
|
$coach->setRoles([ |
|
51
|
|
|
Roles::COACH |
|
52
|
|
|
]); |
|
53
|
|
|
$em->persist($coach); |
|
54
|
|
|
$this->addReference(self::COACH_USER_REFERENCE, $coach); |
|
55
|
|
|
|
|
56
|
|
|
$em->flush(); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|