Passed
Push — main ( cdfe2b...915a08 )
by Sammy
01:35
created
Router/RouterInterface.class.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@
 block discarded – undo
13 13
   public function match($requestUrl = null, $requestMethod = null);
14 14
   
15 15
   // generates URL for href and location
16
-  public function prehop($route, $route_params=[]);
16
+  public function prehop($route, $route_params = []);
17 17
   
18 18
   // heads to another location
19
-  public function hop($route, $route_params=[]);
19
+  public function hop($route, $route_params = []);
20 20
 
21 21
   // do you GET it ?
22 22
   public function requests() : bool;
Please login to merge, or discard this patch.
Router/AltoRouter.php 3 patches
Indentation   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -2,266 +2,266 @@
 block discarded – undo
2 2
 
3 3
 class AltoRouter {
4 4
 
5
-	/**
6
-	 * @var array Array of all routes (incl. named routes).
7
-	 */
8
-	protected $routes = [];
9
-
10
-	/**
11
-	 * @var array Array of all named routes.
12
-	 */
13
-	protected $namedRoutes = [];
14
-
15
-	/**
16
-	 * @var string Can be used to ignore leading part of the Request URL (if main file lives in subdirectory of host)
17
-	 */
18
-	protected $basePath = '';
19
-
20
-	/**
21
-	 * @var array Array of default match types (regex helpers)
22
-	 */
23
-	protected $matchTypes = array(
24
-		'i'  => '[0-9]++',
25
-		'a'  => '[0-9A-Za-z]++',
26
-		'h'  => '[0-9A-Fa-f]++',
27
-		'*'  => '.+?',
28
-		'**' => '.++',
29
-		''   => '[^/\.]++'
30
-	);
31
-
32
-	/**
33
-	  * Create router in one call from config.
34
-	  *
35
-	  * @param array $routes
36
-	  * @param string $basePath
37
-	  * @param array $matchTypes
38
-	  */
39
-	public function __construct( $routes = array(), $basePath = '', $matchTypes = array() ) {
40
-		$this->addRoutes($routes);
41
-		$this->setBasePath($basePath);
42
-		$this->addMatchTypes($matchTypes);
43
-	}
44
-
45
-	/**
46
-	 * Retrieves all routes.
47
-	 * Useful if you want to process or display routes.
48
-	 * @return array All routes.
49
-	 */
50
-	public function getRoutes() {
51
-		return $this->routes;
52
-	}
53
-
54
-	/**
55
-	 * Add multiple routes at once from array in the following format:
56
-	 *
57
-	 *   $routes = array(
58
-	 *      array($method, $route, $target, $name)
59
-	 *   );
60
-	 *
61
-	 * @param array $routes
62
-	 * @return void
63
-	 * @author Koen Punt
64
-	 * @throws Exception
65
-	 */
66
-	public function addRoutes($routes){
67
-		if(!is_array($routes) && !$routes instanceof Traversable) {
68
-			throw new \Exception('Routes should be an array or an instance of Traversable');
69
-		}
70
-		foreach($routes as $route) {
71
-			call_user_func_array(array($this, 'map'), $route);
72
-		}
73
-	}
74
-
75
-	/**
76
-	 * Set the base path.
77
-	 * Useful if you are running your application from a subdirectory.
78
-	 */
79
-	public function setBasePath($basePath) {
80
-		$this->basePath = $basePath;
81
-	}
82
-
83
-	/**
84
-	 * Add named match types. It uses array_merge so keys can be overwritten.
85
-	 *
86
-	 * @param array $matchTypes The key is the name and the value is the regex.
87
-	 */
88
-	public function addMatchTypes($matchTypes) {
89
-		$this->matchTypes = array_merge($this->matchTypes, $matchTypes);
90
-	}
91
-
92
-	/**
93
-	 * Map a route to a target
94
-	 *
95
-	 * @param string $method One of 5 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PATCH|PUT|DELETE)
96
-	 * @param string $route The route regex, custom regex must start with an @. You can use multiple pre-set regex filters, like [i:id]
97
-	 * @param mixed $target The target where this route should point to. Can be anything.
98
-	 * @param string $name Optional name of this route. Supply if you want to reverse route this url in your application.
99
-	 * @throws Exception
100
-	 */
101
-	public function map($method, $route, $target, $name = null) {
102
-
103
-		$this->routes[] = array($method, $route, $target, $name);
104
-
105
-		if($name) {
106
-			if(isset($this->namedRoutes[$name])) {
107
-				throw new \Exception("Can not redeclare route '{$name}'");
108
-			} else {
109
-				$this->namedRoutes[$name] = $route;
110
-			}
111
-
112
-		}
113
-
114
-		return;
115
-	}
116
-
117
-	/**
118
-	 * Reversed routing
119
-	 *
120
-	 * Generate the URL for a named route. Replace regexes with supplied parameters
121
-	 *
122
-	 * @param string $routeName The name of the route.
123
-	 * @param array @params Associative array of parameters to replace placeholders with.
124
-	 * @return string The URL of the route with named parameters in place.
125
-	 * @throws Exception
126
-	 */
127
-	public function generate($routeName, array $params = array()) {
128
-
129
-		// Check if named route exists
130
-		if(!isset($this->namedRoutes[$routeName])) {
131
-			throw new \Exception("Route '{$routeName}' does not exist.");
132
-		}
133
-
134
-		// Replace named parameters
135
-		$route = $this->namedRoutes[$routeName];
136
-
137
-		// prepend base path to route url again
138
-		$url = $this->basePath . $route;
139
-
140
-		if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
141
-
142
-			foreach($matches as $match) {
143
-				list($block, $pre, $type, $param, $optional) = $match;
144
-
145
-				if ($pre) {
146
-					$block = substr($block, 1);
147
-				}
148
-
149
-				if(isset($params[$param])) {
150
-					$url = str_replace($block, $params[$param], $url);
151
-				} elseif ($optional) {
152
-					$url = str_replace($pre . $block, '', $url);
153
-				}
154
-			}
155
-
156
-
157
-		}
158
-
159
-		return $url;
160
-	}
161
-
162
-	/**
163
-	 * Match a given Request Url against stored routes
164
-	 * @param string $requestUrl
165
-	 * @param string $requestMethod
166
-	 * @return array|boolean Array with route information on success, false on failure (no match).
167
-	 */
168
-	public function match($requestUrl = null, $requestMethod = null) {
169
-
170
-		$params = [];
171
-		$match = false;
172
-
173
-		// set Request Url if it isn't passed as parameter
174
-		if($requestUrl === null) {
175
-			$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
176
-		}
177
-
178
-		// strip base path from request url
179
-		$requestUrl = substr($requestUrl, strlen($this->basePath));
5
+  /**
6
+   * @var array Array of all routes (incl. named routes).
7
+   */
8
+  protected $routes = [];
9
+
10
+  /**
11
+   * @var array Array of all named routes.
12
+   */
13
+  protected $namedRoutes = [];
14
+
15
+  /**
16
+   * @var string Can be used to ignore leading part of the Request URL (if main file lives in subdirectory of host)
17
+   */
18
+  protected $basePath = '';
19
+
20
+  /**
21
+   * @var array Array of default match types (regex helpers)
22
+   */
23
+  protected $matchTypes = array(
24
+    'i'  => '[0-9]++',
25
+    'a'  => '[0-9A-Za-z]++',
26
+    'h'  => '[0-9A-Fa-f]++',
27
+    '*'  => '.+?',
28
+    '**' => '.++',
29
+    ''   => '[^/\.]++'
30
+  );
31
+
32
+  /**
33
+   * Create router in one call from config.
34
+   *
35
+   * @param array $routes
36
+   * @param string $basePath
37
+   * @param array $matchTypes
38
+   */
39
+  public function __construct( $routes = array(), $basePath = '', $matchTypes = array() ) {
40
+    $this->addRoutes($routes);
41
+    $this->setBasePath($basePath);
42
+    $this->addMatchTypes($matchTypes);
43
+  }
44
+
45
+  /**
46
+   * Retrieves all routes.
47
+   * Useful if you want to process or display routes.
48
+   * @return array All routes.
49
+   */
50
+  public function getRoutes() {
51
+    return $this->routes;
52
+  }
53
+
54
+  /**
55
+   * Add multiple routes at once from array in the following format:
56
+   *
57
+   *   $routes = array(
58
+   *      array($method, $route, $target, $name)
59
+   *   );
60
+   *
61
+   * @param array $routes
62
+   * @return void
63
+   * @author Koen Punt
64
+   * @throws Exception
65
+   */
66
+  public function addRoutes($routes){
67
+    if(!is_array($routes) && !$routes instanceof Traversable) {
68
+      throw new \Exception('Routes should be an array or an instance of Traversable');
69
+    }
70
+    foreach($routes as $route) {
71
+      call_user_func_array(array($this, 'map'), $route);
72
+    }
73
+  }
74
+
75
+  /**
76
+   * Set the base path.
77
+   * Useful if you are running your application from a subdirectory.
78
+   */
79
+  public function setBasePath($basePath) {
80
+    $this->basePath = $basePath;
81
+  }
82
+
83
+  /**
84
+   * Add named match types. It uses array_merge so keys can be overwritten.
85
+   *
86
+   * @param array $matchTypes The key is the name and the value is the regex.
87
+   */
88
+  public function addMatchTypes($matchTypes) {
89
+    $this->matchTypes = array_merge($this->matchTypes, $matchTypes);
90
+  }
91
+
92
+  /**
93
+   * Map a route to a target
94
+   *
95
+   * @param string $method One of 5 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PATCH|PUT|DELETE)
96
+   * @param string $route The route regex, custom regex must start with an @. You can use multiple pre-set regex filters, like [i:id]
97
+   * @param mixed $target The target where this route should point to. Can be anything.
98
+   * @param string $name Optional name of this route. Supply if you want to reverse route this url in your application.
99
+   * @throws Exception
100
+   */
101
+  public function map($method, $route, $target, $name = null) {
102
+
103
+    $this->routes[] = array($method, $route, $target, $name);
104
+
105
+    if($name) {
106
+      if(isset($this->namedRoutes[$name])) {
107
+        throw new \Exception("Can not redeclare route '{$name}'");
108
+      } else {
109
+        $this->namedRoutes[$name] = $route;
110
+      }
111
+
112
+    }
113
+
114
+    return;
115
+  }
116
+
117
+  /**
118
+   * Reversed routing
119
+   *
120
+   * Generate the URL for a named route. Replace regexes with supplied parameters
121
+   *
122
+   * @param string $routeName The name of the route.
123
+   * @param array @params Associative array of parameters to replace placeholders with.
124
+   * @return string The URL of the route with named parameters in place.
125
+   * @throws Exception
126
+   */
127
+  public function generate($routeName, array $params = array()) {
128
+
129
+    // Check if named route exists
130
+    if(!isset($this->namedRoutes[$routeName])) {
131
+      throw new \Exception("Route '{$routeName}' does not exist.");
132
+    }
133
+
134
+    // Replace named parameters
135
+    $route = $this->namedRoutes[$routeName];
136
+
137
+    // prepend base path to route url again
138
+    $url = $this->basePath . $route;
139
+
140
+    if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
141
+
142
+      foreach($matches as $match) {
143
+        list($block, $pre, $type, $param, $optional) = $match;
144
+
145
+        if ($pre) {
146
+          $block = substr($block, 1);
147
+        }
148
+
149
+        if(isset($params[$param])) {
150
+          $url = str_replace($block, $params[$param], $url);
151
+        } elseif ($optional) {
152
+          $url = str_replace($pre . $block, '', $url);
153
+        }
154
+      }
155
+
156
+
157
+    }
158
+
159
+    return $url;
160
+  }
161
+
162
+  /**
163
+   * Match a given Request Url against stored routes
164
+   * @param string $requestUrl
165
+   * @param string $requestMethod
166
+   * @return array|boolean Array with route information on success, false on failure (no match).
167
+   */
168
+  public function match($requestUrl = null, $requestMethod = null) {
169
+
170
+    $params = [];
171
+    $match = false;
172
+
173
+    // set Request Url if it isn't passed as parameter
174
+    if($requestUrl === null) {
175
+      $requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
176
+    }
177
+
178
+    // strip base path from request url
179
+    $requestUrl = substr($requestUrl, strlen($this->basePath));
180 180
     
181
-		// Strip query string (?a=b) from Request Url
182
-		if (($strpos = strpos($requestUrl, '?')) !== false) {
183
-			$requestUrl = substr($requestUrl, 0, $strpos);
184
-		}
185
-
186
-		// set Request Method if it isn't passed as a parameter
187
-		if($requestMethod === null) {
188
-			$requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
189
-		}
190
-
191
-		foreach($this->routes as $handler) {
192
-			list($methods, $route, $target, $name) = $handler;
193
-			$method_match = (stripos($methods, $requestMethod) !== false);
194
-
195
-			// Method did not match, continue to next route.
196
-			if (!$method_match) continue;
197
-
198
-			if ($route === '*') {
199
-				// * wildcard (matches all)
200
-				$match = true;
201
-			} elseif (isset($route[0]) && $route[0] === '@') {
202
-				// @ regex delimiter
203
-				$pattern = '`' . substr($route, 1) . '`u';
204
-				$match = preg_match($pattern, $requestUrl, $params) === 1;
205
-			} elseif (($position = strpos($route, '[')) === false) {
206
-				// No params in url, do string comparison
207
-				$match = strcmp($requestUrl, $route) === 0;
208
-			} else {
209
-				// Compare longest non-param string with url
210
-				if (strncmp($requestUrl, $route, $position) !== 0) {
211
-					continue;
212
-				}
213
-				$regex = $this->compileRoute($route);
214
-				$match = preg_match($regex, $requestUrl, $params) === 1;
215
-			}
216
-
217
-			if ($match) {
218
-
219
-				if ($params) {
220
-					foreach($params as $key => $value) {
221
-						if(is_numeric($key)) unset($params[$key]);
222
-					}
223
-				}
224
-
225
-				return array(
226
-					'target' => $target,
227
-					'params' => $params,
228
-					'name' => $name
229
-				);
230
-			}
231
-		}
232
-		return false;
233
-	}
234
-
235
-	/**
236
-	 * Compile the regex for a given route (EXPENSIVE)
237
-	 */
238
-	private function compileRoute($route) {
239
-		if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
240
-
241
-			$matchTypes = $this->matchTypes;
242
-			foreach($matches as $match) {
243
-				list($block, $pre, $type, $param, $optional) = $match;
244
-
245
-				if (isset($matchTypes[$type])) {
246
-					$type = $matchTypes[$type];
247
-				}
248
-				if ($pre === '.') {
249
-					$pre = '\.';
250
-				}
251
-
252
-				//Older versions of PCRE require the 'P' in (?P<named>)
253
-				$pattern = '(?:'
254
-						. ($pre !== '' ? $pre : null)
255
-						. '('
256
-						. ($param !== '' ? "?P<$param>" : null)
257
-						. $type
258
-						. '))'
259
-						. ($optional !== '' ? '?' : null);
260
-
261
-				$route = str_replace($block, $pattern, $route);
262
-			}
263
-
264
-		}
265
-		return "`^$route$`u";
266
-	}
181
+    // Strip query string (?a=b) from Request Url
182
+    if (($strpos = strpos($requestUrl, '?')) !== false) {
183
+      $requestUrl = substr($requestUrl, 0, $strpos);
184
+    }
185
+
186
+    // set Request Method if it isn't passed as a parameter
187
+    if($requestMethod === null) {
188
+      $requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
189
+    }
190
+
191
+    foreach($this->routes as $handler) {
192
+      list($methods, $route, $target, $name) = $handler;
193
+      $method_match = (stripos($methods, $requestMethod) !== false);
194
+
195
+      // Method did not match, continue to next route.
196
+      if (!$method_match) continue;
197
+
198
+      if ($route === '*') {
199
+        // * wildcard (matches all)
200
+        $match = true;
201
+      } elseif (isset($route[0]) && $route[0] === '@') {
202
+        // @ regex delimiter
203
+        $pattern = '`' . substr($route, 1) . '`u';
204
+        $match = preg_match($pattern, $requestUrl, $params) === 1;
205
+      } elseif (($position = strpos($route, '[')) === false) {
206
+        // No params in url, do string comparison
207
+        $match = strcmp($requestUrl, $route) === 0;
208
+      } else {
209
+        // Compare longest non-param string with url
210
+        if (strncmp($requestUrl, $route, $position) !== 0) {
211
+          continue;
212
+        }
213
+        $regex = $this->compileRoute($route);
214
+        $match = preg_match($regex, $requestUrl, $params) === 1;
215
+      }
216
+
217
+      if ($match) {
218
+
219
+        if ($params) {
220
+          foreach($params as $key => $value) {
221
+            if(is_numeric($key)) unset($params[$key]);
222
+          }
223
+        }
224
+
225
+        return array(
226
+          'target' => $target,
227
+          'params' => $params,
228
+          'name' => $name
229
+        );
230
+      }
231
+    }
232
+    return false;
233
+  }
234
+
235
+  /**
236
+   * Compile the regex for a given route (EXPENSIVE)
237
+   */
238
+  private function compileRoute($route) {
239
+    if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
240
+
241
+      $matchTypes = $this->matchTypes;
242
+      foreach($matches as $match) {
243
+        list($block, $pre, $type, $param, $optional) = $match;
244
+
245
+        if (isset($matchTypes[$type])) {
246
+          $type = $matchTypes[$type];
247
+        }
248
+        if ($pre === '.') {
249
+          $pre = '\.';
250
+        }
251
+
252
+        //Older versions of PCRE require the 'P' in (?P<named>)
253
+        $pattern = '(?:'
254
+            . ($pre !== '' ? $pre : null)
255
+            . '('
256
+            . ($param !== '' ? "?P<$param>" : null)
257
+            . $type
258
+            . '))'
259
+            . ($optional !== '' ? '?' : null);
260
+
261
+        $route = str_replace($block, $pattern, $route);
262
+      }
263
+
264
+    }
265
+    return "`^$route$`u";
266
+  }
267 267
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	  * @param string $basePath
37 37
 	  * @param array $matchTypes
