Total Complexity | 11 |
Total Lines | 136 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
7 | class RoleManager extends ApplicationProvider implements RoleInterface |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $adapter = 'Database'; |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $resource = 'Resta\\Role\\Resource'; |
||
18 | |||
19 | /** |
||
20 | * @var null|string |
||
21 | */ |
||
22 | protected $role; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $routeName; |
||
28 | |||
29 | /** |
||
30 | * passing directly |
||
31 | * |
||
32 | * @return bool |
||
33 | */ |
||
34 | public function directly() |
||
35 | { |
||
36 | return true; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * get resource path |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | public function getAdapter() |
||
45 | { |
||
46 | return $this->adapter; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * get resource path |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | public function getResource() |
||
55 | { |
||
56 | return $this->resource; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function make() |
||
63 | { |
||
64 | $permission = $this->getPermission(); |
||
65 | $role = $this->getRole(); |
||
66 | |||
67 | if(is_null($this->role)){ |
||
68 | return $permission::permissionMake($this->routeName); |
||
69 | } |
||
70 | else{ |
||
71 | return $role::roleMake($this->role); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * role name for role manager |
||
77 | * |
||
78 | * @param $name |
||
79 | * @return $this |
||
80 | */ |
||
81 | public function role($name) |
||
82 | { |
||
83 | $this->role = $name; |
||
84 | |||
85 | return $this; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * route name for role manager |
||
90 | * |
||
91 | * @param $name |
||
92 | * @return $this |
||
93 | */ |
||
94 | public function routeName($name) |
||
95 | { |
||
96 | $this->routeName = $name; |
||
97 | |||
98 | return $this; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * set adapter name |
||
103 | * |
||
104 | * @param string $adapter |
||
105 | * @return RoleManager |
||
106 | */ |
||
107 | public function setAdapter($adapter='Database') |
||
108 | { |
||
109 | $this->adapter = $adapter; |
||
110 | |||
111 | return $this; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * set resource path |
||
116 | * |
||
117 | * @param $resource |
||
118 | * @return void |
||
119 | */ |
||
120 | public function setResource($resource) |
||
121 | { |
||
122 | $this->resource = $resource; |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * get permission |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | private function getPermission() |
||
131 | { |
||
132 | return $this->getResource().'\\'.$this->getAdapter().'\Permission'; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * get permission |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | private function getRole() |
||
143 | } |
||
144 | } |