@@ -38,8 +38,9 @@ |
||
38 | 38 | { |
39 | 39 | foreach ($attributes as $name => $value) |
40 | 40 | { |
41 | - if (!is_string($name)) |
|
42 | - throw new \InvalidArgumentException("Attribute only accepts strings as names"); |
|
41 | + if (!is_string($name)) { |
|
42 | + throw new \InvalidArgumentException("Attribute only accepts strings as names"); |
|
43 | + } |
|
43 | 44 | |
44 | 45 | $instance->setAttribute(new Attribute($name, $value)); |
45 | 46 | } |
@@ -258,12 +258,12 @@ |
||
258 | 258 | { |
259 | 259 | if (static::HAS_END_TAG) |
260 | 260 | { |
261 | - $this->startTag = "<" .strtolower(static::NODE_NAME). ">"; |
|
262 | - $this->endTag = "</" .strtolower(static::NODE_NAME). ">"; |
|
261 | + $this->startTag = "<" . strtolower(static::NODE_NAME) . ">"; |
|
262 | + $this->endTag = "</" . strtolower(static::NODE_NAME) . ">"; |
|
263 | 263 | } |
264 | 264 | else |
265 | 265 | { |
266 | - $this->startTag = "<" .strtolower(static::NODE_NAME); |
|
266 | + $this->startTag = "<" . strtolower(static::NODE_NAME); |
|
267 | 267 | $this->endTag = "/>"; |
268 | 268 | } |
269 | 269 | } |
@@ -110,8 +110,9 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function hasChild($label) |
112 | 112 | { |
113 | - if (array_key_exists($label, $this->children)) |
|
114 | - return true; |
|
113 | + if (array_key_exists($label, $this->children)) { |
|
114 | + return true; |
|
115 | + } |
|
115 | 116 | |
116 | 117 | return false; |
117 | 118 | } |
@@ -125,8 +126,9 @@ discard block |
||
125 | 126 | */ |
126 | 127 | public function getChild($label) |
127 | 128 | { |
128 | - if (array_key_exists($label, $this->children)) |
|
129 | - return $this->children[$label]; |
|
129 | + if (array_key_exists($label, $this->children)) { |
|
130 | + return $this->children[$label]; |
|
131 | + } |
|
130 | 132 | |
131 | 133 | return null; |
132 | 134 | } |
@@ -155,10 +157,11 @@ discard block |
||
155 | 157 | */ |
156 | 158 | public function removeChild($label) |
157 | 159 | { |
158 | - if (array_key_exists($label, $this->children)) |
|
159 | - unset($this->children[$label]); |
|
160 | - else |
|
161 | - throw new Exception\ChildNotFoundException("The child to remove does not exists"); |
|
160 | + if (array_key_exists($label, $this->children)) { |
|
161 | + unset($this->children[$label]); |
|
162 | + } else { |
|
163 | + throw new Exception\ChildNotFoundException("The child to remove does not exists"); |
|
164 | + } |
|
162 | 165 | } |
163 | 166 | |
164 | 167 | /** |
@@ -174,8 +177,9 @@ discard block |
||
174 | 177 | { |
175 | 178 | foreach ($this->attributes as $attrib) |
176 | 179 | { |
177 | - if ($attrib->getName() == $name) |
|
178 | - return true; |
|
180 | + if ($attrib->getName() == $name) { |
|
181 | + return true; |
|
182 | + } |
|
179 | 183 | } |
180 | 184 | } |
181 | 185 | |
@@ -195,8 +199,9 @@ discard block |
||
195 | 199 | { |
196 | 200 | foreach ($this->attributes as $attrib) |
197 | 201 | { |
198 | - if ($attrib->getName() == $name) |
|
199 | - return $attrib; |
|
202 | + if ($attrib->getName() == $name) { |
|
203 | + return $attrib; |
|
204 | + } |
|
200 | 205 | } |
201 | 206 | } |
202 | 207 | |
@@ -218,12 +223,13 @@ discard block |
||
218 | 223 | { |
219 | 224 | foreach ($this->attributes as $key => $_attrib) |
220 | 225 | { |
221 | - if ($_attrib->getName() == $attrib->getName()) |
|
222 | - $this->attributes[$key] = $attribute; |
|
226 | + if ($_attrib->getName() == $attrib->getName()) { |
|
227 | + $this->attributes[$key] = $attribute; |
|
228 | + } |
|
223 | 229 | } |
230 | + } else { |
|
231 | + $this->attributes[] = $attribute; |
|
224 | 232 | } |
225 | - else |
|
226 | - $this->attributes[] = $attribute; |
|
227 | 233 | } |
228 | 234 | |
229 | 235 | /** |
@@ -241,8 +247,9 @@ discard block |
||
241 | 247 | { |
242 | 248 | foreach ($this->attributes as $key => $attrib) |
243 | 249 | { |
244 | - if ($attrib->getName() == $name) |
|
245 | - unset($this->attributes[$key]); |
|
250 | + if ($attrib->getName() == $name) { |
|
251 | + unset($this->attributes[$key]); |
|
252 | + } |
|
246 | 253 | } |
247 | 254 | } |
248 | 255 | |
@@ -260,8 +267,7 @@ discard block |
||
260 | 267 | { |
261 | 268 | $this->startTag = "<" .strtolower(static::NODE_NAME). ">"; |
262 | 269 | $this->endTag = "</" .strtolower(static::NODE_NAME). ">"; |
263 | - } |
|
264 | - else |
|
270 | + } else |
|
265 | 271 | { |
266 | 272 | $this->startTag = "<" .strtolower(static::NODE_NAME); |
267 | 273 | $this->endTag = "/>"; |
@@ -275,8 +281,9 @@ discard block |
||
275 | 281 | */ |
276 | 282 | public function isFormControl() |
277 | 283 | { |
278 | - if (in_array(static::NODE_NAME, ['INPUT'])) |
|
279 | - return true; |
|
284 | + if (in_array(static::NODE_NAME, ['INPUT'])) { |
|
285 | + return true; |
|
286 | + } |
|
280 | 287 | |
281 | 288 | return false; |
282 | 289 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | ]); |
48 | 48 | |
49 | 49 | $form->fill([ |
50 | - "username" => 'jobs', # wrong because of minlength attr |
|
50 | + "username" => 'jobs', # wrong because of minlength attr |
|
51 | 51 | "password" => 'jVi7Qp4X', |
52 | 52 | "email" => 'j@' # wrong because of type and minlength attr |
53 | 53 | ]); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | ]); |
199 | 199 | |
200 | 200 | $form->fill([ |
201 | - "username" => 'jobs', # wrong because of minlength attr |
|
201 | + "username" => 'jobs', # wrong because of minlength attr |
|
202 | 202 | ]); |
203 | 203 | |
204 | 204 | $validator = new FormValidator($form, 'en'); |
@@ -243,12 +243,12 @@ discard block |
||
243 | 243 | $form->fill([ |
244 | 244 | "product" => [ |
245 | 245 | "optical mouse", |
246 | - "-", # wrong name |
|
246 | + "-", # wrong name |
|
247 | 247 | "78" # another wrong name |
248 | 248 | ], |
249 | 249 | "price" => [ |
250 | 250 | 10, |
251 | - 0, # wrong price |
|
251 | + 0, # wrong price |
|
252 | 252 | 0 # another wrong price |
253 | 253 | ] |
254 | 254 | ]); |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | ]); |
306 | 306 | |
307 | 307 | $form->fill([ |
308 | - "username" => 'steave jobs', # wrong because of minlength attr |
|
308 | + "username" => 'steave jobs', # wrong because of minlength attr |
|
309 | 309 | "password" => 'jVi7Qp4X', |
310 | 310 | "type" => 'moderator' # wrong because moderator is not a valid needle |
311 | 311 | ]); |
@@ -48,11 +48,13 @@ |
||
48 | 48 | { |
49 | 49 | $child = $this->getChild($label); |
50 | 50 | |
51 | - if (is_null($child)) |
|
52 | - throw new Exception\ChildNotFoundException("The child '$label' does not exists inside the form element"); |
|
51 | + if (is_null($child)) { |
|
52 | + throw new Exception\ChildNotFoundException("The child '$label' does not exists inside the form element"); |
|
53 | + } |
|
53 | 54 | |
54 | - if (!$child->isFormControl()) |
|
55 | - throw new Exception\NotFormControlException("The child '$label' is not a form control"); |
|
55 | + if (!$child->isFormControl()) { |
|
56 | + throw new Exception\NotFormControlException("The child '$label' is not a form control"); |
|
57 | + } |
|
56 | 58 | |
57 | 59 | $child->setAttribute(new Attribute("value", $value)); |
58 | 60 | } |
@@ -92,29 +92,32 @@ discard block |
||
92 | 92 | */ |
93 | 93 | protected function _error($code, $message = null) |
94 | 94 | { |
95 | - if (!is_null($code) && !is_integer($code) && !is_string($code)) |
|
96 | - throw new \InvalidArgumentException("Invalid type given. Integer or string expected"); |
|
95 | + if (!is_null($code) && !is_integer($code) && !is_string($code)) { |
|
96 | + throw new \InvalidArgumentException("Invalid type given. Integer or string expected"); |
|
97 | + } |
|
97 | 98 | |
98 | - if (is_null($code)) |
|
99 | - $code = preg_replace('/=|\/|\+/', "", base64_encode($message)); |
|
100 | - else |
|
99 | + if (is_null($code)) { |
|
100 | + $code = preg_replace('/=|\/|\+/', "", base64_encode($message)); |
|
101 | + } else |
|
101 | 102 | { |
102 | - if (!array_key_exists($code, $this->standardErrors) && empty($message)) |
|
103 | - /* |
|
103 | + if (!array_key_exists($code, $this->standardErrors) && empty($message)) { |
|
104 | + /* |
|
104 | 105 | * Non-standard errors must have a message to describe the error, make sure |
105 | 106 | * you execute the error() method with a message as the second parameter. |
106 | 107 | */ |
107 | 108 | throw new \LogicException('The message does not be empty in non-standard errors!'); |
109 | + } |
|
108 | 110 | } |
109 | 111 | |
110 | - if (!array_key_exists($code, $this->errors)) |
|
111 | - $this->errors[$code] = (array_key_exists($code, $this->standardErrors)) |
|
112 | + if (!array_key_exists($code, $this->errors)) { |
|
113 | + $this->errors[$code] = (array_key_exists($code, $this->standardErrors)) |
|
112 | 114 | ? |
113 | 115 | is_null($message) |
114 | 116 | ? preg_replace('/\s\'%[a-zA-Z]*%\'/', $message, $this->standardErrors[$code]) |
115 | 117 | # if $message is not null it will replace the %file% wildcard |
116 | 118 | : preg_replace('/%[a-zA-Z]*%/', $message, $this->standardErrors[$code]) |
117 | 119 | : $message; |
120 | + } |
|
118 | 121 | } |
119 | 122 | |
120 | 123 | function __call($method, $arguments) |
@@ -124,10 +127,11 @@ discard block |
||
124 | 127 | switch (count($arguments)) |
125 | 128 | { |
126 | 129 | case 1: |
127 | - if (is_integer($arguments[0])) |
|
128 | - return call_user_func([$this, '_error'], array_shift($arguments)); |
|
129 | - else |
|
130 | - return call_user_func([$this, '_error'], null, array_shift($arguments)); |
|
130 | + if (is_integer($arguments[0])) { |
|
131 | + return call_user_func([$this, '_error'], array_shift($arguments)); |
|
132 | + } else { |
|
133 | + return call_user_func([$this, '_error'], null, array_shift($arguments)); |
|
134 | + } |
|
131 | 135 | break; |
132 | 136 | case 2: |
133 | 137 | return call_user_func([$this, '_error'], $arguments[0], $arguments[1]); |
@@ -304,7 +304,7 @@ |
||
304 | 304 | { |
305 | 305 | foreach ($validator->getMessages() as $message) |
306 | 306 | { |
307 | - $this->error($label ."-~-". (count($this->getErrors()) + 1), $message); |
|
307 | + $this->error($label . "-~-" . (count($this->getErrors()) + 1), $message); |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | } |
@@ -69,9 +69,10 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function isValid() |
71 | 71 | { |
72 | - if (is_null($this->valid)) |
|
73 | - # This error is thrown because of 'setValid' method has not been executed. |
|
72 | + if (is_null($this->valid)) { |
|
73 | + # This error is thrown because of 'setValid' method has not been executed. |
|
74 | 74 | throw new \LogicException('No validation has been executed!'); |
75 | + } |
|
75 | 76 | |
76 | 77 | return $this->valid; |
77 | 78 | } |
@@ -98,8 +99,9 @@ discard block |
||
98 | 99 | { |
99 | 100 | $this->form = $form; |
100 | 101 | |
101 | - if (is_null($locale)) |
|
102 | - $locale = 'en'; |
|
102 | + if (is_null($locale)) { |
|
103 | + $locale = 'en'; |
|
104 | + } |
|
103 | 105 | |
104 | 106 | $i18nTranslator = \Zend\I18n\Translator\Translator::factory( |
105 | 107 | [ |
@@ -133,8 +135,9 @@ discard block |
||
133 | 135 | |
134 | 136 | foreach ($elements as $label => $element) |
135 | 137 | { |
136 | - if (!$element->isFormControl()) |
|
137 | - continue; |
|
138 | + if (!$element->isFormControl()) { |
|
139 | + continue; |
|
140 | + } |
|
138 | 141 | |
139 | 142 | $attribs = $element->getAttributes(); |
140 | 143 | |
@@ -203,19 +206,21 @@ discard block |
||
203 | 206 | |
204 | 207 | case 'min': |
205 | 208 | |
206 | - if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) |
|
207 | - $validator = new GreaterThan(['min' => $value, 'inclusive' => true]); |
|
208 | - else |
|
209 | - throw new \LogicException("The input type must be 'range' or 'number'"); |
|
209 | + if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) { |
|
210 | + $validator = new GreaterThan(['min' => $value, 'inclusive' => true]); |
|
211 | + } else { |
|
212 | + throw new \LogicException("The input type must be 'range' or 'number'"); |
|
213 | + } |
|
210 | 214 | |
211 | 215 | break; |
212 | 216 | |
213 | 217 | case 'max': |
214 | 218 | |
215 | - if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) |
|
216 | - $validator = new LessThan(['max' => $value, 'inclusive' => true]); |
|
217 | - else |
|
218 | - throw new \LogicException("The input type must be 'range' or 'number'"); |
|
219 | + if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) { |
|
220 | + $validator = new LessThan(['max' => $value, 'inclusive' => true]); |
|
221 | + } else { |
|
222 | + throw new \LogicException("The input type must be 'range' or 'number'"); |
|
223 | + } |
|
219 | 224 | |
220 | 225 | break; |
221 | 226 | |
@@ -223,17 +228,19 @@ discard block |
||
223 | 228 | |
224 | 229 | $baseValue = (array_key_exists('min', $all_attribs)) ? $all_attribs['min'] : 0; |
225 | 230 | |
226 | - if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['range'])) |
|
227 | - $validator = new Step(['baseValue' => $baseValue, 'step' => $value]); |
|
228 | - else |
|
229 | - throw new \LogicException("The input type must be 'range'"); |
|
231 | + if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['range'])) { |
|
232 | + $validator = new Step(['baseValue' => $baseValue, 'step' => $value]); |
|
233 | + } else { |
|
234 | + throw new \LogicException("The input type must be 'range'"); |
|
235 | + } |
|
230 | 236 | |
231 | 237 | break; |
232 | 238 | |
233 | 239 | case 'data-validators': |
234 | 240 | |
235 | - if (!is_array($value)) |
|
236 | - throw new \InvalidArgumentException("Invalid type given. Array expected in 'data-validators' attribute."); |
|
241 | + if (!is_array($value)) { |
|
242 | + throw new \InvalidArgumentException("Invalid type given. Array expected in 'data-validators' attribute."); |
|
243 | + } |
|
237 | 244 | |
238 | 245 | foreach ($value as $class => $params) |
239 | 246 | { |
@@ -243,8 +250,9 @@ discard block |
||
243 | 250 | { |
244 | 251 | $className = "\Zend\I18n\Validator\\" . $class; |
245 | 252 | |
246 | - if (!class_exists($className)) |
|
247 | - throw new \RuntimeException("The class '$userInputClass' or '$className' does not exists"); |
|
253 | + if (!class_exists($className)) { |
|
254 | + throw new \RuntimeException("The class '$userInputClass' or '$className' does not exists"); |
|
255 | + } |
|
248 | 256 | } |
249 | 257 | |
250 | 258 | $validator = new $className($params); |
@@ -291,8 +299,9 @@ discard block |
||
291 | 299 | $v->setTranslator($this->translator); |
292 | 300 | $notEmpty = $v->isValid($val); |
293 | 301 | |
294 | - if (!$required && !$notEmpty) |
|
295 | - return null; |
|
302 | + if (!$required && !$notEmpty) { |
|
303 | + return null; |
|
304 | + } |
|
296 | 305 | |
297 | 306 | $valid = $validator->isValid($val); |
298 | 307 | $this->setValid($valid); |
@@ -304,8 +313,7 @@ discard block |
||
304 | 313 | $this->error($label ."-~-". (count($this->getErrors()) + 1), $message); |
305 | 314 | } |
306 | 315 | } |
307 | - } |
|
308 | - else |
|
316 | + } else |
|
309 | 317 | { |
310 | 318 | foreach ($form_value as $val) |
311 | 319 | { |
@@ -330,8 +338,9 @@ discard block |
||
330 | 338 | $errorLbl = explode("-~-", $key); |
331 | 339 | $label = array_shift($errorLbl); |
332 | 340 | |
333 | - if (!array_key_exists($label, $errors)) |
|
334 | - $errors[$label] = []; |
|
341 | + if (!array_key_exists($label, $errors)) { |
|
342 | + $errors[$label] = []; |
|
343 | + } |
|
335 | 344 | |
336 | 345 | $errors[$label][] = $value; |
337 | 346 | } |
@@ -93,7 +93,7 @@ |
||
93 | 93 | { |
94 | 94 | $new = array(); |
95 | 95 | |
96 | - foreach($obj as $key => $val) |
|
96 | + foreach ($obj as $key => $val) |
|
97 | 97 | { |
98 | 98 | $new[$key] = self::objectToArray($val); |
99 | 99 | } |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | $again = true; |
40 | 40 | $new_config[$param . $glue . $key] = $value; |
41 | 41 | } |
42 | + } else { |
|
43 | + $new_config[$param] = $configure; |
|
42 | 44 | } |
43 | - else |
|
44 | - $new_config[$param] = $configure; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | return (!$again) ? $new_config : self::toUnidimensional($new_config, $glue); |
@@ -64,15 +64,17 @@ discard block |
||
64 | 64 | |
65 | 65 | do |
66 | 66 | { |
67 | - if (array_key_exists($key, $haystack)) |
|
68 | - $haystack = $haystack[$key]; |
|
69 | - else |
|
70 | - return $value; |
|
67 | + if (array_key_exists($key, $haystack)) { |
|
68 | + $haystack = $haystack[$key]; |
|
69 | + } else { |
|
70 | + return $value; |
|
71 | + } |
|
71 | 72 | |
72 | 73 | $key = count($needle) ? array_shift($needle) : NULL; |
73 | 74 | |
74 | - if (is_null($key)) |
|
75 | - return $haystack; |
|
75 | + if (is_null($key)) { |
|
76 | + return $haystack; |
|
77 | + } |
|
76 | 78 | |
77 | 79 | } while (!is_null($key)); |
78 | 80 | } |
@@ -86,8 +88,9 @@ discard block |
||
86 | 88 | */ |
87 | 89 | public static function objectToArray($obj) |
88 | 90 | { |
89 | - if (is_object($obj)) |
|
90 | - $obj = (array) $obj; |
|
91 | + if (is_object($obj)) { |
|
92 | + $obj = (array) $obj; |
|
93 | + } |
|
91 | 94 | |
92 | 95 | if (is_array($obj)) |
93 | 96 | { |
@@ -97,9 +100,9 @@ discard block |
||
97 | 100 | { |
98 | 101 | $new[$key] = self::objectToArray($val); |
99 | 102 | } |
103 | + } else { |
|
104 | + $new = $obj; |
|
100 | 105 | } |
101 | - else |
|
102 | - $new = $obj; |
|
103 | 106 | |
104 | 107 | return $new; |
105 | 108 | } |
@@ -25,8 +25,7 @@ discard block |
||
25 | 25 | try |
26 | 26 | { |
27 | 27 | throw new ExceptionException("This is an storable exception"); |
28 | - } |
|
29 | - catch (ExceptionException $e) |
|
28 | + } catch (ExceptionException $e) |
|
30 | 29 | { |
31 | 30 | mkdir('exceptions'); |
32 | 31 | |
@@ -64,8 +63,7 @@ discard block |
||
64 | 63 | try |
65 | 64 | { |
66 | 65 | throw new ExceptionException("This is an storable exception too"); |
67 | - } |
|
68 | - catch (ExceptionException $e) |
|
66 | + } catch (ExceptionException $e) |
|
69 | 67 | { |
70 | 68 | $date = date('dmY'); |
71 | 69 | $file = 'nofolder/exception-' . $date . '.json'; |
@@ -95,8 +93,7 @@ discard block |
||
95 | 93 | try |
96 | 94 | { |
97 | 95 | throw new ExceptionException("This is an storable exception"); |
98 | - } |
|
99 | - catch (ExceptionException $e) |
|
96 | + } catch (ExceptionException $e) |
|
100 | 97 | { |
101 | 98 | $file = 'exceptions/exception-' . $date . '.json'; |
102 | 99 | $storage = new \Drone\Exception\Storage($file); |
@@ -106,8 +103,7 @@ discard block |
||
106 | 103 | try |
107 | 104 | { |
108 | 105 | throw new ExceptionException("This is an storable exception too"); |
109 | - } |
|
110 | - catch (ExceptionException $e) |
|
106 | + } catch (ExceptionException $e) |
|
111 | 107 | { |
112 | 108 | $file = 'exceptions/exception-' . $date . '.json'; |
113 | 109 | $storage = new \Drone\Exception\Storage($file); |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | * This instruction includes each module declared. |
163 | 163 | * Each module has an autoloader to load its classes (controllers and models) |
164 | 164 | */ |
165 | - if (file_exists($this->modulePath ."/". $module."/Module.php")) |
|
166 | - include($this->modulePath ."/". $module."/Module.php"); |
|
165 | + if (file_exists($this->modulePath . "/" . $module . "/Module.php")) |
|
166 | + include($this->modulePath . "/" . $module . "/Module.php"); |
|
167 | 167 | |
168 | 168 | spl_autoload_register($module . "\Module::loader"); |
169 | 169 | } |
@@ -179,17 +179,17 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function run() |
181 | 181 | { |
182 | - $module = isset($_GET["module"]) ? $_GET["module"] : null; |
|
182 | + $module = isset($_GET["module"]) ? $_GET["module"] : null; |
|
183 | 183 | $controller = isset($_GET["controller"]) ? $_GET["controller"] : null; |
184 | - $view = isset($_GET["view"]) ? $_GET["view"] : null; |
|
184 | + $view = isset($_GET["view"]) ? $_GET["view"] : null; |
|
185 | 185 | |
186 | 186 | $request = new \Zend\Http\Request(); |
187 | 187 | |
188 | 188 | # build URI |
189 | 189 | $uri = ''; |
190 | - $uri .= !empty($module) ? '/' . $module : ""; |
|
190 | + $uri .= !empty($module) ? '/' . $module : ""; |
|
191 | 191 | $uri .= !empty($controller) ? '/' . $controller : ""; |
192 | - $uri .= !empty($view) ? '/' . $view : ""; |
|
192 | + $uri .= !empty($view) ? '/' . $view : ""; |
|
193 | 193 | |
194 | 194 | if (empty($uri)) |
195 | 195 | $uri = "/"; |
@@ -92,19 +92,23 @@ discard block |
||
92 | 92 | public function __construct(Array $config) |
93 | 93 | { |
94 | 94 | # start sessions |
95 | - if (!isset($_SESSION)) |
|
96 | - session_start(); |
|
95 | + if (!isset($_SESSION)) { |
|
96 | + session_start(); |
|
97 | + } |
|
97 | 98 | |
98 | - if (!array_key_exists('environment', $config)) |
|
99 | - throw new \InvalidArgumentException("The 'environment' key was not defined"); |
|
99 | + if (!array_key_exists('environment', $config)) { |
|
100 | + throw new \InvalidArgumentException("The 'environment' key was not defined"); |
|
101 | + } |
|
100 | 102 | |
101 | - if (!array_key_exists('dev_mode', $config['environment'])) |
|
102 | - throw new \InvalidArgumentException("The 'dev_mode' key was not defined"); |
|
103 | + if (!array_key_exists('dev_mode', $config['environment'])) { |
|
104 | + throw new \InvalidArgumentException("The 'dev_mode' key was not defined"); |
|
105 | + } |
|
103 | 106 | |
104 | 107 | $this->devMode = $config["environment"]["dev_mode"]; |
105 | 108 | |
106 | - if (!array_key_exists('modules', $config)) |
|
107 | - throw new \InvalidArgumentException("The 'modules' key was not defined"); |
|
109 | + if (!array_key_exists('modules', $config)) { |
|
110 | + throw new \InvalidArgumentException("The 'modules' key was not defined"); |
|
111 | + } |
|
108 | 112 | |
109 | 113 | $this->modules = $config["modules"]; |
110 | 114 | |
@@ -118,8 +122,7 @@ discard block |
||
118 | 122 | { |
119 | 123 | ini_set('display_errors', 1); |
120 | 124 | error_reporting(-1); |
121 | - } |
|
122 | - else |
|
125 | + } else |
|
123 | 126 | { |
124 | 127 | ini_set('display_errors', 0); |
125 | 128 | error_reporting(0); |
@@ -128,26 +131,30 @@ discard block |
||
128 | 131 | # register autoloading functions for each module |
129 | 132 | $this->autoload($this->modules); |
130 | 133 | |
131 | - if (!array_key_exists('router', $config)) |
|
132 | - throw new \InvalidArgumentException("The 'router' key was not defined"); |
|
134 | + if (!array_key_exists('router', $config)) { |
|
135 | + throw new \InvalidArgumentException("The 'router' key was not defined"); |
|
136 | + } |
|
133 | 137 | |
134 | - if (!array_key_exists('routes', $config["router"])) |
|
135 | - throw new \InvalidArgumentException("The 'routes' key was not defined"); |
|
138 | + if (!array_key_exists('routes', $config["router"])) { |
|
139 | + throw new \InvalidArgumentException("The 'routes' key was not defined"); |
|
140 | + } |
|
136 | 141 | |
137 | 142 | $this->router = new Router($config["router"]["routes"]); |
138 | 143 | |
139 | - if (!array_key_exists('base_path', $config['environment'])) |
|
140 | - throw new \InvalidArgumentException("The 'base_path' key was not defined"); |
|
144 | + if (!array_key_exists('base_path', $config['environment'])) { |
|
145 | + throw new \InvalidArgumentException("The 'base_path' key was not defined"); |
|
146 | + } |
|
141 | 147 | |
142 | 148 | $this->router->setBasePath($config["environment"]["base_path"]); |
143 | 149 | |
144 | 150 | # load routes from config |
145 | 151 | foreach ($config["router"]["routes"] as $name => $route) |
146 | 152 | { |
147 | - if ($route instanceof \Zend\Router\Http\RouteInterface) |
|
148 | - $this->getRouter()->addZendRoute($name, $route); |
|
149 | - else |
|
150 | - $this->getRouter()->addRoute($route); |
|
153 | + if ($route instanceof \Zend\Router\Http\RouteInterface) { |
|
154 | + $this->getRouter()->addZendRoute($name, $route); |
|
155 | + } else { |
|
156 | + $this->getRouter()->addRoute($route); |
|
157 | + } |
|
151 | 158 | } |
152 | 159 | |
153 | 160 | # load routes from each module |
@@ -157,11 +164,13 @@ discard block |
||
157 | 164 | { |
158 | 165 | $module_config_file = require($this->modulePath . "/$module/config/module.config.php"); |
159 | 166 | |
160 | - if (!array_key_exists('router', $module_config_file)) |
|
161 | - throw new \RuntimeException("The 'router' key was not defined in the config file for module '$module'"); |
|
167 | + if (!array_key_exists('router', $module_config_file)) { |
|
168 | + throw new \RuntimeException("The 'router' key was not defined in the config file for module '$module'"); |
|
169 | + } |
|
162 | 170 | |
163 | - if (!array_key_exists('routes', $module_config_file["router"])) |
|
164 | - throw new \RuntimeException("The 'routes' key was not defined in the config file for module '$module'"); |
|
171 | + if (!array_key_exists('routes', $module_config_file["router"])) { |
|
172 | + throw new \RuntimeException("The 'routes' key was not defined in the config file for module '$module'"); |
|
173 | + } |
|
165 | 174 | |
166 | 175 | $this->getRouter()->addRoute($module_config_file["router"]["routes"]); |
167 | 176 | } |
@@ -190,14 +199,15 @@ discard block |
||
190 | 199 | * This instruction includes each module declared. |
191 | 200 | * Each module has an autoloader to load its classes (controllers and models) |
192 | 201 | */ |
193 | - if (file_exists($this->modulePath ."/". $module."/Module.php")) |
|
194 | - include($this->modulePath ."/". $module."/Module.php"); |
|
202 | + if (file_exists($this->modulePath ."/". $module."/Module.php")) { |
|
203 | + include($this->modulePath ."/". $module."/Module.php"); |
|
204 | + } |
|
195 | 205 | |
196 | 206 | spl_autoload_register($module . "\Module::loader"); |
197 | 207 | } |
208 | + } else { |
|
209 | + throw new \RuntimeException("The application must have at least one module"); |
|
198 | 210 | } |
199 | - else |
|
200 | - throw new \RuntimeException("The application must have at least one module"); |
|
201 | 211 | } |
202 | 212 | |
203 | 213 | /** |
@@ -219,8 +229,9 @@ discard block |
||
219 | 229 | $uri .= !empty($controller) ? '/' . $controller : ""; |
220 | 230 | $uri .= !empty($view) ? '/' . $view : ""; |
221 | 231 | |
222 | - if (empty($uri)) |
|
223 | - $uri = "/"; |
|
232 | + if (empty($uri)) { |
|
233 | + $uri = "/"; |
|
234 | + } |
|
224 | 235 | |
225 | 236 | $request->setUri($uri); |
226 | 237 | |
@@ -236,9 +247,9 @@ discard block |
||
236 | 247 | $view = $params["action"]; |
237 | 248 | |
238 | 249 | $this->router->setIdentifiers($module, $controller, $view); |
250 | + } else { |
|
251 | + $this->router->setIdentifiers($module, $controller, $view); |
|
239 | 252 | } |
240 | - else |
|
241 | - $this->router->setIdentifiers($module, $controller, $view); |
|
242 | 253 | |
243 | 254 | $this->router->run(); |
244 | 255 | } |