38 38
 	  */
39
-	public function __construct( $routes = array(), $basePath = '', $matchTypes = array() ) {
39
+	public function __construct($routes = array(), $basePath = '', $matchTypes = array()) {
40 40
 		$this->addRoutes($routes);
41 41
 		$this->setBasePath($basePath);
42 42
 		$this->addMatchTypes($matchTypes);
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
 	 * @author Koen Punt
64 64
 	 * @throws Exception
65 65
 	 */
66
-	public function addRoutes($routes){
67
-		if(!is_array($routes) && !$routes instanceof Traversable) {
66
+	public function addRoutes($routes) {
67
+		if (!is_array($routes) && !$routes instanceof Traversable) {
68 68
 			throw new \Exception('Routes should be an array or an instance of Traversable');
69 69
 		}
70
-		foreach($routes as $route) {
70
+		foreach ($routes as $route) {
71 71
 			call_user_func_array(array($this, 'map'), $route);
72 72
 		}
73 73
 	}
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
 
103 103
 		$this->routes[] = array($method, $route, $target, $name);
104 104
 
105
-		if($name) {
106
-			if(isset($this->namedRoutes[$name])) {
105
+		if ($name) {
106
+			if (isset($this->namedRoutes[$name])) {
107 107
 				throw new \Exception("Can not redeclare route '{$name}'");
108 108
 			} else {
109 109
 				$this->namedRoutes[$name] = $route;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 	public function generate($routeName, array $params = array()) {
128 128
 
129 129
 		// Check if named route exists
130
-		if(!isset($this->namedRoutes[$routeName])) {
130
+		if (!isset($this->namedRoutes[$routeName])) {
131 131
 			throw new \Exception("Route '{$routeName}' does not exist.");
132 132
 		}
133 133
 
@@ -135,21 +135,21 @@  discard block
 block discarded – undo
135 135
 		$route = $this->namedRoutes[$routeName];
136 136
 
137 137
 		// prepend base path to route url again
138
-		$url = $this->basePath . $route;
138
+		$url = $this->basePath.$route;
139 139
 
140 140
 		if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
141 141
 
142
-			foreach($matches as $match) {
142
+			foreach ($matches as $match) {
143 143
 				list($block, $pre, $type, $param, $optional) = $match;
144 144
 
145 145
 				if ($pre) {
146 146
 					$block = substr($block, 1);
147 147
 				}
148 148
 
149
-				if(isset($params[$param])) {
149
+				if (isset($params[$param])) {
150 150
 					$url = str_replace($block, $params[$param], $url);
151 151
 				} elseif ($optional) {
152
-					$url = str_replace($pre . $block, '', $url);
152
+					$url = str_replace($pre.$block, '', $url);
153 153
 				}
154 154
 			}
155 155
 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 		$match = false;
172 172
 
173 173
 		// set Request Url if it isn't passed as parameter
174
-		if($requestUrl === null) {
174
+		if ($requestUrl === null) {
175 175
 			$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
176 176
 		}
177 177
 
@@ -184,11 +184,11 @@  discard block
 block discarded – undo
184 184
 		}
185 185
 
186 186
 		// set Request Method if it isn't passed as a parameter
187
-		if($requestMethod === null) {
187
+		if ($requestMethod === null) {
188 188
 			$requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
189 189
 		}
190 190
 
191
-		foreach($this->routes as $handler) {
191
+		foreach ($this->routes as $handler) {
192 192
 			list($methods, $route, $target, $name) = $handler;
193 193
 			$method_match = (stripos($methods, $requestMethod) !== false);
194 194
 
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 				$match = true;
201 201
 			} elseif (isset($route[0]) && $route[0] === '@') {
202 202
 				// @ regex delimiter
203
-				$pattern = '`' . substr($route, 1) . '`u';
203
+				$pattern = '`'.substr($route, 1).'`u';
204 204
 				$match = preg_match($pattern, $requestUrl, $params) === 1;
205 205
 			} elseif (($position = strpos($route, '[')) === false) {
206 206
 				// No params in url, do string comparison
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
 			if ($match) {
218 218
 
219 219
 				if ($params) {
220
-					foreach($params as $key => $value) {
221
-						if(is_numeric($key)) unset($params[$key]);
220
+					foreach ($params as $key => $value) {
221
+						if (is_numeric($key)) unset($params[$key]);
222 222
 					}
223 223
 				}
224 224
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 		if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) {
240 240
 
241 241
 			$matchTypes = $this->matchTypes;
242
-			foreach($matches as $match) {
242
+			foreach ($matches as $match) {
243 243
 				list($block, $pre, $type, $param, $optional) = $match;
244 244
 
245 245
 				if (isset($matchTypes[$type])) {
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -193,7 +193,9 @@  discard block
 block discarded – undo
193 193
 			$method_match = (stripos($methods, $requestMethod) !== false);
194 194
 
195 195
 			// Method did not match, continue to next route.
196
-			if (!$method_match) continue;
196
+			if (!$method_match) {
197
+			  continue;
198
+			}
197 199
 
198 200
 			if ($route === '*') {
199 201
 				// * wildcard (matches all)
@@ -218,7 +220,9 @@  discard block
 block discarded – undo
218 220
 
219 221
 				if ($params) {
220 222
 					foreach($params as $key => $value) {
221
-						if(is_numeric($key)) unset($params[$key]);
223
+						if(is_numeric($key)) {
224
+						  unset($params[$key]);
225
+						}
222 226
 					}
223 227
 				}
224 228
 
Please login to merge, or discard this patch.
Controllers/OperatorController.class.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 namespace HexMakina\kadro\Controllers;
13 13
 
14 14
 use \HexMakina\Crudites\Crudites;
15
-use \HexMakina\kadro\Auth\{Operator,OperatorInterface,ACL,AccessRefusedException};
15
+use \HexMakina\kadro\Auth\{Operator, OperatorInterface, ACL, AccessRefusedException};
16 16
 
17 17
 
18 18
 class OperatorController extends \HexMakina\kadro\Controllers\ORMController
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
     parent::edit();
24 24
 
25 25
     // do we create? or do we edit someone else ? must be admin
26
-    if(is_null($this->load_model) || $this->operator()->operator_id() !== $this->load_model->operator_id())
26
+    if (is_null($this->load_model) || $this->operator()->operator_id() !== $this->load_model->operator_id())
27 27
       $this->authorize('group_admin');
28 28
 
29 29
   }
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
   public function save()
37 37
   {
38
-    if($this->operator()->operator_id() !== $this->form_model->operator_id())
38
+    if ($this->operator()->operator_id() !== $this->form_model->operator_id())
39 39
       $this->authorize('group_admin');
40 40
 
41 41
     parent::save();
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
   public function before_save() : array
45 45
   {
46 46
     //------------------------------------------------------------- PASSWORDS
47
-    if($this->form_model->get('password') != $this->form_model->get('password_verification'))
47
+    if ($this->form_model->get('password') != $this->form_model->get('password_verification'))
48 48
     {
49 49
       $this->logger()->warning('KADRO_operator_ERR_PASSWORDS_MISMATCH');
50 50
       return $this->edit();
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
   public function dashboard()
59 59
   {
60 60
     $real_operator_class = get_class($this->operator());
61
-    $this->viewport('users', $real_operator_class::filter([], ['order_by' => [null,'username', 'ASC']]));
61
+    $this->viewport('users', $real_operator_class::filter([], ['order_by' => [null, 'username', 'ASC']]));
62 62
   }
63 63
 
64 64
   public function destroy()
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
     parent::authorize('group_admin');
72 72
 
73 73
     $operator = Operator::one($this->router()->params());
74
-    if($operator->username() == $this->operator()->username())
74
+    if ($operator->username() == $this->operator()->username())
75 75
       throw new AccessRefusedException();
76 76
 
77
-    if(Operator::toggle_boolean(Operator::table_name(), 'active', $operator->operator_id()) === true)
77
+    if (Operator::toggle_boolean(Operator::table_name(), 'active', $operator->operator_id()) === true)
78 78
     {
79 79
       $confirmation_message = $operator->is_active() ? 'KADRO_operator_DISABLED' : 'KADRO_operator_ENABLED';
80 80
       $this->logger()->nice($confirmation_message, [$operator->get('name')]);
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
     parent::authorize('group_admin');
93 93
 
94 94
     $operator = Operator::one(['username' => $this->router()->params('username')]);
95
-    if($operator->username() == $this->operator()->username())
95
+    if ($operator->username() == $this->operator()->username())
96 96
       throw new AccessRefusedException();
97 97
 
98 98
     $permission_id = $this->router()->params('permission_id');
99 99
 
100 100
     $row_data = ['operator_id' => $operator->operator_id(), 'permission_id' => $permission_id];
101 101
     $row = ACL::table()->restore($row_data);
102
-    if($row->is_new())
102
+    if ($row->is_new())
103 103
     {
104 104
       $row = ACL::table()->produce($row_data);
105 105
       $res = $row->persist();
Please login to merge, or discard this patch.
Braces   +14 added lines, -12 removed lines patch added patch discarded remove patch
@@ -23,8 +23,9 @@  discard block
 block discarded – undo
23 23
     parent::edit();
24 24
 
25 25
     // do we create? or do we edit someone else ? must be admin
26
-    if(is_null($this->load_model) || $this->operator()->operator_id() !== $this->load_model->operator_id())
27
-      $this->authorize('group_admin');
26
+    if(is_null($this->load_model) || $this->operator()->operator_id() !== $this->load_model->operator_id()) {
27
+          $this->authorize('group_admin');
28
+    }
28 29
 
29 30
   }
30 31
 
@@ -35,8 +36,9 @@  discard block
 block discarded – undo
35 36
 
36 37
   public function save()
37 38
   {
38
-    if($this->operator()->operator_id() !== $this->form_model->operator_id())
39
-      $this->authorize('group_admin');
39
+    if($this->operator()->operator_id() !== $this->form_model->operator_id()) {
40
+          $this->authorize('group_admin');
41
+    }
40 42
 
41 43
     parent::save();
42 44
   }
@@ -71,15 +73,15 @@  discard block
 block discarded – undo
71 73
     parent::authorize('group_admin');
72 74
 
73 75
     $operator = Operator::one($this->router()->params());
74
-    if($operator->username() == $this->operator()->username())
75
-      throw new AccessRefusedException();
76
+    if($operator->username() == $this->operator()->username()) {
77
+          throw new AccessRefusedException();
78
+    }
76 79
 
77 80
     if(Operator::toggle_boolean(Operator::table_name(), 'active', $operator->operator_id()) === true)
78 81
     {
79 82
       $confirmation_message = $operator->is_active() ? 'KADRO_operator_DISABLED' : 'KADRO_operator_ENABLED';
80 83
       $this->logger()->nice($confirmation_message, [$operator->get('name')]);
81
-    }
82
-    else
84
+    } else
83 85
     {
84 86
       $this->logger()->warning('CRUDITES_ERR_QUERY_FAILED');
85 87
     }
@@ -92,8 +94,9 @@  discard block
 block discarded – undo
92 94
     parent::authorize('group_admin');
93 95
 
94 96
     $operator = Operator::one(['username' => $this->router()->params('username')]);
95
-    if($operator->username() == $this->operator()->username())
96
-      throw new AccessRefusedException();
97
+    if($operator->username() == $this->operator()->username()) {
98
+          throw new AccessRefusedException();
99
+    }
97 100
 
98 101
     $permission_id = $this->router()->params('permission_id');
99 102
 
@@ -103,8 +106,7 @@  discard block
 block discarded – undo
103 106
     {
104 107
       $row = ACL::table()->produce($row_data);
105 108
       $res = $row->persist();
106
-    }
107
-    else
109
+    } else
108 110
     {
109 111
       $row->wipe();
110 112
     }
Please login to merge, or discard this patch.
Controllers/TradukoController.class.php 3 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@
 block discarded – undo
15 15
   }
16 16
 
17 17
   public function route_back($route_name = NULL, $route_params = []) : string
18
-	{
19
-		return $this->router()->prehop('traduko');
20
-	}
18
+  {
19
+    return $this->router()->prehop('traduko');
20
+  }
21 21
 
22 22
   public function update_file($lang='fra')
23 23
   {
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 		return $this->router()->prehop('traduko');
20 20
 	}
21 21
 
22
-  public function update_file($lang='fra')
22
+  public function update_file($lang = 'fra')
23 23
   {
24 24
     $locale_path = $this->box('settings.locale_data_path');
25 25
     self::create_file($locale_path, $lang);
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
   {
33 33
     $res = Traduko::filter(['lang' => $lang]);
34 34
     $assoc = [];
35
-    foreach($res as $id => $trad)
35
+    foreach ($res as $id => $trad)
36 36
     {
37
-      if(!isset($assoc[$trad->kategorio]))
37
+      if (!isset($assoc[$trad->kategorio]))
38 38
         $assoc[$trad->kategorio] = [];
39
-      if(!isset($assoc[$trad->kategorio][$trad->sekcio]))
39
+      if (!isset($assoc[$trad->kategorio][$trad->sekcio]))
40 40
         $assoc[$trad->kategorio][$trad->sekcio] = [];
41 41
 
42 42
       $assoc[$trad->kategorio][$trad->sekcio][$trad->referenco] = $trad->$lang;
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
     // {
47 47
     $path_to_file = $locale_path.'/'.$lang;
48 48
     // test directory access & creation
49
-    if(!JSON::exists($path_to_file))
49
+    if (!JSON::exists($path_to_file))
50 50
       JSON::make_dir($path_to_file);
51 51
 
52 52
     $file = new JSON($path_to_file.'/'.self::JSON_FILENAME, 'w+');
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
   public static function init($locale_path)
62 62
   {
63 63
     $languages = array_keys(array_slice(Traduko::inspect(Traduko::table_name())->columns(), 4));
64
-    foreach($languages as $l)
64
+    foreach ($languages as $l)
65 65
       self::create_file($locale_path, $l);
66 66
 
67 67
     return $languages;
Please login to merge, or discard this patch.
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -34,10 +34,12 @@  discard block
 block discarded – undo
34 34
     $assoc = [];
35 35
     foreach($res as $id => $trad)
36 36
     {
37
-      if(!isset($assoc[$trad->kategorio]))
38
-        $assoc[$trad->kategorio] = [];
39
-      if(!isset($assoc[$trad->kategorio][$trad->sekcio]))
40
-        $assoc[$trad->kategorio][$trad->sekcio] = [];
37
+      if(!isset($assoc[$trad->kategorio])) {
38
+              $assoc[$trad->kategorio] = [];
39
+      }
40
+      if(!isset($assoc[$trad->kategorio][$trad->sekcio])) {
41
+              $assoc[$trad->kategorio][$trad->sekcio] = [];
42
+      }
41 43
 
42 44
       $assoc[$trad->kategorio][$trad->sekcio][$trad->referenco] = $trad->$lang;
43 45
     }
@@ -46,8 +48,9 @@  discard block
 block discarded – undo
46 48
     // {
47 49
     $path_to_file = $locale_path.'/'.$lang;
48 50
     // test directory access & creation
49
-    if(!JSON::exists($path_to_file))
50
-      JSON::make_dir($path_to_file);
51
+    if(!JSON::exists($path_to_file)) {
52
+          JSON::make_dir($path_to_file);
53
+    }
51 54
 
52 55
     $file = new JSON($path_to_file.'/'.self::JSON_FILENAME, 'w+');
53 56
     $file->set_content(JSON::from_php($assoc));
@@ -61,8 +64,9 @@  discard block
 block discarded – undo
61 64
   public static function init($locale_path)
62 65
   {
63 66
     $languages = array_keys(array_slice(Traduko::inspect(Traduko::table_name())->columns(), 4));
64
-    foreach($languages as $l)
65
-      self::create_file($locale_path, $l);
67
+    foreach($languages as $l) {
68
+          self::create_file($locale_path, $l);
69
+    }
66 70
 
67 71
     return $languages;
68 72
   }
Please login to merge, or discard this patch.
Controllers/Interfaces/CRUDController.class.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -4,14 +4,14 @@
 block discarded – undo
4 4
 
5 5
 interface CRUDController
6 6
 {
7
-   public function dashboard();
8
-   public function edit();
9
-   public function save();
10
-   public function listing();
7
+    public function dashboard();
8
+    public function edit();
9
+    public function save();
10
+    public function listing();
11 11
 
12
-   public function destroy();
12
+    public function destroy();
13 13
 
14
-   public function errors() : array;
14
+    public function errors() : array;
15 15
 }
16 16
 
17 17
 ?>
Please login to merge, or discard this patch.
Controllers/Interfaces/DisplayController.class.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 interface DisplayController extends BaseController
6 6
 {
7 7
 
8
-   /*
8
+    /*
9 9
       The viewport is an associative array of values to be exported as variables in the view
10 10
          the assoc keys will be the variable names
11 11
 
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
            returns null
43 43
    */
44 44
    
45
-   public function viewport($key=null, $value=null, $coercion=false);
45
+    public function viewport($key=null, $value=null, $coercion=false);
46 46
 
47
-   public function display($custom_template = null, $standalone=false);
47
+    public function display($custom_template = null, $standalone=false);
48 48
 
49 49
 }
50 50
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,9 +42,9 @@
 block discarded – undo
42 42
            returns null
43 43
    */
44 44
    
45
-   public function viewport($key=null, $value=null, $coercion=false);
45
+   public function viewport($key = null, $value = null, $coercion = false);
46 46
 
47
-   public function display($custom_template = null, $standalone=false);
47
+   public function display($custom_template = null, $standalone = false);
48 48
 
49 49
 }
50 50
 
Please login to merge, or discard this patch.
Controllers/Paginator.class.php 3 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
 {
8 8
   protected static function prepare_pagination($records_total)
9 9
   {
10
-  	global $settings;
11
-  	global $smarty;
10
+    global $settings;
11
+    global $smarty;
12 12
 
13 13
     $pages_max_on_each_side = 3;
14 14
     $pages_max_displayed = $pages_max_on_each_side*2+1;
@@ -35,12 +35,12 @@  discard block
 block discarded – undo
35 35
     if($pages_last > $pages_total) // $pages_max_displayed greater than the total of pages
36 36
       $pages_last = $pages_total;
37 37
 
38
-  	$this->viewport("pages_total",     $pages_total);
39
-  	$this->viewport("pages_first",     $pages_first);
38
+    $this->viewport("pages_total",     $pages_total);
39
+    $this->viewport("pages_first",     $pages_first);
40 40
     $this->viewport("pages_previous",  $pages_current <= 1 ? $pages_total : $pages_current - 1);
41
-  	$this->viewport("pages_current",   $pages_current);
42
-  	$this->viewport("pages_next",      $pages_current >= $pages_total ? 1 : $pages_current + 1);
43
-  	$this->viewport("pages_last",      $pages_last);
41
+    $this->viewport("pages_current",   $pages_current);
42
+    $this->viewport("pages_next",      $pages_current >= $pages_total ? 1 : $pages_current + 1);
43
+    $this->viewport("pages_last",      $pages_last);
44 44
   }
45 45
 
46 46
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -11,36 +11,36 @@
 block discarded – undo
11 11
   	global $smarty;
12 12
 
13 13
     $pages_max_on_each_side = 3;
14
-    $pages_max_displayed = $pages_max_on_each_side*2+1;
14
+    $pages_max_displayed = $pages_max_on_each_side * 2+1;
15 15
 
16 16
     // are we paginating ?
17 17
 
18
-    if(is_null($this->box('StateAgent')->filters('results_per_page')))
18
+    if (is_null($this->box('StateAgent')->filters('results_per_page')))
19 19
       return;
20 20
 
21 21
     $pages_range    = intval($this->box('StateAgent')->filters('results_per_page'));
22 22
     $pages_total    = $pages_range > 0 ? intval(ceil($records_total / $pages_range)) : 1;
23 23
     $pages_current  = intval($this->box('StateAgent')->filters('page'));
24 24
 
25
-    if($pages_current >= $pages_total)
25
+    if ($pages_current >= $pages_total)
26 26
       $pages_current = $pages_total;
27 27
 
28
-    $pages_first = ($pages_current <= $pages_max_on_each_side)? 1 : $pages_current - $pages_max_on_each_side;
28
+    $pages_first = ($pages_current <= $pages_max_on_each_side) ? 1 : $pages_current-$pages_max_on_each_side;
29 29
 
30
-    $pages_last = $pages_current + $pages_max_on_each_side;
30
+    $pages_last = $pages_current+$pages_max_on_each_side;
31 31
 
32
-    if($pages_last < $pages_max_displayed) // add the missing pages to fullfill $pages_max_displayed
32
+    if ($pages_last < $pages_max_displayed) // add the missing pages to fullfill $pages_max_displayed
33 33
       $pages_last += $pages_max_displayed-$pages_last;
34 34
 
35
-    if($pages_last > $pages_total) // $pages_max_displayed greater than the total of pages
35
+    if ($pages_last > $pages_total) // $pages_max_displayed greater than the total of pages
36 36
       $pages_last = $pages_total;
37 37
 
38
-  	$this->viewport("pages_total",     $pages_total);
39
-  	$this->viewport("pages_first",     $pages_first);
40
-    $this->viewport("pages_previous",  $pages_current <= 1 ? $pages_total : $pages_current - 1);
41
-  	$this->viewport("pages_current",   $pages_current);
42
-  	$this->viewport("pages_next",      $pages_current >= $pages_total ? 1 : $pages_current + 1);
43
-  	$this->viewport("pages_last",      $pages_last);
38
+  	$this->viewport("pages_total", $pages_total);
39
+  	$this->viewport("pages_first", $pages_first);
40
+    $this->viewport("pages_previous", $pages_current <= 1 ? $pages_total : $pages_current-1);
41
+  	$this->viewport("pages_current", $pages_current);
42
+  	$this->viewport("pages_next", $pages_current >= $pages_total ? 1 : $pages_current+1);
43
+  	$this->viewport("pages_last", $pages_last);
44 44
   }
45 45
 
46 46
 }
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -15,25 +15,31 @@
 block discarded – undo
15 15
 
16 16
     // are we paginating ?
17 17
 
18
-    if(is_null($this->box('StateAgent')->filters('results_per_page')))
19
-      return;
18
+    if(is_null($this->box('StateAgent')->filters('results_per_page'))) {
19
+          return;
20
+    }
20 21
 
21 22
     $pages_range    = intval($this->box('StateAgent')->filters('results_per_page'));
22 23
     $pages_total    = $pages_range > 0 ? intval(ceil($records_total / $pages_range)) : 1;
23 24
     $pages_current  = intval($this->box('StateAgent')->filters('page'));
24 25
 
25
-    if($pages_current >= $pages_total)
26
-      $pages_current = $pages_total;
26
+    if($pages_current >= $pages_total) {
27
+          $pages_current = $pages_total;
28
+    }
27 29
 
28 30
     $pages_first = ($pages_current <= $pages_max_on_each_side)? 1 : $pages_current - $pages_max_on_each_side;
29 31
 
30 32
     $pages_last = $pages_current + $pages_max_on_each_side;
31 33
 
32
-    if($pages_last < $pages_max_displayed) // add the missing pages to fullfill $pages_max_displayed
34
+    if($pages_last < $pages_max_displayed) {
35
+      // add the missing pages to fullfill $pages_max_displayed
33 36
       $pages_last += $pages_max_displayed-$pages_last;
37
+    }
34 38
 
35
-    if($pages_last > $pages_total) // $pages_max_displayed greater than the total of pages
39
+    if($pages_last > $pages_total) {
40
+      // $pages_max_displayed greater than the total of pages
36 41
       $pages_last = $pages_total;
42
+    }
37 43
 
38 44
   	$this->viewport("pages_total",     $pages_total);
39 45
   	$this->viewport("pages_first",     $pages_first);
Please login to merge, or discard this patch.
Controllers/KadroController.class.php 3 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -107,18 +107,18 @@  discard block
 block discarded – undo
107 107
     $custom_template = null;
108 108
 
109 109
     if(method_exists($this, 'prepare'))
110
-    	$this->prepare();
110
+      $this->prepare();
111 111
 
112
-  	if(method_exists($this, $method = $this->router()->target_method()))
112
+    if(method_exists($this, $method = $this->router()->target_method()))
113 113
     {
114 114
       $custom_template = $this->$method();
115 115
     }
116 116
 
117 117
     if(method_exists($this, 'conclude'))
118
-    	$this->conclude();
118
+      $this->conclude();
119 119
 
120 120
     if(method_exists($this, 'display'))
121
-    	$template = $this->display($custom_template);
121
+      $template = $this->display($custom_template);
122 122
   }
123 123
 
124 124
   public function conclude(){}
@@ -143,16 +143,16 @@  discard block
 block discarded – undo
143 143
 
144 144
     $template = $this->find_template($smarty, $custom_template); // throws Exception if nothing found
145 145
 
146
-		$this->viewport('controller', $this);
146
+    $this->viewport('controller', $this);
147 147
 
148 148
     $this->viewport('user_messages', $this->logger()->get_user_report());
149 149
 
150 150
 
151
-  	$this->viewport('file_root', $this->router()->file_root());
152
-  	$this->viewport('view_path', $this->router()->file_root() . $this->box('settings.smarty.template_path').'app/');
153
-  	$this->viewport('web_root', $this->router()->web_root());
154
-  	$this->viewport('view_url', $this->router()->web_root() . $this->box('settings.smarty.template_path'));
155
-  	$this->viewport('images_url', $this->router()->web_root() . $this->box('settings.smarty.template_path') . 'images/');
151
+    $this->viewport('file_root', $this->router()->file_root());
152
+    $this->viewport('view_path', $this->router()->file_root() . $this->box('settings.smarty.template_path').'app/');
153
+    $this->viewport('web_root', $this->router()->web_root());
154
+    $this->viewport('view_url', $this->router()->web_root() . $this->box('settings.smarty.template_path'));
155
+    $this->viewport('images_url', $this->router()->web_root() . $this->box('settings.smarty.template_path') . 'images/');
156 156
 
157 157
     foreach($this->viewport() as $template_var_name => $value)
158 158
       $smarty->assign($template_var_name, $value);
@@ -227,12 +227,12 @@  discard block
 block discarded – undo
227 227
    *
228 228
    */
229 229
   public function route_back($route_name=null, $route_params=[]) : string
230
-	{
230
+  {
231 231
     if(is_null($route_name))
232
-		  return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME);
232
+      return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME);
233 233
 
234 234
     return $this->route_back = $this->route_factory($route_name, $route_params);
235
-	}
235
+  }
236 236
 
237 237
   public function route_factory($route_name=null, $route_params=[]) : string
238 238
   {
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 namespace HexMakina\kadro\Controllers;
4 4
 
5
-use \Psr\Container\{ContainerInterface,ContainerExceptionInterface,NotFoundExceptionInterface};
5
+use \Psr\Container\{ContainerInterface, ContainerExceptionInterface, NotFoundExceptionInterface};
6 6
 
7 7
 use \HexMakina\kadro\Auth\{OperatorInterface, AccessRefusedException};
8 8
 use \HexMakina\kadro\Router\RouterInterface;
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
   protected $route_back = null;
17 17
 
18
-  public function __toString(){ return get_called_class();}
18
+  public function __toString() { return get_called_class(); }
19 19
 
20 20
   // -------- Controller Container
21 21
   public function set_container(ContainerInterface $container)
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
   }
30 30
 
31 31
   // shortcut for (un)boxing
32
-  public function box($key, $instance=null)
32
+  public function box($key, $instance = null)
33 33
   {
34
-    if(!is_null($instance))
34
+    if (!is_null($instance))
35 35
       $this->container->register($key, $instance);
36 36
 
37 37
     // dd($this->container->get($key));
@@ -61,32 +61,32 @@  discard block
 block discarded – undo
61 61
     return true; // security by default
62 62
   }
63 63
 
64
-  public function authorize($permission=null)
64
+  public function authorize($permission = null)
65 65
   {
66 66
     // if(!$this->requires_operator() || is_null($permission))
67
-    if(!$this->requires_operator())
67
+    if (!$this->requires_operator())
68 68
       return true;
69 69
 
70 70
     $operator = $this->operator();
71
-    if(is_null($operator) || $operator->is_new() || !$operator->is_active())
71
+    if (is_null($operator) || $operator->is_new() || !$operator->is_active())
72 72
       throw new AccessRefusedException();
73 73
 
74
-    if(!is_null($permission) && !$operator->has_permission($permission))
74
+    if (!is_null($permission) && !$operator->has_permission($permission))
75 75
       throw new AccessRefusedException();
76 76
 
77 77
     return true;
78 78
   }
79 79
 
80
-  public function viewport($key=null, $value=null, $coercion=false)
80
+  public function viewport($key = null, $value = null, $coercion = false)
81 81
   {
82 82
     // no key, returns all
83
-    if(is_null($key))
83
+    if (is_null($key))
84 84
       return $this->template_variables;
85 85
 
86 86
     // got key, got null value, returns $[$key]
87
-    if(is_null($value))
87
+    if (is_null($value))
88 88
     {
89
-      if($coercion === true) // break rule 1 ?
89
+      if ($coercion === true) // break rule 1 ?
90 90
         $this->template_variables[$key] = null;
91 91
 
92 92
       return $this->template_variables[$key] ?? null;
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 
95 95
     // got key, got value
96 96
     // sets or coerces $[$key]=$value and returns $[$key]
97
-    if(!isset($this->template_variables[$key]) || $coercion === true)
97
+    if (!isset($this->template_variables[$key]) || $coercion === true)
98 98
       $this->template_variables[$key] = $value;
99 99
 
100 100
     return $this->template_variables[$key] ?? null;
@@ -106,22 +106,22 @@  discard block
 block discarded – undo
106 106
 
107 107
     $custom_template = null;
108 108
 
109
-    if(method_exists($this, 'prepare'))
109
+    if (method_exists($this, 'prepare'))
110 110
     	$this->prepare();
111 111
 
112
-  	if(method_exists($this, $method = $this->router()->target_method()))
112
+  	if (method_exists($this, $method = $this->router()->target_method()))
113 113
     {
114 114
       $custom_template = $this->$method();
115 115
     }
116 116
 
117
-    if(method_exists($this, 'conclude'))
117
+    if (method_exists($this, 'conclude'))
118 118
     	$this->conclude();
119 119
 
120
-    if(method_exists($this, 'display'))
120
+    if (method_exists($this, 'display'))
121 121
     	$template = $this->display($custom_template);
122 122
   }
123 123
 
124
-  public function conclude(){}
124
+  public function conclude() {}
125 125
 
126 126
   public function prepare()
127 127
   {
@@ -130,14 +130,14 @@  discard block
 block discarded – undo
130 130
 
131 131
   private function trim_request_data()
132 132
   {
133
-    array_walk_recursive($_GET, function(&$value){$value = trim($value);});
134
-    array_walk_recursive($_REQUEST, function(&$value){$value = trim($value);});
133
+    array_walk_recursive($_GET, function(&$value) {$value = trim($value); });
134
+    array_walk_recursive($_REQUEST, function(&$value) {$value = trim($value); });
135 135
 
136
-    if($this->router()->submits())
137
-      array_walk_recursive($_POST, function(&$value){$value = trim($value);});
136
+    if ($this->router()->submits())
137
+      array_walk_recursive($_POST, function(&$value) {$value = trim($value); });
138 138
   }
139 139
 
140
-  public function display($custom_template = null, $standalone=false)
140
+  public function display($custom_template = null, $standalone = false)
141 141
   {
142 142
     $smarty = $this->box('template_engine');
143 143
 
@@ -149,15 +149,15 @@  discard block
 block discarded – undo
149 149
 
150 150
 
151 151
   	$this->viewport('file_root', $this->router()->file_root());
152
-  	$this->viewport('view_path', $this->router()->file_root() . $this->box('settings.smarty.template_path').'app/');
152
+  	$this->viewport('view_path', $this->router()->file_root().$this->box('settings.smarty.template_path').'app/');
153 153
   	$this->viewport('web_root', $this->router()->web_root());
154
-  	$this->viewport('view_url', $this->router()->web_root() . $this->box('settings.smarty.template_path'));
155
-  	$this->viewport('images_url', $this->router()->web_root() . $this->box('settings.smarty.template_path') . 'images/');
154
+  	$this->viewport('view_url', $this->router()->web_root().$this->box('settings.smarty.template_path'));
155
+  	$this->viewport('images_url', $this->router()->web_root().$this->box('settings.smarty.template_path').'images/');
156 156
 
157
-    foreach($this->viewport() as $template_var_name => $value)
157
+    foreach ($this->viewport() as $template_var_name => $value)
158 158
       $smarty->assign($template_var_name, $value);
159 159
 
160
-    if($standalone === false)
160
+    if ($standalone === false)
161 161
     {
162 162
       $smarty->display(sprintf('%s|%s', $this->box('settings.smarty.template_inclusion_path'), $template));
163 163
     }
@@ -180,32 +180,32 @@  discard block
 block discarded – undo
180 180
     $controller_template_path = $this->template_base();
181 181
     $templates = [];
182 182
 
183
-    if(!empty($custom_template))
183
+    if (!empty($custom_template))
184 184
     {
185 185
       // 1. check for custom template in the current controller directory
186
-      $templates ['custom_3']= sprintf('%s/%s.html', $controller_template_path, $custom_template);
186
+      $templates ['custom_3'] = sprintf('%s/%s.html', $controller_template_path, $custom_template);
187 187
       // 2. check for custom template formatted as controller/view
188
-      $templates ['custom_2']= $custom_template.'.html';
189
-      $templates ['custom_1']= '_layouts/'.$custom_template.'.html';
188
+      $templates ['custom_2'] = $custom_template.'.html';
189
+      $templates ['custom_1'] = '_layouts/'.$custom_template.'.html';
190 190
     }
191 191
 
192
-    if(!empty($this->router()->target_method()))
192
+    if (!empty($this->router()->target_method()))
193 193
     {
194 194
       // 1. check for template in controller-related directory
195
-      $templates ['target_1']= sprintf('%s/%s.html', $controller_template_path, $this->router()->target_method());
195
+      $templates ['target_1'] = sprintf('%s/%s.html', $controller_template_path, $this->router()->target_method());
196 196
       // 2. check for template in app-related directory
197
-      $templates ['target_2']= sprintf('_layouts/%s.html', $this->router()->target_method());
197
+      $templates ['target_2'] = sprintf('_layouts/%s.html', $this->router()->target_method());
198 198
       // 3. check for template in kadro directory
199
-      $templates ['target_3']= sprintf('%s.html', $this->router()->target_method());
199
+      $templates ['target_3'] = sprintf('%s.html', $this->router()->target_method());
200 200
     }
201 201
 
202
-    $templates ['default_3']= sprintf('%s/edit.html', $controller_template_path);
203
-    $templates ['default_4']= 'edit.tpl';
202
+    $templates ['default_3'] = sprintf('%s/edit.html', $controller_template_path);
203
+    $templates ['default_4'] = 'edit.tpl';
204 204
     $templates = array_unique($templates);
205 205
 
206
-    while(!is_null($tpl_path = array_shift($templates)))
206
+    while (!is_null($tpl_path = array_shift($templates)))
207 207
     {
208
-      if($smarty->templateExists($tpl_path))
208
+      if ($smarty->templateExists($tpl_path))
209 209
         return $tpl_path;
210 210
     }
211 211
 
@@ -226,21 +226,21 @@  discard block
 block discarded – undo
226 226
    * route_back($route_name [,$route_params]), sets $route_back using route_factory()
227 227
    *
228 228
    */
229
-  public function route_back($route_name=null, $route_params=[]) : string
229
+  public function route_back($route_name = null, $route_params = []) : string
230 230
 	{
231
-    if(is_null($route_name))
231
+    if (is_null($route_name))
232 232
 		  return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME);
233 233
 
234 234
     return $this->route_back = $this->route_factory($route_name, $route_params);
235 235
 	}
236 236
 
237
-  public function route_factory($route_name=null, $route_params=[]) : string
237
+  public function route_factory($route_name = null, $route_params = []) : string
238 238
   {
239 239
     $route = null;
240 240
 
241
-    if(is_string($route_name) && !empty($route_name))
241
+    if (is_string($route_name) && !empty($route_name))
242 242
     {
243
-      if($this->router()->route_exists($route_name))
243
+      if ($this->router()->route_exists($route_name))
244 244
         $route = $this->router()->prehop($route_name, $route_params);
245 245
       else
246 246
         $route = $route_name;
Please login to merge, or discard this patch.
Braces   +49 added lines, -33 removed lines patch added patch discarded remove patch
@@ -31,8 +31,9 @@  discard block
 block discarded – undo
31 31
   // shortcut for (un)boxing
32 32
   public function box($key, $instance=null)
33 33
   {
34
-    if(!is_null($instance))
35
-      $this->container->register($key, $instance);
34
+    if(!is_null($instance)) {
35
+          $this->container->register($key, $instance);
36
+    }
36 37
 
37 38
     // dd($this->container->get($key));
38 39
     return $this->container->get($key);
@@ -64,15 +65,18 @@  discard block
 block discarded – undo
64 65
   public function authorize($permission=null)
65 66
   {
66 67
     // if(!$this->requires_operator() || is_null($permission))
67
-    if(!$this->requires_operator())
68
-      return true;
68
+    if(!$this->requires_operator()) {
69
+          return true;
70
+    }
69 71
 
70 72
     $operator = $this->operator();
71
-    if(is_null($operator) || $operator->is_new() || !$operator->is_active())
72
-      throw new AccessRefusedException();
73
+    if(is_null($operator) || $operator->is_new() || !$operator->is_active()) {
74
+          throw new AccessRefusedException();
75
+    }
73 76
 
74
-    if(!is_null($permission) && !$operator->has_permission($permission))
75
-      throw new AccessRefusedException();
77
+    if(!is_null($permission) && !$operator->has_permission($permission)) {
78
+          throw new AccessRefusedException();
79
+    }
76 80
 
77 81
     return true;
78 82
   }
@@ -80,22 +84,26 @@  discard block
 block discarded – undo
80 84
   public function viewport($key=null, $value=null, $coercion=false)
81 85
   {
82 86
     // no key, returns all
83
-    if(is_null($key))
84
-      return $this->template_variables;
87
+    if(is_null($key)) {
88
+          return $this->template_variables;
89
+    }
85 90
 
86 91
     // got key, got null value, returns $[$key]
87 92
     if(is_null($value))
88 93
     {
89
-      if($coercion === true) // break rule 1 ?
94
+      if($coercion === true) {
95
+        // break rule 1 ?
90 96
         $this->template_variables[$key] = null;
97
+      }
91 98
 
92 99
       return $this->template_variables[$key] ?? null;
93 100
     }
94 101
 
95 102
     // got key, got value
96 103
     // sets or coerces $[$key]=$value and returns $[$key]
97
-    if(!isset($this->template_variables[$key]) || $coercion === true)
98
-      $this->template_variables[$key] = $value;
104
+    if(!isset($this->template_variables[$key]) || $coercion === true) {
105
+          $this->template_variables[$key] = $value;
106
+    }
99 107
 
100 108
     return $this->template_variables[$key] ?? null;
101 109
   }
@@ -106,19 +114,22 @@  discard block
 block discarded – undo
106 114
 
107 115
     $custom_template = null;
108 116
 
109
-    if(method_exists($this, 'prepare'))
110
-    	$this->prepare();
117
+    if(method_exists($this, 'prepare')) {
118
+        	$this->prepare();
119
+    }
111 120
 
112 121
   	if(method_exists($this, $method = $this->router()->target_method()))
113 122
     {
114 123
       $custom_template = $this->$method();
115 124
     }
116 125
 
117
-    if(method_exists($this, 'conclude'))
118
-    	$this->conclude();
126
+    if(method_exists($this, 'conclude')) {
127
+        	$this->conclude();
128
+    }
119 129
 
120
-    if(method_exists($this, 'display'))
121
-    	$template = $this->display($custom_template);
130
+    if(method_exists($this, 'display')) {
131
+        	$template = $this->display($custom_template);
132
+    }
122 133
   }
123 134
 
124 135
   public function conclude(){}
@@ -133,8 +144,10 @@  discard block
 block discarded – undo
133 144
     array_walk_recursive($_GET, function(&$value){$value = trim($value);});
134 145
     array_walk_recursive($_REQUEST, function(&$value){$value = trim($value);});
135 146
 
136
-    if($this->router()->submits())
137
-      array_walk_recursive($_POST, function(&$value){$value = trim($value);});
147
+    if($this->router()->submits()) {
148
+          array_walk_recursive($_POST, function(&$value){$value = trim($value);
149
+    }
150
+    });
138 151
   }
139 152
 
140 153
   public function display($custom_template = null, $standalone=false)
@@ -154,14 +167,14 @@  discard block
 block discarded – undo
154 167
   	$this->viewport('view_url', $this->router()->web_root() . $this->box('settings.smarty.template_path'));
155 168
   	$this->viewport('images_url', $this->router()->web_root() . $this->box('settings.smarty.template_path') . 'images/');
156 169
 
157
-    foreach($this->viewport() as $template_var_name => $value)
158
-      $smarty->assign($template_var_name, $value);
170
+    foreach($this->viewport() as $template_var_name => $value) {
171
+          $smarty->assign($template_var_name, $value);
172
+    }
159 173
 
160 174
     if($standalone === false)
161 175
     {
162 176
       $smarty->display(sprintf('%s|%s', $this->box('settings.smarty.template_inclusion_path'), $template));
163
-    }
164
-    else
177
+    } else
165 178
     {
166 179
       $smarty->display($template);
167 180
     }
@@ -205,8 +218,9 @@  discard block
 block discarded – undo
205 218
 
206 219
     while(!is_null($tpl_path = array_shift($templates)))
207 220
     {
208
-      if($smarty->templateExists($tpl_path))
209
-        return $tpl_path;
221
+      if($smarty->templateExists($tpl_path)) {
222
+              return $tpl_path;
223
+      }
210 224
     }
211 225
 
212 226
     throw new \Exception('KADRO_ERR_NO_TEMPLATE_TO_DISPLAY');
@@ -228,8 +242,9 @@  discard block
 block discarded – undo
228 242
    */
229 243
   public function route_back($route_name=null, $route_params=[]) : string
230 244
 	{
231
-    if(is_null($route_name))
232
-		  return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME);
245
+    if(is_null($route_name)) {
246
+    		  return $this->route_back ?? $this->router()->prehop(RouterInterface::ROUTE_HOME_NAME);
247
+    }
233 248
 
234 249
     return $this->route_back = $this->route_factory($route_name, $route_params);
235 250
 	}
@@ -240,10 +255,11 @@  discard block
 block discarded – undo
240 255
 
241 256
     if(is_string($route_name) && !empty($route_name))
242 257
     {
243
-      if($this->router()->route_exists($route_name))
244
-        $route = $this->router()->prehop($route_name, $route_params);
245
-      else
246
-        $route = $route_name;
258
+      if($this->router()->route_exists($route_name)) {
259
+              $route = $this->router()->prehop($route_name, $route_params);
260
+      } else {
261
+              $route = $route_name;
262
+      }
247 263
 
248 264
       return $route;
249 265
     }
Please login to merge, or discard this patch.
Controllers/ORMController.class.php 3 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
     foreach(['prepare', "before_$method", $method, "after_$method"] as $step => $chainling)
31 31
     {
32 32
       $this->search_and_execute_trait_methods($chainling);
33
-    	if(method_exists($this, $chainling) && empty($this->errors()))
33
+      if(method_exists($this, $chainling) && empty($this->errors()))
34 34
       {
35 35
         $res = $this->$chainling();
36 36
 
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
     }
49 49
 
50 50
     if(method_exists($this, 'conclude')) // conclude always executed, even with has_halting_messages
51
-    	$this->conclude();
51
+      $this->conclude();
52 52
 
53 53
     if(method_exists($this, 'display'))
54
-    	$template = $this->display($custom_template);
54
+      $template = $this->display($custom_template);
55 55
   }
56 56
 
57 57
   public function prepare()
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -27,19 +27,19 @@  discard block
 block discarded – undo
27 27
     $custom_template = null;
28 28
     $method = $this->router()->target_method();
29 29
 
30
-    foreach(['prepare', "before_$method", $method, "after_$method"] as $step => $chainling)
30
+    foreach (['prepare', "before_$method", $method, "after_$method"] as $step => $chainling)
31 31
     {
32 32
       $this->search_and_execute_trait_methods($chainling);
33
-    	if(method_exists($this, $chainling) && empty($this->errors()))
33
+    	if (method_exists($this, $chainling) && empty($this->errors()))
34 34
       {
35 35
         $res = $this->$chainling();
36 36
 
37
-        if($this->logger()->has_halting_messages()) // logger handled a critical error during the chailing execution
37
+        if ($this->logger()->has_halting_messages()) // logger handled a critical error during the chailing execution
38 38
         {
39 39
           break; // dont go on with other
40 40
         }
41 41
 
42
-        if($chainling === $method)
42
+        if ($chainling === $method)
43 43
         {
44 44
 
45 45
           $custom_template = $res;
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
       }
48 48
     }
49 49
 
50
-    if(method_exists($this, 'conclude')) // conclude always executed, even with has_halting_messages
50
+    if (method_exists($this, 'conclude')) // conclude always executed, even with has_halting_messages
51 51
     	$this->conclude();
52 52
 
53
-    if(method_exists($this, 'display'))
53
+    if (method_exists($this, 'display'))
54 54
     	$template = $this->display($custom_template);
55 55
   }
56 56
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
   {
59 59
     parent::prepare();
60 60
 
61
-    if(!class_exists($this->model_class_name = $this->class_name()))
61
+    if (!class_exists($this->model_class_name = $this->class_name()))
62 62
       throw new \Exception("!class_exists($this->model_class_name)");
63 63
 
64 64
     $this->model_type = $this->model_class_name::model_type();
@@ -68,22 +68,22 @@  discard block
 block discarded – undo
68 68
 
69 69
     $pk_values = [];
70 70
 
71
-    if($this->router()->submits())
71
+    if ($this->router()->submits())
72 72
     {
73 73
       $this->form_model->import($this->sanitize_post_data($this->router()->submitted()));
74 74
       $pk_values = $this->model_class_name::table()->primary_keys_match($this->router()->submitted());
75 75
 
76 76
       $this->load_model = $this->model_class_name::exists($pk_values);
77 77
     }
78
-    elseif($this->router()->requests())
78
+    elseif ($this->router()->requests())
79 79
     {
80 80
       $pk_values = $this->model_class_name::table()->primary_keys_match($this->router()->params());
81 81
 
82
-      if(!is_null($this->load_model = $this->model_class_name::exists($pk_values)))
82
+      if (!is_null($this->load_model = $this->model_class_name::exists($pk_values)))
83 83
         $this->form_model = clone $this->load_model;
84 84
     }
85 85
 
86
-    if(!is_null($this->load_model) && $this->load_model->traceable())
86
+    if (!is_null($this->load_model) && $this->load_model->traceable())
87 87
       $this->viewport('load_model_history', $this->load_model->traces() ?? []);
88 88
   }
89 89
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
   // ----------- META -----------
95 95
   public function class_name() : string
96 96
   {
97
-    if(is_null($this->model_class_name))
97
+    if (is_null($this->model_class_name))
98 98
     {
99 99
       $this->model_class_name = get_called_class();
100 100
       $this->model_class_name = str_replace('\Controllers\\', '\Models\\', $this->model_class_name);
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
   public function persist_model($model) : ?ModelInterface
108 108
   {
109 109
     $this->errors = $model->save($this->operator()->operator_id()); // returns [errors]
110
-    if(empty($this->errors()))
110
+    if (empty($this->errors()))
111 111
     {
112 112
       $this->logger()->nice('CRUDITES_INSTANCE_ALTERED', ['MODEL_'.get_class($model)::model_type().'_INSTANCE']);
113 113
       return $model;
114 114
     }
115
-    foreach($this->errors() as $field => $error_msg)
115
+    foreach ($this->errors() as $field => $error_msg)
116 116
       $this->logger()->warning($error_msg, [$field]);
117 117
 
118 118
     return null;
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
     return $this->listing(); //default dashboard is a listing
124 124
   }
125 125
 
126
-  public function listing($model=null,$filters=[],$options=[])
126
+  public function listing($model = null, $filters = [], $options = [])
127 127
   {
128 128
     $class_name = is_null($model) ? $this->model_class_name : get_class($model);
129 129
 
130
-    if(!isset($filters['date_start']))  $filters['date_start'] = $this->box('StateAgent')->filters('date_start');
131
-    if(!isset($filters['date_stop']))   $filters['date_stop'] = $this->box('StateAgent')->filters('date_stop');
130
+    if (!isset($filters['date_start']))  $filters['date_start'] = $this->box('StateAgent')->filters('date_start');
131
+    if (!isset($filters['date_stop']))   $filters['date_stop'] = $this->box('StateAgent')->filters('date_stop');
132 132
 
133 133
     // dd($filters);
134 134
     $listing = $class_name::filter($filters);
@@ -139,24 +139,24 @@  discard block
 block discarded – undo
139 139
   public function viewport_listing($class_name, $listing, $listing_template)
140 140
   {
141 141
     $listing_fields = [];
142
-    if(empty($listing))
142
+    if (empty($listing))
143 143
     {
144
-      foreach($class_name::table()->columns() as $column)
144
+      foreach ($class_name::table()->columns() as $column)
145 145
       {
146 146
 
147
-        if(!$column->is_auto_incremented() && !$column->is_hidden())
148
-          $listing_fields[$column->name()]=L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $column->name()));
147
+        if (!$column->is_auto_incremented() && !$column->is_hidden())
148
+          $listing_fields[$column->name()] = L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $column->name()));
149 149
       }
150 150
     }
151 151
     else
152 152
     {
153 153
       $current = current($listing);
154
-      if(is_object($current))
154
+      if (is_object($current))
155 155
         $current = get_object_vars($current);
156 156
 
157
-      foreach(array_keys($current) as $field)
157
+      foreach (array_keys($current) as $field)
158 158
       {
159
-        $listing_fields[$field]=L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $field));
159
+        $listing_fields[$field] = L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $field));
160 160
       }
161 161
 
162 162
     }
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
     $this->edit();
179 179
   }
180 180
 
181
-  public function edit(){}
181
+  public function edit() {}
182 182
 
183 183
   public function save()
184 184
   {
185 185
     $model = $this->persist_model($this->form_model);
186 186
 
187
-    if(empty($this->errors()))
187
+    if (empty($this->errors()))
188 188
       $this->route_back($model);
189 189
     else
190 190
     {
@@ -195,21 +195,21 @@  discard block
 block discarded – undo
195 195
 
196 196
   public function before_edit()
197 197
   {
198
-    if(!is_null($this->router()->params('id')) && is_null($this->load_model))
198
+    if (!is_null($this->router()->params('id')) && is_null($this->load_model))
199 199
     {
200 200
       $this->logger()->warning('CRUDITES_ERR_INSTANCE_NOT_FOUND', ['MODEL_'.$this->model_class_name::model_type().'_INSTANCE']);
201 201
       $this->router()->hop($this->model_class_name::model_type());
202 202
     }
203 203
   }
204 204
 
205
-  public function before_save() : array { return [];}
205
+  public function before_save() : array { return []; }
206 206
 
207 207
   // default: hop to altered object
208
-  public function after_save() {$this->router()->hop($this->route_back());}
208
+  public function after_save() {$this->router()->hop($this->route_back()); }
209 209
 
210 210
   public function destroy_confirm()
211 211
   {
212
-    if(is_null($this->load_model))
212
+    if (is_null($this->load_model))
213 213
     {
214 214
       $this->logger()->warning('CRUDITES_ERR_INSTANCE_NOT_FOUND', ['MODEL_'.$this->model_type.'_INSTANCE']);
215 215
       $this->router()->hop($this->model_type);
@@ -222,12 +222,12 @@  discard block
 block discarded – undo
222 222
 
223 223
   public function before_destroy() // default: checks for load_model and immortality, hops back to object on failure
224 224
   {
225
-    if(is_null($this->load_model))
225
+    if (is_null($this->load_model))
226 226
     {
227 227
       $this->logger()->warning('CRUDITES_ERR_INSTANCE_NOT_FOUND', ['MODEL_'.$this->model_type.'_INSTANCE']);
228 228
       $this->router()->hop($this->model_type);
229 229
     }
230
-    elseif($this->load_model->immortal())
230
+    elseif ($this->load_model->immortal())
231 231
     {
232 232
 
233 233
       $this->logger()->warning('CRUDITES_ERR_INSTANCE_IS_IMMORTAL', ['MODEL_'.$this->model_type.'_INSTANCE']);
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
 
238 238
   public function destroy()
239 239
   {
240
-    if(!$this->router()->submits())
240
+    if (!$this->router()->submits())
241 241
       throw new \Exception('KADRO_ROUTER_MUST_SUBMIT');
242 242
 
243
-    if($this->load_model->destroy($this->operator()->operator_id()) === false)
243
+    if ($this->load_model->destroy($this->operator()->operator_id()) === false)
244 244
     {
245 245
       $this->logger()->info('CRUDITES_ERR_INSTANCE_IS_UNDELETABLE', [''.$this->load_model]);
246 246
       $this->route_back($this->load_model);
@@ -263,10 +263,10 @@  discard block
 block discarded – undo
263 263
 
264 264
     $this->viewport('form_model_type', $this->model_type);
265 265
 
266
-    if(isset($this->load_model))
266
+    if (isset($this->load_model))
267 267
       $this->viewport('load_model', $this->load_model);
268 268
 
269
-    if(isset($this->form_model))
269
+    if (isset($this->form_model))
270 270
       $this->viewport('form_model', $this->form_model);
271 271
   }
272 272
 
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
 
279 279
     $header = false;
280 280
 
281
-    foreach($collection as $line)
281
+    foreach ($collection as $line)
282 282
     {
283 283
       $line = get_object_vars($line);
284
-      if($header === false)
284
+      if ($header === false)
285 285
       {
286
-        fputcsv($fp,array_keys($line));
286
+        fputcsv($fp, array_keys($line));
287 287
         $header = true;
288 288
       }
289
-      fputcsv($fp,$line);
289
+      fputcsv($fp, $line);
290 290
     }
291 291
     fclose($fp);
292 292
 
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
   public function export()
297 297
   {
298 298
     $format = $this->router()->params('format');
299
-    switch($format)
299
+    switch ($format)
300 300
     {
301 301
       case null:
302 302
         $filename = $this->model_type;
@@ -325,33 +325,33 @@  discard block
 block discarded – undo
325 325
     $route_params = [];
326 326
 
327 327
     $route_name = get_class($model)::model_type().'_';
328
-    if($model->is_new())
329
-      $route_name.= 'new';
328
+    if ($model->is_new())
329
+      $route_name .= 'new';
330 330
     else
331 331
     {
332
-      $route_name.= 'default';
332
+      $route_name .= 'default';
333 333
       $route_params = ['id' => $model->get_id()];
334 334
     }
335 335
     $res = $this->router()->prehop($route_name, $route_params);
336 336
     return $res;
337 337
   }
338 338
 
339
-  public function route_factory($route=null, $route_params=[]) : string
339
+  public function route_factory($route = null, $route_params = []) : string
340 340
   {
341
-    if(is_null($route) && $this->router()->submits())
341
+    if (is_null($route) && $this->router()->submits())
342 342
       $route = $this->form_model;
343 343
 
344
-    if(!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface'))
344
+    if (!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface'))
345 345
       $route = $this->route_model($route);
346 346
 
347 347
     return parent::route_factory($route, $route_params);
348 348
   }
349 349
 
350
-  private function sanitize_post_data($post_data=[])
350
+  private function sanitize_post_data($post_data = [])
351 351
   {
352
-    foreach($this->model_class_name::table()->columns() as $col)
352
+    foreach ($this->model_class_name::table()->columns() as $col)
353 353
     {
354
-      if($col->type()->is_boolean())
354
+      if ($col->type()->is_boolean())
355 355
       {
356 356
           $post_data[$col->name()] = !empty($post_data[$col->name()]);
357 357
       }
Please login to merge, or discard this patch.
Braces   +60 added lines, -43 removed lines patch added patch discarded remove patch
@@ -34,9 +34,12 @@  discard block
 block discarded – undo
34 34
       {
35 35
         $res = $this->$chainling();
36 36
 
37
-        if($this->logger()->has_halting_messages()) // logger handled a critical error during the chailing execution
37
+        if($this->logger()->has_halting_messages()) {
38
+          // logger handled a critical error during the chailing execution
38 39
         {
39
-          break; // dont go on with other
40
+          break;
41
+        }
42
+        // dont go on with other
40 43
         }
41 44
 
42 45
         if($chainling === $method)
@@ -47,19 +50,23 @@  discard block
 block discarded – undo
47 50
       }
48 51
     }
49 52
 
50
-    if(method_exists($this, 'conclude')) // conclude always executed, even with has_halting_messages
53
+    if(method_exists($this, 'conclude')) {
54
+      // conclude always executed, even with has_halting_messages
51 55
     	$this->conclude();
56
+    }
52 57
 
53
-    if(method_exists($this, 'display'))
54
-    	$template = $this->display($custom_template);
58
+    if(method_exists($this, 'display')) {
59
+        	$template = $this->display($custom_template);
60
+    }
55 61
   }
56 62
 
57 63
   public function prepare()
58 64
   {
59 65
     parent::prepare();
60 66
 
61
-    if(!class_exists($this->model_class_name = $this->class_name()))
62
-      throw new \Exception("!class_exists($this->model_class_name)");
67
+    if(!class_exists($this->model_class_name = $this->class_name())) {
68
+          throw new \Exception("!class_exists($this->model_class_name)");
69
+    }
63 70
 
64 71
     $this->model_type = $this->model_class_name::model_type();
65 72
 
@@ -74,17 +81,18 @@  discard block
 block discarded – undo
74 81
       $pk_values = $this->model_class_name::table()->primary_keys_match($this->router()->submitted());
75 82
 
76 83
       $this->load_model = $this->model_class_name::exists($pk_values);
77
-    }
78
-    elseif($this->router()->requests())
84
+    } elseif($this->router()->requests())
79 85
     {
80 86
       $pk_values = $this->model_class_name::table()->primary_keys_match($this->router()->params());
81 87
 
82
-      if(!is_null($this->load_model = $this->model_class_name::exists($pk_values)))
83
-        $this->form_model = clone $this->load_model;
88
+      if(!is_null($this->load_model = $this->model_class_name::exists($pk_values))) {
89
+              $this->form_model = clone $this->load_model;
90
+      }
84 91
     }
85 92
 
86
-    if(!is_null($this->load_model) && $this->load_model->traceable())
87
-      $this->viewport('load_model_history', $this->load_model->traces() ?? []);
93
+    if(!is_null($this->load_model) && $this->load_model->traceable()) {
94
+          $this->viewport('load_model_history', $this->load_model->traces() ?? []);
95
+    }
88 96
   }
89 97
 
90 98
   public function has_load_model()
@@ -112,8 +120,9 @@  discard block
 block discarded – undo
112 120
       $this->logger()->nice('CRUDITES_INSTANCE_ALTERED', ['MODEL_'.get_class($model)::model_type().'_INSTANCE']);
113 121
       return $model;
114 122
     }
115
-    foreach($this->errors() as $field => $error_msg)
116
-      $this->logger()->warning($error_msg, [$field]);
123
+    foreach($this->errors() as $field => $error_msg) {
124
+          $this->logger()->warning($error_msg, [$field]);
125
+    }
117 126
 
118 127
     return null;
119 128
   }
@@ -127,8 +136,12 @@  discard block
 block discarded – undo
127 136
   {
128 137
     $class_name = is_null($model) ? $this->model_class_name : get_class($model);
129 138
 
130
-    if(!isset($filters['date_start']))  $filters['date_start'] = $this->box('StateAgent')->filters('date_start');
131
-    if(!isset($filters['date_stop']))   $filters['date_stop'] = $this->box('StateAgent')->filters('date_stop');
139
+    if(!isset($filters['date_start'])) {
140
+      $filters['date_start'] = $this->box('StateAgent')->filters('date_start');
141
+    }
142
+    if(!isset($filters['date_stop'])) {
143
+      $filters['date_stop'] = $this->box('StateAgent')->filters('date_stop');
144
+    }
132 145
 
133 146
     // dd($filters);
134 147
     $listing = $class_name::filter($filters);
@@ -144,15 +157,16 @@  discard block
 block discarded – undo
144 157
       foreach($class_name::table()->columns() as $column)
145 158
       {
146 159
 
147
-        if(!$column->is_auto_incremented() && !$column->is_hidden())
148
-          $listing_fields[$column->name()]=L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $column->name()));
160
+        if(!$column->is_auto_incremented() && !$column->is_hidden()) {
161
+                  $listing_fields[$column->name()]=L(sprintf('MODEL_%s_FIELD_%s', $class_name::model_type(), $column->name()));
162
+        }
149 163
       }
150
-    }
151
-    else
164
+    } else
152 165
     {
153 166
       $current = current($listing);
154
-      if(is_object($current))
155
-        $current = get_object_vars($current);
167
+      if(is_object($current)) {
168
+              $current = get_object_vars($current);
169
+      }
156 170
 
157 171
       foreach(array_keys($current) as $field)
158 172
       {
@@ -184,9 +198,9 @@  discard block
 block discarded – undo
184 198
   {
185 199
     $model = $this->persist_model($this->form_model);
186 200
 
187
-    if(empty($this->errors()))
188
-      $this->route_back($model);
189
-    else
201
+    if(empty($this->errors())) {
202
+          $this->route_back($model);
203
+    } else
190 204
     {
191 205
       $this->edit();
192 206
       return 'edit';
@@ -226,8 +240,7 @@  discard block
 block discarded – undo
226 240
     {
227 241
       $this->logger()->warning('CRUDITES_ERR_INSTANCE_NOT_FOUND', ['MODEL_'.$this->model_type.'_INSTANCE']);
228 242
       $this->router()->hop($this->model_type);
229
-    }
230
-    elseif($this->load_model->immortal())
243
+    } elseif($this->load_model->immortal())
231 244
     {
232 245
 
233 246
       $this->logger()->warning('CRUDITES_ERR_INSTANCE_IS_IMMORTAL', ['MODEL_'.$this->model_type.'_INSTANCE']);
@@ -237,15 +250,15 @@  discard block
 block discarded – undo
237 250
 
238 251
   public function destroy()
239 252
   {
240
-    if(!$this->router()->submits())
241
-      throw new \Exception('KADRO_ROUTER_MUST_SUBMIT');
253
+    if(!$this->router()->submits()) {
254
+          throw new \Exception('KADRO_ROUTER_MUST_SUBMIT');
255
+    }
242 256
 
243 257
     if($this->load_model->destroy($this->operator()->operator_id()) === false)
244 258
     {
245 259
       $this->logger()->info('CRUDITES_ERR_INSTANCE_IS_UNDELETABLE', [''.$this->load_model]);
246 260
       $this->route_back($this->load_model);
247
-    }
248
-    else
261
+    } else
249 262
     {
250 263
       $this->logger()->nice('CRUDITES_INSTANCE_DESTROYED', ['MODEL_'.$this->model_type.'_INSTANCE']);
251 264
       $this->route_back($this->model_type);
@@ -263,11 +276,13 @@  discard block
 block discarded – undo
263 276
 
264 277
     $this->viewport('form_model_type', $this->model_type);
265 278
 
266
-    if(isset($this->load_model))
267
-      $this->viewport('load_model', $this->load_model);
279
+    if(isset($this->load_model)) {
280
+          $this->viewport('load_model', $this->load_model);
281
+    }
268 282
 
269
-    if(isset($this->form_model))
270
-      $this->viewport('form_model', $this->form_model);
283
+    if(isset($this->form_model)) {
284
+          $this->viewport('form_model', $this->form_model);
285
+    }
271 286
   }
272 287
 
273 288
   public function collection_to_csv($collection, $filename)
@@ -325,9 +340,9 @@  discard block
 block discarded – undo
325 340
     $route_params = [];
326 341
 
327 342
     $route_name = get_class($model)::model_type().'_';
328
-    if($model->is_new())
329
-      $route_name.= 'new';
330
-    else
343
+    if($model->is_new()) {
344
+          $route_name.= 'new';
345
+    } else
331 346
     {
332 347
       $route_name.= 'default';
333 348
       $route_params = ['id' => $model->get_id()];
@@ -338,11 +353,13 @@  discard block
 block discarded – undo
338 353
 
339 354
   public function route_factory($route=null, $route_params=[]) : string
340 355
   {
341
-    if(is_null($route) && $this->router()->submits())
342
-      $route = $this->form_model;
356
+    if(is_null($route) && $this->router()->submits()) {
357
+          $route = $this->form_model;
358
+    }
343 359
 
344
-    if(!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface'))
345
-      $route = $this->route_model($route);
360
+    if(!is_null($route) && is_subclass_of($route, '\HexMakina\Crudites\Interfaces\ModelInterface')) {
361
+          $route = $this->route_model($route);
362
+    }
346 363
 
347 364
     return parent::route_factory($route, $route_params);
348 365
   }
Please login to merge, or discard this patch.