|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the O2System Framework package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Steeve Andrian Salim |
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Created by PhpStorm. |
|
14
|
|
|
* User: steevenz |
|
15
|
|
|
* Date: 02/07/18 |
|
16
|
|
|
* Time: 09.52 |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace O2System\Security\Authentication\User; |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
use O2System\Spl\Patterns\Structural\Repository\AbstractRepository; |
|
23
|
|
|
|
|
24
|
|
|
class Authority extends AbstractRepository |
|
25
|
|
|
{ |
|
26
|
|
|
public function __construct(array $role) |
|
27
|
|
|
{ |
|
28
|
|
|
foreach ($role as $key => $value) { |
|
29
|
|
|
$this->store($key, $value); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function store($offset, $data) |
|
34
|
|
|
{ |
|
35
|
|
|
if ($offset === 'permission') { |
|
36
|
|
|
if (in_array($data, ['GRANTED', 'DENIED'])) { |
|
37
|
|
|
$data = strtoupper($data); |
|
38
|
|
|
} else { |
|
39
|
|
|
return; |
|
40
|
|
|
} |
|
41
|
|
|
} elseif ($offset === 'privileges') { |
|
42
|
|
|
list($create, $read, $update, $delete, $import, $export, $print, $special) = array_pad(str_split($data), 8, |
|
43
|
|
|
0); |
|
44
|
|
|
$data = [ |
|
45
|
|
|
'create' => ($create == '1' ? true : false), |
|
46
|
|
|
'read' => ($read == '1' ? true : false), |
|
47
|
|
|
'update' => ($update == '1' ? true : false), |
|
48
|
|
|
'delete' => ($delete == '1' ? true : false), |
|
49
|
|
|
'import' => ($import == '1' ? true : false), |
|
50
|
|
|
'export' => ($export == '1' ? true : false), |
|
51
|
|
|
'print' => ($print == '1' ? true : false), |
|
52
|
|
|
'special' => ($special == '1' ? true : false), |
|
53
|
|
|
]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
parent::store($offset, $data); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getPermission() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->get('permission'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getPrivileges() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->get('privileges'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function hasCreatePrivilege() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->checkPrivilege('create'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function checkPrivilege($action) |
|
75
|
|
|
{ |
|
76
|
|
|
if ($privileges = $this->get('privileges')) { |
|
77
|
|
|
return (bool)$privileges[ $action ]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return false; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function hasReadPrivilege() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->checkPrivilege('read'); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function hasUpdatePrivilage() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->checkPrivilege('update'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function hasDeletePrivilage() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->checkPrivilege('delete'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function hasImportPrivilege() |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->checkPrivilege('import'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function hasExportPrivilege() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->checkPrivilege('export'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function hasPrintPrivilege() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->checkPrivilege('print'); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function hasSpecialPrivilege() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->checkPrivilege('special'); |
|
116
|
|
|
} |
|
117
|
|
|
} |