|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Webcook security bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* See LICENSE file in the root of the bundle. Webcook |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Webcook\Cms\SecurityBundle\DataFixtures\ORM; |
|
10
|
|
|
|
|
11
|
|
|
use Doctrine\Common\DataFixtures\FixtureInterface; |
|
12
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
13
|
|
|
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; |
|
14
|
|
|
use Webcook\Cms\SecurityBundle\Entity\Role; |
|
15
|
|
|
use Webcook\Cms\SecurityBundle\Entity\RoleResource; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Role fixtures for tests. |
|
21
|
|
|
*/ |
|
22
|
|
|
class LoadRoleData implements FixtureInterface, ContainerAwareInterface, OrderedFixtureInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* System container. |
|
26
|
|
|
* |
|
27
|
|
|
* @var ContainerInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $container; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Entity manager. |
|
33
|
|
|
* |
|
34
|
|
|
* @var ObjectManager |
|
35
|
|
|
*/ |
|
36
|
|
|
private $manager; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Set container. |
|
40
|
|
|
* |
|
41
|
|
|
* {@inheritDoc} |
|
42
|
|
|
* @param ContainerInterface $container [description] |
|
43
|
|
|
*/ |
|
44
|
49 |
|
public function setContainer(ContainerInterface $container = null) |
|
45
|
|
|
{ |
|
46
|
49 |
|
$this->container = $container; |
|
47
|
49 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Load fixtures into db. |
|
51
|
|
|
* |
|
52
|
|
|
* @param ObjectManager $manager |
|
53
|
|
|
* {@inheritDoc} |
|
54
|
|
|
*/ |
|
55
|
49 |
|
public function load(ObjectManager $manager) |
|
56
|
|
|
{ |
|
57
|
49 |
|
$this->manager = $manager; |
|
58
|
|
|
|
|
59
|
49 |
|
$role = new Role(); |
|
60
|
49 |
|
$role->setName('Administrator'); |
|
61
|
49 |
|
$role->setRole('ROLE_ADMIN'); |
|
62
|
|
|
|
|
63
|
49 |
|
$this->manager->persist($role); |
|
64
|
|
|
|
|
65
|
49 |
|
$this->addResources($role); |
|
66
|
|
|
|
|
67
|
49 |
|
$role = new Role(); |
|
68
|
49 |
|
$role->setName('Editor'); |
|
69
|
49 |
|
$role->setRole('ROLE_EDITOR'); |
|
70
|
|
|
|
|
71
|
49 |
|
$this->manager->persist($role); |
|
72
|
|
|
|
|
73
|
49 |
|
$this->addResources($role, false); |
|
74
|
|
|
|
|
75
|
49 |
|
$this->manager->flush(); |
|
76
|
49 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Add resources into role object. |
|
80
|
|
|
* |
|
81
|
|
|
* @param Role $role [description] |
|
82
|
|
|
* @param boolean $admin [description] |
|
83
|
|
|
*/ |
|
84
|
49 |
|
private function addResources(Role $role, $admin = true) |
|
85
|
|
|
{ |
|
86
|
49 |
|
$resources = $this->manager->getRepository('Webcook\Cms\SecurityBundle\Entity\Resource')->findAll(); |
|
87
|
|
|
|
|
88
|
49 |
|
foreach ($resources as $resource) { |
|
89
|
49 |
|
$roleResource = new RoleResource(); |
|
90
|
49 |
|
$roleResource->setRole($role); |
|
91
|
49 |
|
$roleResource->setResource($resource); |
|
92
|
49 |
|
$roleResource->setEdit($admin); |
|
93
|
49 |
|
$roleResource->setInsert($admin); |
|
94
|
49 |
|
$roleResource->setDelete($admin); |
|
95
|
|
|
|
|
96
|
49 |
|
$this->manager->persist($roleResource); |
|
97
|
|
|
} |
|
98
|
49 |
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get fixture order. |
|
102
|
|
|
* |
|
103
|
|
|
* {@inheritdoc} |
|
104
|
|
|
* |
|
105
|
|
|
* @return [type] [description] |
|
|
|
|
|
|
106
|
|
|
*/ |
|
107
|
49 |
|
public function getOrder() |
|
108
|
|
|
{ |
|
109
|
49 |
|
return 1; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.