| @@ -189,6 +189,9 @@ | ||
| 189 | 189 | } | 
| 190 | 190 | } | 
| 191 | 191 | |
| 192 | + /** | |
| 193 | + * @param string $controller | |
| 194 | + */ | |
| 192 | 195 | private function checkForHandler($controller, $handler) | 
| 193 | 196 |  	{ | 
| 194 | 197 |  		if(!method_exists($controller, $handler)) { | 
| @@ -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,8 +106,8 @@ discard block | ||
| 106 | 106 | |
| 107 | 107 | private function bindConfiguration(array $rules) | 
| 108 | 108 |      { | 
| 109 | -    	foreach($rules as $key => $value){ | |
| 110 | -			switch($key){ | |
| 109 | +    	foreach ($rules as $key => $value) { | |
| 110 | +			switch ($key) { | |
| 111 | 111 | case "user_type": | 
| 112 | 112 | $this->userType = $value; | 
| 113 | 113 | break; | 
| @@ -119,7 +119,7 @@ discard block | ||
| 119 | 119 | break; | 
| 120 | 120 | case "controller": | 
| 121 | 121 | $this->controller = $value; | 
| 122 | -					if(!is_object($value)) { | |
| 122 | +					if (!is_object($value)) { | |
| 123 | 123 |  						Log::write("warning", sprintf("controller is not an object (%s)", gettype($value))); | 
| 124 | 124 | } | 
| 125 | 125 | break; | 
| @@ -129,9 +129,9 @@ discard block | ||
| 129 | 129 | } | 
| 130 | 130 | } | 
| 131 | 131 | |
| 132 | -		foreach($rules['groups']  as $key => $value){ | |
| 133 | -			if($key == $this->userType){ | |
| 134 | -				foreach($value as $v){ | |
| 132 | +		foreach ($rules['groups']  as $key => $value) { | |
| 133 | +			if ($key == $this->userType) { | |
| 134 | +				foreach ($value as $v) { | |
| 135 | 135 | array_push($this->actions, $v); | 
| 136 | 136 | } | 
| 137 | 137 | } | 
| @@ -142,8 +142,8 @@ discard block | ||
| 142 | 142 |      { | 
| 143 | 143 | $existRulesForGroups = false; | 
| 144 | 144 | |
| 145 | -    	if(isset($rules['groups'])){ | |
| 146 | -			foreach($rules['groups'] as $key => $value){ | |
| 145 | +    	if (isset($rules['groups'])) { | |
| 146 | +			foreach ($rules['groups'] as $key => $value) { | |
| 147 | 147 | $this->searchForApplyGroupRules($key, $value); | 
| 148 | 148 | } | 
| 149 | 149 | } | 
| @@ -153,7 +153,7 @@ discard block | ||
| 153 | 153 | |
| 154 | 154 | private function searchForApplyGroupRules($key) | 
| 155 | 155 |      { | 
| 156 | -    	if($key == $this->userType){ | |
| 156 | +    	if ($key == $this->userType) { | |
| 157 | 157 |      		if ($this->notInArrayAction()) { | 
| 158 | 158 | $this->redirectIfIsSet(); | 
| 159 | 159 | |
| @@ -169,8 +169,8 @@ discard block | ||
| 169 | 169 | |
| 170 | 170 | private function applyViewsRules(array $rules) | 
| 171 | 171 |      { | 
| 172 | -    	if(isset($rules['views'])){ | |
| 173 | -			foreach($rules['views'] as $key => $value){ | |
| 172 | +    	if (isset($rules['views'])) { | |
| 173 | +			foreach ($rules['views'] as $key => $value) { | |
| 174 | 174 | $this->searchForApplyViewRules($key, $value); | 
| 175 | 175 | } | 
| 176 | 176 | } | 
| @@ -178,8 +178,8 @@ discard block | ||
| 178 | 178 | |
| 179 | 179 | private function searchForApplyViewRules($key, $value) | 
| 180 | 180 |      { | 
| 181 | -    	if($key == $this->action) { | |
| 182 | -			if(!$this->checkForHandler($this->controller, $value) || !$this->controller->$value()){ | |
| 181 | +    	if ($key == $this->action) { | |
| 182 | +			if (!$this->checkForHandler($this->controller, $value) || !$this->controller->$value()) { | |
| 183 | 183 | $this->redirectIfIsSet(); | 
| 184 | 184 | |
| 185 | 185 | $this->allow = false; | 
| @@ -189,7 +189,7 @@ discard block | ||
| 189 | 189 | |
| 190 | 190 | private function checkForHandler($controller, $handler) | 
| 191 | 191 |  	{ | 
| 192 | -		if(!method_exists($controller, $handler)) { | |
| 192 | +		if (!method_exists($controller, $handler)) { | |
| 193 | 193 | $msg = sprintf( | 
| 194 | 194 | "Controller %s=%s has no method called '%s'", | 
| 195 | 195 | is_object($controller) ? "class" : "type", | 
| @@ -197,7 +197,7 @@ discard block | ||
| 197 | 197 | $handler | 
| 198 | 198 | ); | 
| 199 | 199 |  			Log::write("debug", $msg); | 
| 200 | -			if($this->throwEx) { | |
| 200 | +			if ($this->throwEx) { | |
| 201 | 201 | throw new MissingHandlerException($msg); | 
| 202 | 202 | } | 
| 203 | 203 | return false; | 
| @@ -208,8 +208,8 @@ discard block | ||
| 208 | 208 | |
| 209 | 209 | private function redirectIfIsSet() | 
| 210 | 210 |      { | 
| 211 | -    	if($this->redirect != ''){ | |
| 212 | -			if($this->message != ''){ | |
| 211 | +    	if ($this->redirect != '') { | |
| 212 | +			if ($this->message != '') { | |
| 213 | 213 | $this->Flash->set($this->message); | 
| 214 | 214 | } | 
| 215 | 215 | |