@@ -68,14 +68,14 @@ discard block |
||
| 68 | 68 | $this->controller = $this->_registry->getController(); |
| 69 | 69 | $this->session = $this->controller->request->session(); |
| 70 | 70 | |
| 71 | - $this->actions = array(); |
|
| 72 | - $this->allow = true; |
|
| 71 | + $this->actions = array(); |
|
| 72 | + $this->allow = true; |
|
| 73 | 73 | $this->redirect = ''; |
| 74 | - $this->params = ''; |
|
| 74 | + $this->params = ''; |
|
| 75 | 75 | $this->message = ''; |
| 76 | 76 | $this->userType = ''; |
| 77 | 77 | $this->action = null; |
| 78 | - $this->throwEx = isset($config["throwEx"]) && $config["throwEx"]; |
|
| 78 | + $this->throwEx = isset($config["throwEx"]) && $config["throwEx"]; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param array $rules Array of rules for permissions. |
| 85 | 85 | * @return bool false if user / group doesn't have permission, true if has permission |
| 86 | 86 | */ |
| 87 | - public function allow ($rules) { |
|
| 87 | + public function allow($rules) { |
|
| 88 | 88 | $this->setUserValues(); |
| 89 | 89 | $this->bindConfiguration($rules); |
| 90 | 90 | |
@@ -106,18 +106,18 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | private function bindConfiguration(array $rules) |
| 108 | 108 | { |
| 109 | - foreach(array("user_type", "redirect", "action", "controller", "message") as $key) { |
|
| 110 | - if(isset($rules[$key])) { |
|
| 109 | + foreach (array("user_type", "redirect", "action", "controller", "message") as $key) { |
|
| 110 | + if (isset($rules[$key])) { |
|
| 111 | 111 | $this->$key = $value; |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | - if(!is_object($value)) { |
|
| 114 | + if (!is_object($value)) { |
|
| 115 | 115 | Log::write("warning", sprintf("controller is not an object (%s)", gettype($value))); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - foreach($rules['groups'] as $key => $value){ |
|
| 119 | - if($key == $this->userType){ |
|
| 120 | - foreach($value as $v){ |
|
| 118 | + foreach ($rules['groups'] as $key => $value) { |
|
| 119 | + if ($key == $this->userType) { |
|
| 120 | + foreach ($value as $v) { |
|
| 121 | 121 | array_push($this->actions, $v); |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | { |
| 129 | 129 | $existRulesForGroups = false; |
| 130 | 130 | |
| 131 | - if(isset($rules['groups'])){ |
|
| 132 | - foreach($rules['groups'] as $key => $value){ |
|
| 131 | + if (isset($rules['groups'])) { |
|
| 132 | + foreach ($rules['groups'] as $key => $value) { |
|
| 133 | 133 | $this->searchForApplyGroupRules($key, $value); |
| 134 | 134 | } |
| 135 | 135 | } |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | private function searchForApplyGroupRules($key) |
| 141 | 141 | { |
| 142 | - if($key == $this->userType){ |
|
| 142 | + if ($key == $this->userType) { |
|
| 143 | 143 | if ($this->notInArrayAction()) { |
| 144 | 144 | $this->redirectIfIsSet(); |
| 145 | 145 | |
@@ -155,8 +155,8 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | private function applyViewsRules(array $rules) |
| 157 | 157 | { |
| 158 | - if(isset($rules['views'])){ |
|
| 159 | - foreach($rules['views'] as $key => $value){ |
|
| 158 | + if (isset($rules['views'])) { |
|
| 159 | + foreach ($rules['views'] as $key => $value) { |
|
| 160 | 160 | $this->searchForApplyViewRules($key, $value); |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | private function searchForApplyViewRules($key, $value) |
| 166 | 166 | { |
| 167 | - if($key == $this->action) { |
|
| 168 | - if(!$this->checkForHandler($this->controller, $value) || !$this->controller->$value()){ |
|
| 167 | + if ($key == $this->action) { |
|
| 168 | + if (!$this->checkForHandler($this->controller, $value) || !$this->controller->$value()) { |
|
| 169 | 169 | $this->redirectIfIsSet(); |
| 170 | 170 | |
| 171 | 171 | $this->allow = false; |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | private function checkForHandler($controller, $handler) |
| 177 | 177 | { |
| 178 | - if(!method_exists($controller, $handler)) { |
|
| 178 | + if (!method_exists($controller, $handler)) { |
|
| 179 | 179 | $msg = sprintf( |
| 180 | 180 | "Controller %s=%s has no method called '%s'", |
| 181 | 181 | is_object($controller) ? "class" : "type", |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $handler |
| 184 | 184 | ); |
| 185 | 185 | Log::write("debug", $msg); |
| 186 | - if($this->throwEx) { |
|
| 186 | + if ($this->throwEx) { |
|
| 187 | 187 | throw new MissingHandlerException($msg); |
| 188 | 188 | } |
| 189 | 189 | return false; |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | private function redirectIfIsSet() |
| 196 | 196 | { |
| 197 | - if($this->redirect != ''){ |
|
| 198 | - if($this->message != ''){ |
|
| 197 | + if ($this->redirect != '') { |
|
| 198 | + if ($this->message != '') { |
|
| 199 | 199 | $this->Flash->set($this->message); |
| 200 | 200 | } |
| 201 | 201 | |