|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* The MIT License (MIT) |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2014-2016 Spomky-Labs |
|
7
|
|
|
* |
|
8
|
|
|
* This software may be modified and distributed under the terms |
|
9
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace SpomkyLabs\RoleHierarchyBundle\Model; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
|
15
|
|
|
|
|
16
|
|
|
class RoleManager implements RoleManagerInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $class; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var \Doctrine\Common\Persistence\ObjectManager |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $entity_manager; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var \Doctrine\Common\Persistence\ObjectRepository |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $entity_repository; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* RoleManager constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param \Doctrine\Common\Persistence\ManagerRegistry $manager_registry |
|
37
|
|
|
* @param string $class |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(ManagerRegistry $manager_registry, $class) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->class = $class; |
|
42
|
|
|
$this->entity_manager = $manager_registry->getManagerForClass($class); |
|
43
|
|
|
$this->entity_repository = $this->entity_manager->getRepository($class); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getEntityManager() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->entity_manager; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getEntityRepository() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->entity_repository; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getRoles() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->getEntityRepository()->findAll(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getClass() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->class; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* {@inheritdoc} |
|
80
|
|
|
*/ |
|
81
|
|
|
public function createRole() |
|
82
|
|
|
{ |
|
83
|
|
|
$class = $this->getClass(); |
|
84
|
|
|
|
|
85
|
|
|
return new $class(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* {@inheritdoc} |
|
90
|
|
|
*/ |
|
91
|
|
|
public function saveRole(RoleInterface $role) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->getEntityManager()->persist($role); |
|
94
|
|
|
$this->getEntityManager()->flush(); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|