Completed
Pull Request — master (#4)
by Alessandro
02:58
created
src/Controller/Component/UserPermissionsComponent.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -36,21 +36,21 @@  discard block
 block discarded – undo
36 36
 *
37 37
 * @param string $event The event to use.
38 38
 */
39
-    public function initialize(array $config)
40
-    {
41
-        parent::initialize($config);
39
+	public function initialize(array $config)
40
+	{
41
+		parent::initialize($config);
42 42
         
43
-        $this->controller = $this->_registry->getController();
44
-        $this->session = $this->controller->request->session();
43
+		$this->controller = $this->_registry->getController();
44
+		$this->session = $this->controller->request->session();
45 45
 
46
-        $this->actions 		= array();
46
+		$this->actions 		= array();
47 47
 		$this->allow 		= true;
48 48
 		$this->redirect 	= '';
49 49
 		$this->params 		= '';
50 50
 		$this->message 		= '';
51 51
 		$this->userType 	= '';
52 52
 		$this->action   	= null;
53
-    }
53
+	}
54 54
 
55 55
 /**
56 56
 * Initialization to get controller variable
@@ -58,45 +58,45 @@  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) {
62
-    	$this->setUserValues();
63
-    	$this->bindConfiguration($rules);
61
+	public function allow ($rules) {
62
+		$this->setUserValues();
63
+		$this->bindConfiguration($rules);
64 64
 
65 65
 		if (!$this->applyGroupsRules($rules)) {
66 66
 			$this->applyViewsRules($rules);
67 67
 		}
68 68
 
69 69
 		return $this->allow;
70
-    }
70
+	}
71 71
 
72
-    private function setUserValues()
73
-    {
74
-    	$userId = $this->session->read('Auth.User.id');
72
+	private function setUserValues()
73
+	{
74
+		$userId = $this->session->read('Auth.User.id');
75 75
 
76
-    	if (!isset($userId)) {
76
+		if (!isset($userId)) {
77 77
 			$this->userType = 'guest';
78 78
 		}
79
-    }
79
+	}
80 80
 
81
-    private function bindConfiguration(array $rules) 
82
-    {
83
-    	foreach($rules as $key => $value){
81
+	private function bindConfiguration(array $rules) 
82
+	{
83
+		foreach($rules as $key => $value){
84 84
 			switch($key){
85 85
 				case "user_type":
86
-			        $this->userType = $value;
87
-			        break;
88
-			    case "redirect":
89
-			        $this->redirect = $value;
90
-			        break;
91
-			    case "action":
92
-			        $this->action = $value;
93
-			        break;
94
-			    case "controller":
95
-			        $this->controller = $value;
96
-			        break;
97
-			    case "message":
98
-			        $this->message = $value;
99
-			        break;
86
+					$this->userType = $value;
87
+					break;
88
+				case "redirect":
89
+					$this->redirect = $value;
90
+					break;
91
+				case "action":
92
+					$this->action = $value;
93
+					break;
94
+				case "controller":
95
+					$this->controller = $value;
96
+					break;
97
+				case "message":
98
+					$this->message = $value;
99
+					break;
100 100
 			}
101 101
 		}
102 102
 
@@ -107,61 +107,61 @@  discard block
 block discarded – undo
107 107
 				}
108 108
 			}
109 109
 		}
110
-    }
110
+	}
111 111
 
112
-    private function applyGroupsRules(array $rules) : bool
113
-    {
114
-    	$existRulesForGroups = false;
112
+	private function applyGroupsRules(array $rules) : bool
113
+	{
114
+		$existRulesForGroups = false;
115 115
 
116
-    	if(isset($rules['groups'])){
116
+		if(isset($rules['groups'])){
117 117
 			foreach($rules['groups'] as $key => $value){
118 118
 				$this->searchForApplyGroupRules($key, $value);
119 119
 			}
120 120
 		}
121 121
 
122 122
 		return $existRulesForGroups;
123
-    }
123
+	}
124 124
 
125
-    private function searchForApplyGroupRules($key, $value)
126
-    {
127
-    	if($key == $this->userType){
128
-    		if ($this->notInArrayAction()) {
125
+	private function searchForApplyGroupRules($key, $value)
126
+	{
127
+		if($key == $this->userType){
128
+			if ($this->notInArrayAction()) {
129 129
 				$existRulesForGroups = true;
130 130
 				$this->redirectIfIsSet();
131 131
 				
132 132
 				$this->allow = false;
133 133
 			}
134 134
 		}
135
-    }
135
+	}
136 136
 
137
-    private function notInArrayAction()
138
-    {
139
-    	return ((!in_array('*', $this->actions)) && (!in_array($this->action, $this->actions)));
140
-    }
137
+	private function notInArrayAction()
138
+	{
139
+		return ((!in_array('*', $this->actions)) && (!in_array($this->action, $this->actions)));
140
+	}
141 141
 
142
-    private function applyViewsRules(array $rules)
143
-    {
144
-    	if(isset($rules['views'])){
142
+	private function applyViewsRules(array $rules)
143
+	{
144
+		if(isset($rules['views'])){
145 145
 			foreach($rules['views'] as $key => $value){
146 146
 				$this->searchForApplyViewRules($key, $value);
147 147
 			}
148 148
 		}
149
-    }
149
+	}
150 150
 
151
-    private function searchForApplyViewRules($key, $value)
152
-    {
153
-    	if($key == $this->action){
151
+	private function searchForApplyViewRules($key, $value)
152
+	{
153
+		if($key == $this->action){
154 154
 			if(!$this->controller->$value()){
155 155
 				$this->redirectIfIsSet();
156 156
 				
157 157
 				$this->allow = false;
158 158
 			}
159 159
 		}
160
-    }
160
+	}
161 161
 
162
-    private function redirectIfIsSet()
163
-    {
164
-    	if($this->redirect != ''){
162
+	private function redirectIfIsSet()
163
+	{
164
+		if($this->redirect != ''){
165 165
 			if($this->message != ''){
166 166
 				$this->Flash->set($this->message);
167 167
 			}
Please login to merge, or discard this 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.