Total Complexity | 6 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
18 | abstract class AbstractIniter implements RbacIniterInterface |
||
19 | { |
||
20 | /** |
||
21 | * Provides a tree of permissions to be set in AuthManager. |
||
22 | * |
||
23 | * @return array where: |
||
24 | * - key: role name |
||
25 | * - value: role items |
||
26 | */ |
||
27 | abstract public function getTree(); |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function init(AuthManager $auth) |
||
33 | { |
||
34 | foreach (array_keys($this->getTree()) as $role) { |
||
35 | $auth->setRole($role); |
||
36 | } |
||
37 | |||
38 | foreach ($this->getTree() as $role => $items) { |
||
39 | foreach ($items as $name) { |
||
40 | $item = $auth->getItem($name); |
||
41 | if ($item === null) { |
||
42 | $item = $auth->setPermission($name); |
||
43 | $auth->setPermission("deny:$name"); |
||
44 | } |
||
45 | $auth->setChild($role, $item); |
||
46 | } |
||
47 | } |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | public function reinit(AuthManager $auth) |
||
57 | } |
||
58 | } |
||
59 |