Completed
Pull Request — master (#4)
by Alessandro
02:58
created
src/Controller/Component/UserPermissionsComponent.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
43 43
         $this->controller = $this->_registry->getController();
44 44
         $this->session = $this->controller->request->session();
45 45
 
46
-        $this->actions 		= array();
47
-		$this->allow 		= true;
46
+        $this->actions = array();
47
+		$this->allow = true;
48 48
 		$this->redirect 	= '';
49
-		$this->params 		= '';
49
+		$this->params = '';
50 50
 		$this->message 		= '';
51 51
 		$this->userType 	= '';
52 52
 		$this->action   	= null;
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 * @param array $rules Array of rules for permissions.
59 59
 * @return string '0' if user / group doesn't have permission, 1 if has permission
60 60
 */
61
-    public function allow ($rules) {
61
+    public function allow($rules) {
62 62
     	$this->setUserValues();
63 63
     	$this->bindConfiguration($rules);
64 64
 
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
 
81 81
     private function bindConfiguration(array $rules) 
82 82
     {
83
-    	foreach($rules as $key => $value){
84
-			switch($key){
83
+    	foreach ($rules as $key => $value) {
84
+			switch ($key) {
85 85
 				case "user_type":
86 86
 			        $this->userType = $value;
87 87
 			        break;
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
 			}
101 101
 		}
102 102
 
103
-		foreach($rules['groups']  as $key => $value){
104
-			if($key == $this->userType){
105
-				foreach($value as $v){
103
+		foreach ($rules['groups']  as $key => $value) {
104
+			if ($key == $this->userType) {
105
+				foreach ($value as $v) {
106 106
 					array_push($this->actions, $v);
107 107
 				}
108 108
 			}
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
     {
114 114
     	$existRulesForGroups = false;
115 115
 
116
-    	if(isset($rules['groups'])){
117
-			foreach($rules['groups'] as $key => $value){
116
+    	if (isset($rules['groups'])) {
117
+			foreach ($rules['groups'] as $key => $value) {
118 118
 				$this->searchForApplyGroupRules($key, $value);
119 119
 			}
120 120
 		}
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 
125 125
     private function searchForApplyGroupRules($key, $value)
126 126
     {
127
-    	if($key == $this->userType){
127
+    	if ($key == $this->userType) {
128 128
     		if ($this->notInArrayAction()) {
129 129
 				$existRulesForGroups = true;
130 130
 				$this->redirectIfIsSet();
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
 
142 142
     private function applyViewsRules(array $rules)
143 143
     {
144
-    	if(isset($rules['views'])){
145
-			foreach($rules['views'] as $key => $value){
144
+    	if (isset($rules['views'])) {
145
+			foreach ($rules['views'] as $key => $value) {
146 146
 				$this->searchForApplyViewRules($key, $value);
147 147
 			}
148 148
 		}
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
 
151 151
     private function searchForApplyViewRules($key, $value)
152 152
     {
153
-    	if($key == $this->action){
154
-			if(!$this->controller->$value()){
153
+    	if ($key == $this->action) {
154
+			if (!$this->controller->$value()) {
155 155
 				$this->redirectIfIsSet();
156 156
 				
157 157
 				$this->allow = false;
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 
162 162
     private function redirectIfIsSet()
163 163
     {
164
-    	if($this->redirect != ''){
165
-			if($this->message != ''){
164
+    	if ($this->redirect != '') {
165
+			if ($this->message != '') {
166 166
 				$this->Flash->set($this->message);
167 167
 			}
168 168
 			
Please login to merge, or discard this patch.