@@ -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 ) |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | AbstractViewComponent $parent = null, |
| 90 | 90 | ExecHelper $execHelper = null, |
| 91 | 91 | LoggerInterface $logger = null |
| 92 | - ){ |
|
| 92 | + ) { |
|
| 93 | 93 | // Null means we are root |
| 94 | 94 | $this->parent = $parent; |
| 95 | 95 | |
@@ -99,11 +99,11 @@ discard block |
||
| 99 | 99 | if (null === $execHelper) { |
| 100 | 100 | $execHelper = new ExecHelper(); |
| 101 | 101 | } |
| 102 | - $this->setExec( $execHelper ); |
|
| 102 | + $this->setExec($execHelper); |
|
| 103 | 103 | |
| 104 | 104 | $this->handleDependencyInjection(); |
| 105 | 105 | |
| 106 | - $this->setLogger( $logger ); |
|
| 106 | + $this->setLogger($logger); |
|
| 107 | 107 | |
| 108 | 108 | // Set up the state container |
| 109 | 109 | $this->initState(); |
@@ -113,11 +113,11 @@ discard block |
||
| 113 | 113 | * @param string $message |
| 114 | 114 | * @param string $level A constant from LogLevel |
| 115 | 115 | */ |
| 116 | - protected function log( $message, $level ){ |
|
| 117 | - if( isset( $this->logger ) ){ |
|
| 118 | - $class = get_class( $this ); |
|
| 116 | + protected function log($message, $level) { |
|
| 117 | + if (isset($this->logger)) { |
|
| 118 | + $class = get_class($this); |
|
| 119 | 119 | $message = "[{$class}] {$message}"; |
| 120 | - $this->logger->log( $level, $message ); |
|
| 120 | + $this->logger->log($level, $message); |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | * User this to serialise ViewComponents as extra steps may be added later. |
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | - public function dehydrate(){ |
|
| 129 | - $this->log( "Dehydrating", LogLevel::DEBUG ); |
|
| 130 | - return serialize( $this ); |
|
| 128 | + public function dehydrate() { |
|
| 129 | + $this->log("Dehydrating", LogLevel::DEBUG); |
|
| 130 | + return serialize($this); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -138,13 +138,13 @@ discard block |
||
| 138 | 138 | * @return AbstractViewComponent |
| 139 | 139 | */ |
| 140 | 140 | |
| 141 | - public static function rehydrate( $serialised, ExecHelper $execHelper, LoggerInterface $logger = null ){ |
|
| 141 | + public static function rehydrate($serialised, ExecHelper $execHelper, LoggerInterface $logger = null) { |
|
| 142 | 142 | /** @var AbstractViewComponent $view */ |
| 143 | - $view = unserialize( $serialised ); |
|
| 144 | - $view->setExec( $execHelper ); |
|
| 143 | + $view = unserialize($serialised); |
|
| 144 | + $view->setExec($execHelper); |
|
| 145 | 145 | $view->handleDependencyInjection(); |
| 146 | - $view->setLogger( $logger ); |
|
| 147 | - $view->log( "Rehydrated", LogLevel::DEBUG ); |
|
| 146 | + $view->setLogger($logger); |
|
| 147 | + $view->log("Rehydrated", LogLevel::DEBUG); |
|
| 148 | 148 | return $view; |
| 149 | 149 | } |
| 150 | 150 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * @throws \Exception |
| 169 | 169 | * @return Response |
| 170 | 170 | */ |
| 171 | - public function render( $execMethodName = null, array $execArgs = null ) |
|
| 171 | + public function render($execMethodName = null, array $execArgs = null) |
|
| 172 | 172 | { |
| 173 | 173 | $this->state->validate(); |
| 174 | 174 | |
@@ -183,13 +183,13 @@ discard block |
||
| 183 | 183 | // If we're called with an 'exec' then run it instead of rendering the whole tree. |
| 184 | 184 | // It may still render the whole tree or it may just render a portion or just return JSON |
| 185 | 185 | if ($execMethodName) { // Used to test for null but it could easily be an empty string |
| 186 | - $this->log( "Rendering with exec: {$execMethodName}, args:".var_export($execArgs, true ), LogLevel::DEBUG ); |
|
| 187 | - $out = $this->execMethod( $execMethodName, $execArgs ); |
|
| 186 | + $this->log("Rendering with exec: {$execMethodName}, args:".var_export($execArgs, true), LogLevel::DEBUG); |
|
| 187 | + $out = $this->execMethod($execMethodName, $execArgs); |
|
| 188 | 188 | }else { |
| 189 | - $this->log( "Rendering without exec", LogLevel::DEBUG ); |
|
| 190 | - $out = $this->template->render( $this->state, $this->props ); |
|
| 191 | - if (!( $out instanceof Response )) { |
|
| 192 | - throw new \Exception( get_class( $this->template ) . " returned invalid response. Should have been an instance of ViewComponentResponse" ); |
|
| 189 | + $this->log("Rendering without exec", LogLevel::DEBUG); |
|
| 190 | + $out = $this->template->render($this->state, $this->props); |
|
| 191 | + if (!($out instanceof Response)) { |
|
| 192 | + throw new \Exception(get_class($this->template)." returned invalid response. Should have been an instance of ViewComponentResponse"); |
|
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | return $out; |
@@ -203,26 +203,26 @@ discard block |
||
| 203 | 203 | * @throws \Exception |
| 204 | 204 | * @return Response |
| 205 | 205 | */ |
| 206 | - protected function execMethod( $methodName, array $args = null ) |
|
| 206 | + protected function execMethod($methodName, array $args = null) |
|
| 207 | 207 | { |
| 208 | - if (!is_array( $methodName )) { |
|
| 209 | - $methodName = explode( '.', $methodName ); |
|
| 208 | + if (!is_array($methodName)) { |
|
| 209 | + $methodName = explode('.', $methodName); |
|
| 210 | 210 | } |
| 211 | - if (count( $methodName ) == 1) { |
|
| 212 | - $methodName = $methodName[ 0 ] . 'Handler'; |
|
| 213 | - $out = $this->$methodName( $args ); |
|
| 211 | + if (count($methodName) == 1) { |
|
| 212 | + $methodName = $methodName[ 0 ].'Handler'; |
|
| 213 | + $out = $this->$methodName($args); |
|
| 214 | 214 | }else { |
| 215 | - $childName = array_shift( $methodName ); |
|
| 215 | + $childName = array_shift($methodName); |
|
| 216 | 216 | $child = $this->childComponents[ $childName ]; |
| 217 | 217 | if ($child instanceof AbstractViewComponent) { |
| 218 | - $out = $child->execMethod( $methodName, $args ); |
|
| 218 | + $out = $child->execMethod($methodName, $args); |
|
| 219 | 219 | }else { |
| 220 | - throw new \Exception( implode( ".", $methodName ) . " is not a valid method." ); |
|
| 220 | + throw new \Exception(implode(".", $methodName)." is not a valid method."); |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | - if (!( $out instanceof Response )) { |
|
| 224 | - $nameStr = is_array( $methodName )?implode( ".", $methodName ):$methodName; |
|
| 225 | - throw new \Exception( $nameStr . " returned invalid response. Should have been an instance of ViewComponentResponse" ); |
|
| 223 | + if (!($out instanceof Response)) { |
|
| 224 | + $nameStr = is_array($methodName) ? implode(".", $methodName) : $methodName; |
|
| 225 | + throw new \Exception($nameStr." returned invalid response. Should have been an instance of ViewComponentResponse"); |
|
| 226 | 226 | } |
| 227 | 227 | return $out; |
| 228 | 228 | } |
@@ -231,10 +231,10 @@ discard block |
||
| 231 | 231 | * @param $execMethod |
| 232 | 232 | * @return string |
| 233 | 233 | */ |
| 234 | - public function getExecPath( $execMethod ) |
|
| 234 | + public function getExecPath($execMethod) |
|
| 235 | 235 | { |
| 236 | 236 | $path = $this->getPath(); |
| 237 | - return ( $path === null?$execMethod:$path . '.' . $execMethod ); |
|
| 237 | + return ($path === null ? $execMethod : $path.'.'.$execMethod); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | /** |
| 250 | 250 | * @param $string |
| 251 | 251 | */ |
| 252 | - protected function setFlashMessage( $string ) |
|
| 252 | + protected function setFlashMessage($string) |
|
| 253 | 253 | { |
| 254 | 254 | $this->flashMessage = $string; |
| 255 | 255 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | /** |
| 258 | 258 | * @param $string |
| 259 | 259 | */ |
| 260 | - protected function setFlashError( $string ) |
|
| 260 | + protected function setFlashError($string) |
|
| 261 | 261 | { |
| 262 | 262 | $this->flashError = $string; |
| 263 | 263 | } |
@@ -299,8 +299,8 @@ discard block |
||
| 299 | 299 | if (null === $this->parent) { |
| 300 | 300 | return null; |
| 301 | 301 | } |
| 302 | - if (null !== ( $pPath = $this->parent->getPath() )) { |
|
| 303 | - return $pPath . '.' . $this->handle; |
|
| 302 | + if (null !== ($pPath = $this->parent->getPath())) { |
|
| 303 | + return $pPath.'.'.$this->handle; |
|
| 304 | 304 | }else { |
| 305 | 305 | return $this->handle; |
| 306 | 306 | } |
@@ -315,20 +315,20 @@ discard block |
||
| 315 | 315 | * @return AbstractViewComponent |
| 316 | 316 | * @throws \Exception |
| 317 | 317 | */ |
| 318 | - protected function addOrUpdateChild( $handle, $type, array $props = [ ] ) |
|
| 318 | + protected function addOrUpdateChild($handle, $type, array $props = [ ]) |
|
| 319 | 319 | { |
| 320 | - $this->log( "Adding/updating child '{$handle}' of type {$type}", LogLevel::DEBUG ); |
|
| 321 | - if (!isset( $this->childComponents[ $handle ] )) { |
|
| 322 | - if( ! class_exists( $type ) ){ |
|
| 323 | - throw new \Exception( "Class '{$type}' for sub-component does not exist." ); |
|
| 320 | + $this->log("Adding/updating child '{$handle}' of type {$type}", LogLevel::DEBUG); |
|
| 321 | + if (!isset($this->childComponents[ $handle ])) { |
|
| 322 | + if (!class_exists($type)) { |
|
| 323 | + throw new \Exception("Class '{$type}' for sub-component does not exist."); |
|
| 324 | 324 | } |
| 325 | - $child = new $type( $handle, $this, $this->exec, $this->logger ); |
|
| 325 | + $child = new $type($handle, $this, $this->exec, $this->logger); |
|
| 326 | 326 | $this->childComponents[ $handle ] = $child; |
| 327 | 327 | }else { |
| 328 | 328 | // exec, di and logger are set recursively in rehydrate() |
| 329 | 329 | $child = $this->childComponents[ $handle ]; |
| 330 | 330 | } |
| 331 | - $child->updateProps( $props ); |
|
| 331 | + $child->updateProps($props); |
|
| 332 | 332 | $child->updateState(); |
| 333 | 333 | } |
| 334 | 334 | |
@@ -339,12 +339,12 @@ discard block |
||
| 339 | 339 | * @return Response |
| 340 | 340 | * @throws \Exception |
| 341 | 341 | */ |
| 342 | - public function renderChild( $handle ) |
|
| 342 | + public function renderChild($handle) |
|
| 343 | 343 | { |
| 344 | 344 | if (!$this->childComponents[ $handle ]) { |
| 345 | 345 | $message = "Attempted to render nonexistent child component with handle '{$handle}'"; |
| 346 | - $this->log( $message, LogLevel::CRITICAL ); |
|
| 347 | - throw new \Exception( $message ); |
|
| 346 | + $this->log($message, LogLevel::CRITICAL); |
|
| 347 | + throw new \Exception($message); |
|
| 348 | 348 | } |
| 349 | 349 | return $this->childComponents[ $handle ]->render()->content; |
| 350 | 350 | } |
@@ -392,79 +392,79 @@ discard block |
||
| 392 | 392 | * @param array $inputs |
| 393 | 393 | * @throws \Exception |
| 394 | 394 | */ |
| 395 | - protected function testInputs( array $inputSpec, array &$inputs ) |
|
| 395 | + protected function testInputs(array $inputSpec, array &$inputs) |
|
| 396 | 396 | { |
| 397 | 397 | |
| 398 | 398 | foreach ($inputSpec as $fieldName => $fieldSpec) { |
| 399 | 399 | // Required field |
| 400 | - if (( count( $fieldSpec ) < 2 )) { |
|
| 401 | - if (!isset( $inputs[ $fieldName ] )) { |
|
| 402 | - $calledFunc = debug_backtrace()[1]['function']; |
|
| 403 | - $callerFunc = debug_backtrace()[2]['function']; |
|
| 404 | - $callerClass = debug_backtrace()[2]['class']; |
|
| 400 | + if ((count($fieldSpec) < 2)) { |
|
| 401 | + if (!isset($inputs[ $fieldName ])) { |
|
| 402 | + $calledFunc = debug_backtrace()[ 1 ][ 'function' ]; |
|
| 403 | + $callerFunc = debug_backtrace()[ 2 ][ 'function' ]; |
|
| 404 | + $callerClass = debug_backtrace()[ 2 ][ 'class' ]; |
|
| 405 | 405 | $parentText = ''; |
| 406 | - if( $this->parent !== null ){ |
|
| 406 | + if ($this->parent !== null) { |
|
| 407 | 407 | $parentText = " (parent component is ".get_class($this->parent).")"; |
| 408 | 408 | } |
| 409 | - throw new \Exception( $fieldName . " is a required field for " . get_class( $this )."::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}" ); |
|
| 409 | + throw new \Exception($fieldName." is a required field for ".get_class($this)."::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}"); |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | 412 | // Set default is unset |
| 413 | - if (!isset( $inputs[ $fieldName ] )) { |
|
| 413 | + if (!isset($inputs[ $fieldName ])) { |
|
| 414 | 414 | $inputs[ $fieldName ] = $fieldSpec[ 1 ]; |
| 415 | 415 | } |
| 416 | 416 | // Check type |
| 417 | 417 | // Any type allowed, continue |
| 418 | - if (!isset( $fieldSpec[ 0 ] ) || $fieldSpec[ 0 ] === null) { |
|
| 418 | + if (!isset($fieldSpec[ 0 ]) || $fieldSpec[ 0 ] === null) { |
|
| 419 | 419 | continue; |
| 420 | 420 | } |
| 421 | 421 | $requiredType = $fieldSpec[ 0 ]; |
| 422 | 422 | $input = $inputs[ $fieldName ]; |
| 423 | 423 | // Specific type required |
| 424 | 424 | // Null is allowed |
| 425 | - if (!is_null( $input )) { |
|
| 425 | + if (!is_null($input)) { |
|
| 426 | 426 | switch ($requiredType) { |
| 427 | 427 | case "boolean": |
| 428 | 428 | case "bool": |
| 429 | - $failed = !is_bool( $input ); |
|
| 429 | + $failed = !is_bool($input); |
|
| 430 | 430 | break; |
| 431 | 431 | case "integer": |
| 432 | 432 | case "int": |
| 433 | - $failed = !is_int( $input+0 ); |
|
| 433 | + $failed = !is_int($input + 0); |
|
| 434 | 434 | break; |
| 435 | 435 | case "double": |
| 436 | - $failed = !is_double( $input+0 ); |
|
| 436 | + $failed = !is_double($input + 0); |
|
| 437 | 437 | break; |
| 438 | 438 | case "float": |
| 439 | - $failed = !is_float( $input+0 ); |
|
| 439 | + $failed = !is_float($input + 0); |
|
| 440 | 440 | break; |
| 441 | 441 | case "string": |
| 442 | - $failed = !is_string( $input ); |
|
| 442 | + $failed = !is_string($input); |
|
| 443 | 443 | break; |
| 444 | 444 | case "array": |
| 445 | - $failed = !is_array( $input ); |
|
| 445 | + $failed = !is_array($input); |
|
| 446 | 446 | break; |
| 447 | 447 | case "object": |
| 448 | - $failed = !is_object( $input ); |
|
| 448 | + $failed = !is_object($input); |
|
| 449 | 449 | break; |
| 450 | 450 | case "resource": |
| 451 | - $failed = !is_resource( $input ); |
|
| 451 | + $failed = !is_resource($input); |
|
| 452 | 452 | break; |
| 453 | 453 | case "callable": |
| 454 | - $failed = !is_callable( $input ); |
|
| 454 | + $failed = !is_callable($input); |
|
| 455 | 455 | break; |
| 456 | 456 | default: |
| 457 | - $failed = !( $input instanceof $requiredType ); |
|
| 457 | + $failed = !($input instanceof $requiredType); |
|
| 458 | 458 | } |
| 459 | 459 | if ($failed) { |
| 460 | - $calledFunc = debug_backtrace()[1]['function']; |
|
| 461 | - $callerFunc = debug_backtrace()[2]['function']; |
|
| 462 | - $callerClass = debug_backtrace()[2]['class']; |
|
| 460 | + $calledFunc = debug_backtrace()[ 1 ][ 'function' ]; |
|
| 461 | + $callerFunc = debug_backtrace()[ 2 ][ 'function' ]; |
|
| 462 | + $callerClass = debug_backtrace()[ 2 ][ 'class' ]; |
|
| 463 | 463 | $parentText = ''; |
| 464 | - if( $this->parent !== null ){ |
|
| 464 | + if ($this->parent !== null) { |
|
| 465 | 465 | $parentText = " (parent component is ".get_class($this->parent).")"; |
| 466 | 466 | } |
| 467 | - throw new \Exception( $fieldName . " should be of type " . $requiredType . "in " . get_class( $this )."::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}" ); |
|
| 467 | + throw new \Exception($fieldName." should be of type ".$requiredType."in ".get_class($this)."::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}"); |
|
| 468 | 468 | } |
| 469 | 469 | } |
| 470 | 470 | } |
@@ -475,9 +475,9 @@ discard block |
||
| 475 | 475 | * |
| 476 | 476 | * @var array $props |
| 477 | 477 | */ |
| 478 | - public function updateView( $props ) |
|
| 478 | + public function updateView($props) |
|
| 479 | 479 | { |
| 480 | - $this->updateProps( $props ); |
|
| 480 | + $this->updateProps($props); |
|
| 481 | 481 | $this->updateState(); |
| 482 | 482 | } |
| 483 | 483 | |
@@ -486,13 +486,13 @@ discard block |
||
| 486 | 486 | * |
| 487 | 487 | * @var array $props |
| 488 | 488 | */ |
| 489 | - protected function updateProps( $props ) |
|
| 489 | + protected function updateProps($props) |
|
| 490 | 490 | { |
| 491 | - $this->log( "Storing new props: " . var_export( $props, true ), LogLevel::DEBUG ); |
|
| 491 | + $this->log("Storing new props: ".var_export($props, true), LogLevel::DEBUG); |
|
| 492 | 492 | $this->props = $props; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - protected function forceResponse( Response $response ) |
|
| 495 | + protected function forceResponse(Response $response) |
|
| 496 | 496 | { |
| 497 | 497 | $this->forceResponse = $response; |
| 498 | 498 | } |
@@ -500,12 +500,12 @@ discard block |
||
| 500 | 500 | /** |
| 501 | 501 | * @param ExecHelper $execHelper |
| 502 | 502 | */ |
| 503 | - private function setExec( ExecHelper $execHelper ) |
|
| 503 | + private function setExec(ExecHelper $execHelper) |
|
| 504 | 504 | { |
| 505 | 505 | $this->exec = clone $execHelper; |
| 506 | - $this->exec->setComponent( $this ); |
|
| 507 | - foreach( $this->childComponents as $child ){ |
|
| 508 | - $child->setExec( $execHelper ); |
|
| 506 | + $this->exec->setComponent($this); |
|
| 507 | + foreach ($this->childComponents as $child) { |
|
| 508 | + $child->setExec($execHelper); |
|
| 509 | 509 | } |
| 510 | 510 | } |
| 511 | 511 | |
@@ -519,9 +519,9 @@ discard block |
||
| 519 | 519 | // it manually and you still get the advantage that the deps |
| 520 | 520 | // are specified in the optional injectDependencies() method's |
| 521 | 521 | // signature |
| 522 | - $this->log( "Dependency injection...", LogLevel::DEBUG ); |
|
| 523 | - DependencyInjector::instance()->injectIntoMethod( $this ); |
|
| 524 | - foreach( $this->childComponents as $child ){ |
|
| 522 | + $this->log("Dependency injection...", LogLevel::DEBUG); |
|
| 523 | + DependencyInjector::instance()->injectIntoMethod($this); |
|
| 524 | + foreach ($this->childComponents as $child) { |
|
| 525 | 525 | $child->handleDependencyInjection(); |
| 526 | 526 | } |
| 527 | 527 | } |
@@ -529,13 +529,13 @@ discard block |
||
| 529 | 529 | /** |
| 530 | 530 | * @param LoggerInterface $logger |
| 531 | 531 | */ |
| 532 | - private function setLogger( LoggerInterface $logger = null ) |
|
| 532 | + private function setLogger(LoggerInterface $logger = null) |
|
| 533 | 533 | { |
| 534 | - if( null !== $logger ){ |
|
| 534 | + if (null !== $logger) { |
|
| 535 | 535 | $this->logger = $logger; |
| 536 | 536 | /** @var AbstractViewComponent $child */ |
| 537 | - foreach( $this->childComponents as $child ){ |
|
| 538 | - $child->setLogger( $logger ); |
|
| 537 | + foreach ($this->childComponents as $child) { |
|
| 538 | + $child->setLogger($logger); |
|
| 539 | 539 | } |
| 540 | 540 | } |
| 541 | 541 | } |
@@ -98,7 +98,7 @@ |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | - * @param $templatePath |
|
| 101 | + * @param string $templatePath |
|
| 102 | 102 | * @return null|string |
| 103 | 103 | * @throws \Exception |
| 104 | 104 | */ |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | $templatePath = null, |
| 52 | 52 | $templateString = null, |
| 53 | 53 | ResourceRepository $repo = null |
| 54 | - ){ |
|
| 55 | - parent::__construct( $component ); |
|
| 54 | + ) { |
|
| 55 | + parent::__construct($component); |
|
| 56 | 56 | $this->templatePath = $templatePath; |
| 57 | 57 | $this->templateString = $templateString; |
| 58 | 58 | // Optional Puli repo |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @return Response |
| 66 | 66 | * @throws \Exception |
| 67 | 67 | */ |
| 68 | - protected function doRender( ViewState $state, array $props = [ ] ) |
|
| 68 | + protected function doRender(ViewState $state, array $props = [ ]) |
|
| 69 | 69 | { |
| 70 | 70 | // Available variables in template file are: |
| 71 | 71 | // $state |
@@ -81,20 +81,20 @@ discard block |
||
| 81 | 81 | /** @noinspection PhpUnusedLocalVariableInspection */ |
| 82 | 82 | $exec = $this->component->exec; |
| 83 | 83 | if ($this->templatePath) { |
| 84 | - $realPath = $this->getRealTemplatePath( $this->templatePath ); |
|
| 84 | + $realPath = $this->getRealTemplatePath($this->templatePath); |
|
| 85 | 85 | ob_start(); |
| 86 | 86 | /** @noinspection PhpIncludeInspection */ |
| 87 | - include( $realPath ); |
|
| 87 | + include($realPath); |
|
| 88 | 88 | $rendered = ob_get_clean(); |
| 89 | 89 | }elseif ($this->templateString) { |
| 90 | 90 | ob_start(); |
| 91 | - eval( "?>" . $this->templateString ); |
|
| 91 | + eval("?>".$this->templateString); |
|
| 92 | 92 | $rendered = ob_get_clean(); |
| 93 | 93 | }else { |
| 94 | - throw new \Exception( "Neither valid template path no valid template string passed to PhpTemplate." ); |
|
| 94 | + throw new \Exception("Neither valid template path no valid template string passed to PhpTemplate."); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - return new Response( "text/html", $rendered ); |
|
| 97 | + return new Response("text/html", $rendered); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -102,18 +102,18 @@ discard block |
||
| 102 | 102 | * @return null|string |
| 103 | 103 | * @throws \Exception |
| 104 | 104 | */ |
| 105 | - private function getRealTemplatePath( $templatePath ) |
|
| 105 | + private function getRealTemplatePath($templatePath) |
|
| 106 | 106 | { |
| 107 | 107 | if ($this->repo instanceof ResourceRepository) { |
| 108 | - if ($this->repo->contains( $templatePath )) { |
|
| 109 | - return $this->repo->get( $templatePath ) |
|
| 108 | + if ($this->repo->contains($templatePath)) { |
|
| 109 | + return $this->repo->get($templatePath) |
|
| 110 | 110 | ->getFilesystemPath(); |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | - if (file_exists( $templatePath )) { |
|
| 113 | + if (file_exists($templatePath)) { |
|
| 114 | 114 | return $templatePath; |
| 115 | 115 | } |
| 116 | - throw new \Exception( "Template path not found in repository or on filesystem: {$templatePath}, in PhpTemplate" ); |
|
| 116 | + throw new \Exception("Template path not found in repository or on filesystem: {$templatePath}, in PhpTemplate"); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | } |
@@ -107,7 +107,7 @@ |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | - * @param $loader |
|
| 110 | + * @param Twig_LoaderInterface $loader |
|
| 111 | 111 | */ |
| 112 | 112 | protected function initTwig( $loader ) |
| 113 | 113 | { |
@@ -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 Response |
| 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,16 +40,16 @@ |
||
| 40 | 40 | * @param string $content |
| 41 | 41 | * @param int|null $responseCode |
| 42 | 42 | */ |
| 43 | - public function __construct( $type, $content, $responseCode = null ) |
|
| 43 | + public 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 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * Class AbstractTemplate |
| 26 | 26 | * @package PatternSeek\ComponentView |
| 27 | 27 | */ |
| 28 | -abstract class AbstractTemplate{ |
|
| 28 | +abstract class AbstractTemplate { |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * @var AbstractViewComponent |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | /** |
| 36 | 36 | * @param AbstractViewComponent $component |
| 37 | 37 | */ |
| 38 | - public function __construct( AbstractViewComponent $component ){ |
|
| 38 | + public function __construct(AbstractViewComponent $component) { |
|
| 39 | 39 | $this->component = $component; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | * @param array $props |
| 46 | 46 | * @return Response |
| 47 | 47 | */ |
| 48 | - public function render( ViewState $state, array $props = [] ) |
|
| 48 | + public function render(ViewState $state, array $props = [ ]) |
|
| 49 | 49 | { |
| 50 | - return $this->doRender( $state, $props ); |
|
| 50 | + return $this->doRender($state, $props); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -55,6 +55,6 @@ discard block |
||
| 55 | 55 | * @param array $props |
| 56 | 56 | * @return Response |
| 57 | 57 | */ |
| 58 | - abstract protected function doRender( ViewState $state, array $props = [] ); |
|
| 58 | + abstract protected function doRender(ViewState $state, array $props = [ ]); |
|
| 59 | 59 | |
| 60 | 60 | } |
@@ -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 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | return <<<EOS |
| 70 | 70 | <form method="{$method}" action=""{$formID}{$onSubmit} enctype="{$encType}"> |
| 71 | - <input type="hidden" name="exec" value="{$this->component->getExecPath( $execMethod )}"> |
|
| 71 | + <input type="hidden" name="exec" value="{$this->component->getExecPath($execMethod)}"> |
|
| 72 | 72 | {$formBody} |
| 73 | 73 | </form> |
| 74 | 74 | EOS; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | public function callStatic($class, $function, $args = array()) |
| 85 | 85 | { |
| 86 | 86 | if (class_exists($class) && method_exists($class, $function)) { |
| 87 | - return call_user_func_array( array( $class, $function ), $args ); |
|
| 87 | + return call_user_func_array(array($class, $function), $args); |
|
| 88 | 88 | } |
| 89 | 89 | return null; |
| 90 | 90 | } |
@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | * @param array $anchorAttrs |
| 99 | 99 | * @return string |
| 100 | 100 | */ |
| 101 | - public function replaceElementUsingLink( $execMethod, $args = [ ], $targetDiv, $linkText, $anchorAttrs = [ ] ) |
|
| 101 | + public function replaceElementUsingLink($execMethod, $args = [ ], $targetDiv, $linkText, $anchorAttrs = [ ]) |
|
| 102 | 102 | { |
| 103 | - $url = $this->url( $execMethod, $args, true ); |
|
| 103 | + $url = $this->url($execMethod, $args, true); |
|
| 104 | 104 | $attrs = [ ]; |
| 105 | 105 | foreach ($anchorAttrs as $k => $v) { |
| 106 | 106 | $attrs[ ] = "{$k}='{$v}'"; |
| 107 | 107 | } |
| 108 | - $attrsStr = implode( ' ', $attrs ); |
|
| 108 | + $attrsStr = implode(' ', $attrs); |
|
| 109 | 109 | return <<<EOS |
| 110 | 110 | <script type="application/javascript"> |
| 111 | 111 | if( typeof(execLink) != "function" ){ |
@@ -138,11 +138,11 @@ discard block |
||
| 138 | 138 | * @param string $encType |
| 139 | 139 | * @return string |
| 140 | 140 | */ |
| 141 | - public function replaceElementUsingForm( $execMethod, $method, $formBody, $targetDiv, $formID, $encType = 'application/x-www-form-urlencoded' ) |
|
| 141 | + public function replaceElementUsingForm($execMethod, $method, $formBody, $targetDiv, $formID, $encType = 'application/x-www-form-urlencoded') |
|
| 142 | 142 | { |
| 143 | 143 | return <<<EOS |
| 144 | - {$this->wrapForm( $execMethod, $method, $formBody, true, $formID, |
|
| 145 | - "execForm( this, \"{$targetDiv}\" ); return false;", $encType )} |
|
| 144 | + {$this->wrapForm($execMethod, $method, $formBody, true, $formID, |
|
| 145 | + "execForm( this, \"{$targetDiv}\" ); return false;", $encType)} |
|
| 146 | 146 | <script type="application/javascript"> |
| 147 | 147 | if( typeof(execForm) != "function" ){ |
| 148 | 148 | var execForm = function( form, targetDiv ){ |