1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Del\Passport; |
4
|
|
|
|
5
|
|
|
use Del\Passport\Entity\Passport; |
6
|
|
|
use Del\Passport\Entity\Role; |
7
|
|
|
use Doctrine\ORM\EntityManager; |
8
|
|
|
|
9
|
|
|
class PassportControl |
10
|
|
|
{ |
11
|
|
|
/** @var EntityManager */ |
12
|
|
|
private $entityManager; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* PassportControl constructor. |
16
|
|
|
* @param EntityManager $entityManager |
17
|
|
|
*/ |
18
|
|
|
public function __construct(EntityManager $entityManager) |
19
|
|
|
{ |
20
|
|
|
$this->entityManager = $entityManager; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param PassportInterface $passport |
25
|
|
|
* @param ActionInterface $action |
26
|
|
|
* @param ResourceInterface $resource |
27
|
|
|
* @return bool |
28
|
|
|
*/ |
29
|
|
|
public function isAuthorized(PassportInterface $passport, ActionInterface $action, ResourceInterface $resource): bool |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
return true; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param PassportInterface $passport |
36
|
|
|
* @param RoleInterface $role |
37
|
|
|
* @param ResourceInterface $resource |
38
|
|
|
* @return bool |
39
|
|
|
*/ |
40
|
|
|
public function grantEntitlement(PassportInterface $passport, RoleInterface $role, ResourceInterface $resource): bool |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
return true; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param PassportInterface $passport |
47
|
|
|
* @param RoleInterface $role |
48
|
|
|
* @param ResourceInterface $resource |
49
|
|
|
* @return bool |
50
|
|
|
*/ |
51
|
|
|
public function revokeEntitlement(PassportInterface $passport, RoleInterface $role, ResourceInterface $resource): bool |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
return true; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param int $userId |
58
|
|
|
* @return PassportInterface |
59
|
|
|
*/ |
60
|
|
|
public function createNewPassport(int $userId): PassportInterface |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$passport = new Passport(); |
63
|
|
|
|
64
|
|
|
return $passport; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param int $userId |
|
|
|
|
69
|
|
|
* @return PassportInterface |
70
|
|
|
*/ |
71
|
|
|
public function createNewRole(RoleInterface $role): RoleInterface |
72
|
|
|
{ |
73
|
|
|
$this->entityManager->persist($role); |
74
|
|
|
$this->entityManager->flush($role); |
75
|
|
|
|
76
|
|
|
return $role; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param int $userId |
|
|
|
|
81
|
|
|
* @return PassportInterface |
82
|
|
|
*/ |
83
|
|
|
public function removeRole(RoleInterface $role): void |
84
|
|
|
{ |
85
|
|
|
$this->entityManager->remove($role); |
86
|
|
|
$this->entityManager->flush($role); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string $name |
91
|
|
|
* @return Role|null |
92
|
|
|
*/ |
93
|
|
|
public function findRole(string $name): ?Role |
94
|
|
|
{ |
95
|
|
|
return $this->entityManager->getRepository(Role::class)->findOneBy([ |
96
|
|
|
'roleName' => $name, |
97
|
|
|
]); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.