@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | if ($execMethodName) { // Used to test for null but it could easily be an empty string |
172 | 172 | $this->log( "Rendering with exec: {$execMethodName}, args:".var_export($execArgs, true ), LogLevel::DEBUG ); |
173 | 173 | $out = $this->execMethod( $execMethodName, $execArgs ); |
174 | - }else { |
|
174 | + } else { |
|
175 | 175 | $this->log( "Rendering without exec", LogLevel::DEBUG ); |
176 | 176 | $out = $this->template->render( $this->state, $this->props ); |
177 | 177 | if (!( $out instanceof ViewComponentResponse )) { |
@@ -197,12 +197,12 @@ discard block |
||
197 | 197 | if (count( $methodName ) == 1) { |
198 | 198 | $methodName = $methodName[ 0 ] . 'Handler'; |
199 | 199 | $out = $this->$methodName( $args ); |
200 | - }else { |
|
200 | + } else { |
|
201 | 201 | $childName = array_shift( $methodName ); |
202 | 202 | $child = $this->childComponents[ $childName ]; |
203 | 203 | if ($child instanceof AbstractViewComponent) { |
204 | 204 | $out = $child->execMethod( $methodName, $args ); |
205 | - }else { |
|
205 | + } else { |
|
206 | 206 | throw new \Exception( implode( ".", $methodName ) . " is not a valid method." ); |
207 | 207 | } |
208 | 208 | } |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | } |
284 | 284 | if (null !== ( $pPath = $this->parent->getPath() )) { |
285 | 285 | return $pPath . '.' . $this->handle; |
286 | - }else { |
|
286 | + } else { |
|
287 | 287 | return $this->handle; |
288 | 288 | } |
289 | 289 | } |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | } |
307 | 307 | $child = new $type( $handle, $this, $this->exec, $this->logger ); |
308 | 308 | $this->childComponents[ $handle ] = $child; |
309 | - }else { |
|
309 | + } else { |
|
310 | 310 | // exec, di and logger are set recursively in rehydrate() |
311 | 311 | $child = $this->childComponents[ $handle ]; |
312 | 312 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
145 | - * @return array |
|
145 | + * @return string[] |
|
146 | 146 | */ |
147 | 147 | public function __sleep() |
148 | 148 | { |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | /** |
185 | 185 | * Execute a component method within the page or component. |
186 | 186 | * Called first on a top level component which then passes the call down to the appropriate sub-component (or executes on itself if appropriate). |
187 | - * @param array|string $methodName A methodname in the format subComponent.anotherSubComponent.methodName. Either dotted string as described, or parts in an array. The top level page component shouldn't be included |
|
187 | + * @param string $methodName A methodname in the format subComponent.anotherSubComponent.methodName. Either dotted string as described, or parts in an array. The top level page component shouldn't be included |
|
188 | 188 | * @param array $args |
189 | 189 | * @throws \Exception |
190 | 190 | * @return Response |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
217 | - * @param $execMethod |
|
217 | + * @param string $execMethod |
|
218 | 218 | * @return string |
219 | 219 | */ |
220 | 220 | public function getExecPath( $execMethod ) |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * Render a child component. |
323 | 323 | * |
324 | 324 | * @param $handle |
325 | - * @return Response |
|
325 | + * @return string |
|
326 | 326 | * @throws \Exception |
327 | 327 | */ |
328 | 328 | public function renderChild( $handle ) |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | AbstractViewComponent $parent = null, |
83 | 83 | ExecHelper $execHelper = null, |
84 | 84 | LoggerInterface $logger = null |
85 | - ){ |
|
85 | + ) { |
|
86 | 86 | // Null means we are root |
87 | 87 | $this->parent = $parent; |
88 | 88 | |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | if (null === $execHelper) { |
93 | 93 | $execHelper = new ExecHelper(); |
94 | 94 | } |
95 | - $this->setExec( $execHelper ); |
|
95 | + $this->setExec($execHelper); |
|
96 | 96 | |
97 | 97 | $this->handleDependencyInjection(); |
98 | 98 | |
99 | - $this->setLogger( $logger ); |
|
99 | + $this->setLogger($logger); |
|
100 | 100 | |
101 | 101 | // Set up the state container |
102 | 102 | $this->initState(); |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | * @param string $message |
107 | 107 | * @param string $level A constant from LogLevel |
108 | 108 | */ |
109 | - protected function log( $message, $level ){ |
|
110 | - if( isset( $this->logger ) ){ |
|
111 | - $class = get_class( $this ); |
|
109 | + protected function log($message, $level) { |
|
110 | + if (isset($this->logger)) { |
|
111 | + $class = get_class($this); |
|
112 | 112 | $message = "[{$class}] {$message}"; |
113 | - $this->logger->log( $level, $message ); |
|
113 | + $this->logger->log($level, $message); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | * User this to serialise ViewComponents as extra steps may be added later. |
119 | 119 | * @return string |
120 | 120 | */ |
121 | - public function dehydrate(){ |
|
122 | - $this->log( "Dehydrating", LogLevel::DEBUG ); |
|
123 | - return serialize( $this ); |
|
121 | + public function dehydrate() { |
|
122 | + $this->log("Dehydrating", LogLevel::DEBUG); |
|
123 | + return serialize($this); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | * @return AbstractViewComponent |
132 | 132 | */ |
133 | 133 | |
134 | - public static function rehydrate( $serialised, ExecHelper $execHelper, LoggerInterface $logger = null ){ |
|
134 | + public static function rehydrate($serialised, ExecHelper $execHelper, LoggerInterface $logger = null) { |
|
135 | 135 | /** @var AbstractViewComponent $view */ |
136 | - $view = unserialize( $serialised ); |
|
137 | - $view->setExec( $execHelper ); |
|
136 | + $view = unserialize($serialised); |
|
137 | + $view->setExec($execHelper); |
|
138 | 138 | $view->handleDependencyInjection(); |
139 | - $view->setLogger( $logger ); |
|
140 | - $view->log( "Rehydrated", LogLevel::DEBUG ); |
|
139 | + $view->setLogger($logger); |
|
140 | + $view->log("Rehydrated", LogLevel::DEBUG); |
|
141 | 141 | return $view; |
142 | 142 | } |
143 | 143 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * @throws \Exception |
162 | 162 | * @return Response |
163 | 163 | */ |
164 | - public function render( $execMethodName = null, array $execArgs = null ) |
|
164 | + public function render($execMethodName = null, array $execArgs = null) |
|
165 | 165 | { |
166 | 166 | $this->state->validate(); |
167 | 167 | $this->initTemplate(); |
@@ -169,13 +169,13 @@ discard block |
||
169 | 169 | // If we're called with an 'exec' then run it instead of rendering the whole tree. |
170 | 170 | // It may still render the whole tree or it may just render a portion or just return JSON |
171 | 171 | if ($execMethodName) { // Used to test for null but it could easily be an empty string |
172 | - $this->log( "Rendering with exec: {$execMethodName}, args:".var_export($execArgs, true ), LogLevel::DEBUG ); |
|
173 | - $out = $this->execMethod( $execMethodName, $execArgs ); |
|
172 | + $this->log("Rendering with exec: {$execMethodName}, args:" . var_export($execArgs, true), LogLevel::DEBUG); |
|
173 | + $out = $this->execMethod($execMethodName, $execArgs); |
|
174 | 174 | }else { |
175 | - $this->log( "Rendering without exec", LogLevel::DEBUG ); |
|
176 | - $out = $this->template->render( $this->state, $this->props ); |
|
177 | - if (!( $out instanceof Response )) { |
|
178 | - throw new \Exception( get_class( $this->template ) . " returned invalid response. Should have been an instance of ViewComponentResponse" ); |
|
175 | + $this->log("Rendering without exec", LogLevel::DEBUG); |
|
176 | + $out = $this->template->render($this->state, $this->props); |
|
177 | + if (!($out instanceof Response)) { |
|
178 | + throw new \Exception(get_class($this->template) . " returned invalid response. Should have been an instance of ViewComponentResponse"); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | return $out; |
@@ -189,26 +189,26 @@ discard block |
||
189 | 189 | * @throws \Exception |
190 | 190 | * @return Response |
191 | 191 | */ |
192 | - protected function execMethod( $methodName, array $args = null ) |
|
192 | + protected function execMethod($methodName, array $args = null) |
|
193 | 193 | { |
194 | - if (!is_array( $methodName )) { |
|
195 | - $methodName = explode( '.', $methodName ); |
|
194 | + if (!is_array($methodName)) { |
|
195 | + $methodName = explode('.', $methodName); |
|
196 | 196 | } |
197 | - if (count( $methodName ) == 1) { |
|
197 | + if (count($methodName) == 1) { |
|
198 | 198 | $methodName = $methodName[ 0 ] . 'Handler'; |
199 | - $out = $this->$methodName( $args ); |
|
199 | + $out = $this->$methodName($args); |
|
200 | 200 | }else { |
201 | - $childName = array_shift( $methodName ); |
|
201 | + $childName = array_shift($methodName); |
|
202 | 202 | $child = $this->childComponents[ $childName ]; |
203 | 203 | if ($child instanceof AbstractViewComponent) { |
204 | - $out = $child->execMethod( $methodName, $args ); |
|
204 | + $out = $child->execMethod($methodName, $args); |
|
205 | 205 | }else { |
206 | - throw new \Exception( implode( ".", $methodName ) . " is not a valid method." ); |
|
206 | + throw new \Exception(implode(".", $methodName) . " is not a valid method."); |
|
207 | 207 | } |
208 | 208 | } |
209 | - if (!( $out instanceof Response )) { |
|
210 | - $nameStr = is_array( $methodName )?implode( ".", $methodName ):$methodName; |
|
211 | - throw new \Exception( $nameStr . " returned invalid response. Should have been an instance of ViewComponentResponse" ); |
|
209 | + if (!($out instanceof Response)) { |
|
210 | + $nameStr = is_array($methodName) ? implode(".", $methodName) : $methodName; |
|
211 | + throw new \Exception($nameStr . " returned invalid response. Should have been an instance of ViewComponentResponse"); |
|
212 | 212 | } |
213 | 213 | return $out; |
214 | 214 | } |
@@ -217,10 +217,10 @@ discard block |
||
217 | 217 | * @param $execMethod |
218 | 218 | * @return string |
219 | 219 | */ |
220 | - public function getExecPath( $execMethod ) |
|
220 | + public function getExecPath($execMethod) |
|
221 | 221 | { |
222 | 222 | $path = $this->getPath(); |
223 | - return ( $path === null?$execMethod:$path . '.' . $execMethod ); |
|
223 | + return ($path === null ? $execMethod : $path . '.' . $execMethod); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | /** |
236 | 236 | * @param $string |
237 | 237 | */ |
238 | - protected function setFlashMessage( $string ) |
|
238 | + protected function setFlashMessage($string) |
|
239 | 239 | { |
240 | 240 | $this->flashMessage = $string; |
241 | 241 | } |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | /** |
244 | 244 | * @param $string |
245 | 245 | */ |
246 | - protected function setFlashError( $string ) |
|
246 | + protected function setFlashError($string) |
|
247 | 247 | { |
248 | 248 | $this->flashError = $string; |
249 | 249 | } |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | if (null === $this->parent) { |
286 | 286 | return null; |
287 | 287 | } |
288 | - if (null !== ( $pPath = $this->parent->getPath() )) { |
|
288 | + if (null !== ($pPath = $this->parent->getPath())) { |
|
289 | 289 | return $pPath . '.' . $this->handle; |
290 | 290 | }else { |
291 | 291 | return $this->handle; |
@@ -301,20 +301,20 @@ discard block |
||
301 | 301 | * @return AbstractViewComponent |
302 | 302 | * @throws \Exception |
303 | 303 | */ |
304 | - protected function addOrUpdateChild( $handle, $type, array $props = [ ] ) |
|
304 | + protected function addOrUpdateChild($handle, $type, array $props = [ ]) |
|
305 | 305 | { |
306 | - $this->log( "Adding/updating child '{$handle}' of type {$type}", LogLevel::DEBUG ); |
|
307 | - if (!isset( $this->childComponents[ $handle ] )) { |
|
308 | - if( ! class_exists( $type ) ){ |
|
309 | - throw new \Exception( "Class '{$type}' for sub-component does not exist." ); |
|
306 | + $this->log("Adding/updating child '{$handle}' of type {$type}", LogLevel::DEBUG); |
|
307 | + if (!isset($this->childComponents[ $handle ])) { |
|
308 | + if (!class_exists($type)) { |
|
309 | + throw new \Exception("Class '{$type}' for sub-component does not exist."); |
|
310 | 310 | } |
311 | - $child = new $type( $handle, $this, $this->exec, $this->logger ); |
|
311 | + $child = new $type($handle, $this, $this->exec, $this->logger); |
|
312 | 312 | $this->childComponents[ $handle ] = $child; |
313 | 313 | }else { |
314 | 314 | // exec, di and logger are set recursively in rehydrate() |
315 | 315 | $child = $this->childComponents[ $handle ]; |
316 | 316 | } |
317 | - $child->updateProps( $props ); |
|
317 | + $child->updateProps($props); |
|
318 | 318 | $child->updateState(); |
319 | 319 | } |
320 | 320 | |
@@ -325,12 +325,12 @@ discard block |
||
325 | 325 | * @return Response |
326 | 326 | * @throws \Exception |
327 | 327 | */ |
328 | - public function renderChild( $handle ) |
|
328 | + public function renderChild($handle) |
|
329 | 329 | { |
330 | 330 | if (!$this->childComponents[ $handle ]) { |
331 | 331 | $message = "Attempted to render nonexistent child component with handle '{$handle}'"; |
332 | - $this->log( $message, LogLevel::CRITICAL ); |
|
333 | - throw new \Exception( $message ); |
|
332 | + $this->log($message, LogLevel::CRITICAL); |
|
333 | + throw new \Exception($message); |
|
334 | 334 | } |
335 | 335 | return $this->childComponents[ $handle ]->render()->content; |
336 | 336 | } |
@@ -378,79 +378,79 @@ discard block |
||
378 | 378 | * @param array $inputs |
379 | 379 | * @throws \Exception |
380 | 380 | */ |
381 | - protected function testInputs( array $inputSpec, array &$inputs ) |
|
381 | + protected function testInputs(array $inputSpec, array &$inputs) |
|
382 | 382 | { |
383 | 383 | |
384 | 384 | foreach ($inputSpec as $fieldName => $fieldSpec) { |
385 | 385 | // Required field |
386 | - if (( count( $fieldSpec ) < 2 )) { |
|
387 | - if (!isset( $inputs[ $fieldName ] )) { |
|
388 | - $calledFunc = debug_backtrace()[1]['function']; |
|
389 | - $callerFunc = debug_backtrace()[2]['function']; |
|
390 | - $callerClass = debug_backtrace()[2]['class']; |
|
386 | + if ((count($fieldSpec) < 2)) { |
|
387 | + if (!isset($inputs[ $fieldName ])) { |
|
388 | + $calledFunc = debug_backtrace()[ 1 ][ 'function' ]; |
|
389 | + $callerFunc = debug_backtrace()[ 2 ][ 'function' ]; |
|
390 | + $callerClass = debug_backtrace()[ 2 ][ 'class' ]; |
|
391 | 391 | $parentText = ''; |
392 | - if( $this->parent !== null ){ |
|
393 | - $parentText = " (parent component is ".get_class($this->parent).")"; |
|
392 | + if ($this->parent !== null) { |
|
393 | + $parentText = " (parent component is " . get_class($this->parent) . ")"; |
|
394 | 394 | } |
395 | - throw new \Exception( $fieldName . " is a required field for " . get_class( $this )."::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}" ); |
|
395 | + throw new \Exception($fieldName . " is a required field for " . get_class($this) . "::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}"); |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | // Set default is unset |
399 | - if (!isset( $inputs[ $fieldName ] )) { |
|
399 | + if (!isset($inputs[ $fieldName ])) { |
|
400 | 400 | $inputs[ $fieldName ] = $fieldSpec[ 1 ]; |
401 | 401 | } |
402 | 402 | // Check type |
403 | 403 | // Any type allowed, continue |
404 | - if (!isset( $fieldSpec[ 0 ] ) || $fieldSpec[ 0 ] === null) { |
|
404 | + if (!isset($fieldSpec[ 0 ]) || $fieldSpec[ 0 ] === null) { |
|
405 | 405 | continue; |
406 | 406 | } |
407 | 407 | $requiredType = $fieldSpec[ 0 ]; |
408 | 408 | $input = $inputs[ $fieldName ]; |
409 | 409 | // Specific type required |
410 | 410 | // Null is allowed |
411 | - if (!is_null( $input )) { |
|
411 | + if (!is_null($input)) { |
|
412 | 412 | switch ($requiredType) { |
413 | 413 | case "boolean": |
414 | 414 | case "bool": |
415 | - $failed = !is_bool( $input ); |
|
415 | + $failed = !is_bool($input); |
|
416 | 416 | break; |
417 | 417 | case "integer": |
418 | 418 | case "int": |
419 | - $failed = !is_int( $input+0 ); |
|
419 | + $failed = !is_int($input + 0); |
|
420 | 420 | break; |
421 | 421 | case "double": |
422 | - $failed = !is_double( $input+0 ); |
|
422 | + $failed = !is_double($input + 0); |
|
423 | 423 | break; |
424 | 424 | case "float": |
425 | - $failed = !is_float( $input+0 ); |
|
425 | + $failed = !is_float($input + 0); |
|
426 | 426 | break; |
427 | 427 | case "string": |
428 | - $failed = !is_string( $input ); |
|
428 | + $failed = !is_string($input); |
|
429 | 429 | break; |
430 | 430 | case "array": |
431 | - $failed = !is_array( $input ); |
|
431 | + $failed = !is_array($input); |
|
432 | 432 | break; |
433 | 433 | case "object": |
434 | - $failed = !is_object( $input ); |
|
434 | + $failed = !is_object($input); |
|
435 | 435 | break; |
436 | 436 | case "resource": |
437 | - $failed = !is_resource( $input ); |
|
437 | + $failed = !is_resource($input); |
|
438 | 438 | break; |
439 | 439 | case "callable": |
440 | - $failed = !is_callable( $input ); |
|
440 | + $failed = !is_callable($input); |
|
441 | 441 | break; |
442 | 442 | default: |
443 | - $failed = !( $input instanceof $requiredType ); |
|
443 | + $failed = !($input instanceof $requiredType); |
|
444 | 444 | } |
445 | 445 | if ($failed) { |
446 | - $calledFunc = debug_backtrace()[1]['function']; |
|
447 | - $callerFunc = debug_backtrace()[2]['function']; |
|
448 | - $callerClass = debug_backtrace()[2]['class']; |
|
446 | + $calledFunc = debug_backtrace()[ 1 ][ 'function' ]; |
|
447 | + $callerFunc = debug_backtrace()[ 2 ][ 'function' ]; |
|
448 | + $callerClass = debug_backtrace()[ 2 ][ 'class' ]; |
|
449 | 449 | $parentText = ''; |
450 | - if( $this->parent !== null ){ |
|
451 | - $parentText = " (parent component is ".get_class($this->parent).")"; |
|
450 | + if ($this->parent !== null) { |
|
451 | + $parentText = " (parent component is " . get_class($this->parent) . ")"; |
|
452 | 452 | } |
453 | - throw new \Exception( $fieldName . " should be of type " . $requiredType . "in " . get_class( $this )."::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}" ); |
|
453 | + throw new \Exception($fieldName . " should be of type " . $requiredType . "in " . get_class($this) . "::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}"); |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | } |
@@ -461,9 +461,9 @@ discard block |
||
461 | 461 | * |
462 | 462 | * @var array $props |
463 | 463 | */ |
464 | - public function updateView( $props ) |
|
464 | + public function updateView($props) |
|
465 | 465 | { |
466 | - $this->updateProps( $props ); |
|
466 | + $this->updateProps($props); |
|
467 | 467 | $this->updateState(); |
468 | 468 | } |
469 | 469 | |
@@ -472,21 +472,21 @@ discard block |
||
472 | 472 | * |
473 | 473 | * @var array $props |
474 | 474 | */ |
475 | - protected function updateProps( $props ) |
|
475 | + protected function updateProps($props) |
|
476 | 476 | { |
477 | - $this->log( "Storing new props: " . var_export( $props, true ), LogLevel::DEBUG ); |
|
477 | + $this->log("Storing new props: " . var_export($props, true), LogLevel::DEBUG); |
|
478 | 478 | $this->props = $props; |
479 | 479 | } |
480 | 480 | |
481 | 481 | /** |
482 | 482 | * @param ExecHelper $execHelper |
483 | 483 | */ |
484 | - private function setExec( ExecHelper $execHelper ) |
|
484 | + private function setExec(ExecHelper $execHelper) |
|
485 | 485 | { |
486 | 486 | $this->exec = clone $execHelper; |
487 | - $this->exec->setComponent( $this ); |
|
488 | - foreach( $this->childComponents as $child ){ |
|
489 | - $child->setExec( $execHelper ); |
|
487 | + $this->exec->setComponent($this); |
|
488 | + foreach ($this->childComponents as $child) { |
|
489 | + $child->setExec($execHelper); |
|
490 | 490 | } |
491 | 491 | } |
492 | 492 | |
@@ -500,9 +500,9 @@ discard block |
||
500 | 500 | // it manually and you still get the advantage that the deps |
501 | 501 | // are specified in the optional injectDependencies() method's |
502 | 502 | // signature |
503 | - $this->log( "Dependency injection...", LogLevel::DEBUG ); |
|
504 | - DependencyInjector::instance()->injectIntoMethod( $this ); |
|
505 | - foreach( $this->childComponents as $child ){ |
|
503 | + $this->log("Dependency injection...", LogLevel::DEBUG); |
|
504 | + DependencyInjector::instance()->injectIntoMethod($this); |
|
505 | + foreach ($this->childComponents as $child) { |
|
506 | 506 | $child->handleDependencyInjection(); |
507 | 507 | } |
508 | 508 | } |
@@ -510,13 +510,13 @@ discard block |
||
510 | 510 | /** |
511 | 511 | * @param LoggerInterface $logger |
512 | 512 | */ |
513 | - private function setLogger( LoggerInterface $logger = null ) |
|
513 | + private function setLogger(LoggerInterface $logger = null) |
|
514 | 514 | { |
515 | - if( null !== $logger ){ |
|
515 | + if (null !== $logger) { |
|
516 | 516 | $this->logger = $logger; |
517 | 517 | /** @var AbstractViewComponent $child */ |
518 | - foreach( $this->childComponents as $child ){ |
|
519 | - $child->setLogger( $logger ); |
|
518 | + foreach ($this->childComponents as $child) { |
|
519 | + $child->setLogger($logger); |
|
520 | 520 | } |
521 | 521 | } |
522 | 522 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | protected $component; |
20 | 20 | |
21 | - public function setComponent( AbstractViewComponent $component ) |
|
21 | + public function setComponent(AbstractViewComponent $component) |
|
22 | 22 | { |
23 | 23 | $this->component = $component; |
24 | 24 | } |
@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | * @param bool $onlyComponentOutput |
31 | 31 | * @return string A URL or URI |
32 | 32 | */ |
33 | - public function url( $execMethod, $args = [ ], $onlyComponentOutput = false ) // $onlyComponentOutput Not used in this implementation but necessary for subclasses |
|
33 | + public function url($execMethod, $args = [ ], $onlyComponentOutput = false) // $onlyComponentOutput Not used in this implementation but necessary for subclasses |
|
34 | 34 | { |
35 | 35 | // $onlyComponentOutput is not used in this implementation but may be by sub-classes |
36 | - $args[ 'exec' ] = $this->component->getExecPath( $execMethod ); |
|
37 | - $qs = http_build_query( $args ); |
|
36 | + $args[ 'exec' ] = $this->component->getExecPath($execMethod); |
|
37 | + $qs = http_build_query($args); |
|
38 | 38 | return "?{$qs}"; |
39 | 39 | } |
40 | 40 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | } |
67 | 67 | return <<<EOS |
68 | 68 | <form method="{$method}" action=""{$formID}{$onSubmit}> |
69 | - <input type="hidden" name="exec" value="{$this->component->getExecPath( $execMethod )}"> |
|
69 | + <input type="hidden" name="exec" value="{$this->component->getExecPath($execMethod)}"> |
|
70 | 70 | {$formBody} |
71 | 71 | </form> |
72 | 72 | EOS; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | function callStatic($class, $function, $args = array()) |
83 | 83 | { |
84 | 84 | if (class_exists($class) && method_exists($class, $function)) { |
85 | - return call_user_func_array( array( $class, $function ), $args ); |
|
85 | + return call_user_func_array(array($class, $function), $args); |
|
86 | 86 | } |
87 | 87 | return null; |
88 | 88 | } |
@@ -96,14 +96,14 @@ discard block |
||
96 | 96 | * @param array $anchorAttrs |
97 | 97 | * @return string |
98 | 98 | */ |
99 | - public function replaceElementUsingLink( $execMethod, $args = [ ], $targetDiv, $linkText, $anchorAttrs = [ ] ) |
|
99 | + public function replaceElementUsingLink($execMethod, $args = [ ], $targetDiv, $linkText, $anchorAttrs = [ ]) |
|
100 | 100 | { |
101 | - $url = $this->url( $execMethod, $args, true ); |
|
101 | + $url = $this->url($execMethod, $args, true); |
|
102 | 102 | $attrs = [ ]; |
103 | 103 | foreach ($anchorAttrs as $k => $v) { |
104 | 104 | $attrs[ ] = "{$k}='{$v}'"; |
105 | 105 | } |
106 | - $attrsStr = implode( ' ', $attrs ); |
|
106 | + $attrsStr = implode(' ', $attrs); |
|
107 | 107 | return <<<EOS |
108 | 108 | <script type="application/javascript"> |
109 | 109 | if( typeof(execLink) != "function" ){ |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | * @param $formID |
136 | 136 | * @return string |
137 | 137 | */ |
138 | - public function replaceElementUsingForm( $execMethod, $method, $formBody, $targetDiv, $formID ) |
|
138 | + public function replaceElementUsingForm($execMethod, $method, $formBody, $targetDiv, $formID) |
|
139 | 139 | { |
140 | 140 | return <<<EOS |
141 | - {$this->wrapForm( $execMethod, $method, $formBody, true, $formID, |
|
142 | - "execForm( this, \"{$targetDiv}\" ); return false;" )} |
|
141 | + {$this->wrapForm($execMethod, $method, $formBody, true, $formID, |
|
142 | + "execForm( this, \"{$targetDiv}\" ); return false;")} |
|
143 | 143 | <script type="application/javascript"> |
144 | 144 | if( typeof(execForm) != "function" ){ |
145 | 145 | var execForm = function( form, targetDiv ){ |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Class AbstractTemplate |
25 | 25 | * @package PatternSeek\ComponentView |
26 | 26 | */ |
27 | -abstract class AbstractTemplate{ |
|
27 | +abstract class AbstractTemplate { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * @var AbstractViewComponent |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * @param AbstractViewComponent $component |
36 | 36 | */ |
37 | - public function __construct( AbstractViewComponent $component ){ |
|
37 | + public function __construct(AbstractViewComponent $component) { |
|
38 | 38 | $this->component = $component; |
39 | 39 | } |
40 | 40 | |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | * @param array $props |
45 | 45 | * @return string |
46 | 46 | */ |
47 | - public function render( ViewState $state, array $props = [] ) |
|
47 | + public function render(ViewState $state, array $props = [ ]) |
|
48 | 48 | { |
49 | - return $this->doRender( $state, $props ); |
|
49 | + return $this->doRender($state, $props); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -54,6 +54,6 @@ discard block |
||
54 | 54 | * @param array $props |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - abstract protected function doRender( ViewState $state, array $props = [] ); |
|
57 | + abstract protected function doRender(ViewState $state, array $props = [ ]); |
|
58 | 58 | |
59 | 59 | } |
@@ -100,7 +100,7 @@ |
||
100 | 100 | |
101 | 101 | if (class_exists( "Puli\\TwigExtension\\PuliExtension" ) && null !== $this->repo) { |
102 | 102 | $loader = new \Twig_Loader_Chain( [ new PuliTemplateLoader( $this->repo ), new Twig_Loader_String() ] ); |
103 | - }else { |
|
103 | + } else { |
|
104 | 104 | $loader = new Twig_Loader_String(); |
105 | 105 | } |
106 | 106 | return $loader; |
@@ -57,15 +57,15 @@ discard block |
||
57 | 57 | $templatePath = null, |
58 | 58 | $templateString = null, |
59 | 59 | ResourceRepository $repo = null |
60 | - ){ |
|
61 | - parent::__construct( $component ); |
|
60 | + ) { |
|
61 | + parent::__construct($component); |
|
62 | 62 | $this->templatePath = $templatePath; |
63 | 63 | $this->templateString = $templateString; |
64 | 64 | // Optional Puli repo |
65 | 65 | $this->repo = $repo; |
66 | 66 | |
67 | 67 | Twig_Autoloader::register(); |
68 | - $this->initTwig( $this->getLoader() ); |
|
68 | + $this->initTwig($this->getLoader()); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -73,15 +73,15 @@ discard block |
||
73 | 73 | * @param array $props |
74 | 74 | * @return string |
75 | 75 | */ |
76 | - protected function doRender( ViewState $state, array $props = [] ) |
|
76 | + protected function doRender(ViewState $state, array $props = [ ]) |
|
77 | 77 | { |
78 | 78 | // If puli plugin is available then add it. |
79 | - if (class_exists( "Puli\\TwigExtension\\PuliExtension" ) && null !== $this->repo) { |
|
80 | - $this->twig->addExtension( new PuliExtension( $this->repo ) ); |
|
79 | + if (class_exists("Puli\\TwigExtension\\PuliExtension") && null !== $this->repo) { |
|
80 | + $this->twig->addExtension(new PuliExtension($this->repo)); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | $rendered = $this->twig->render( |
84 | - $this->templateString?$this->templateString:$this->templatePath, |
|
84 | + $this->templateString ? $this->templateString : $this->templatePath, |
|
85 | 85 | [ |
86 | 86 | 'state' => $state, |
87 | 87 | 'props' => $props, |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | 'parent' => $this->component->getParent(), |
90 | 90 | 'exec' => $this->component->exec |
91 | 91 | ] ); |
92 | - return new Response( "text/html", $rendered ); |
|
92 | + return new Response("text/html", $rendered); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | protected function getLoader() |
99 | 99 | { |
100 | 100 | |
101 | - if (class_exists( "Puli\\TwigExtension\\PuliExtension" ) && null !== $this->repo) { |
|
102 | - $loader = new \Twig_Loader_Chain( [ new PuliTemplateLoader( $this->repo ), new Twig_Loader_String() ] ); |
|
101 | + if (class_exists("Puli\\TwigExtension\\PuliExtension") && null !== $this->repo) { |
|
102 | + $loader = new \Twig_Loader_Chain([ new PuliTemplateLoader($this->repo), new Twig_Loader_String() ]); |
|
103 | 103 | }else { |
104 | 104 | $loader = new Twig_Loader_String(); |
105 | 105 | } |
@@ -109,13 +109,13 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * @param $loader |
111 | 111 | */ |
112 | - protected function initTwig( $loader ) |
|
112 | + protected function initTwig($loader) |
|
113 | 113 | { |
114 | 114 | $config = [ 'autoescape' => false ]; |
115 | - if (defined( "TWIG_CACHE_DIR" )) { |
|
115 | + if (defined("TWIG_CACHE_DIR")) { |
|
116 | 116 | $config[ 'cache' ] = TWIG_CACHE_DIR; |
117 | 117 | } |
118 | - $this->twig = new Twig_Environment( $loader, $config ); |
|
118 | + $this->twig = new Twig_Environment($loader, $config); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | } |
@@ -40,7 +40,7 @@ |
||
40 | 40 | if( null == $responseCode ){ |
41 | 41 | if( $type == "redirect" ){ |
42 | 42 | $responseCode = 301; |
43 | - }else{ |
|
43 | + } else{ |
|
44 | 44 | $responseCode = 200; |
45 | 45 | } |
46 | 46 | } |
@@ -40,16 +40,16 @@ |
||
40 | 40 | * @param string $content |
41 | 41 | * @param int|null $responseCode |
42 | 42 | */ |
43 | - function __construct( $type, $content, $responseCode = null ) |
|
43 | + function __construct($type, $content, $responseCode = null) |
|
44 | 44 | { |
45 | 45 | $this->type = $type; |
46 | 46 | $this->content = $content; |
47 | 47 | |
48 | 48 | // Response code defaults |
49 | 49 | if (null === $responseCode) { |
50 | - if( $type == "redirect" ){ |
|
50 | + if ($type == "redirect") { |
|
51 | 51 | $responseCode = 302; |
52 | - }else{ |
|
52 | + }else { |
|
53 | 53 | $responseCode = 200; |
54 | 54 | } |
55 | 55 | } |