@@ -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 ViewComponentResponse |
@@ -213,6 +213,9 @@ discard block |
||
| 213 | 213 | return $out; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | + /** |
|
| 217 | + * @param string $execMethod |
|
| 218 | + */ |
|
| 216 | 219 | public function getExecPath( $execMethod ) |
| 217 | 220 | { |
| 218 | 221 | $path = $this->getPath(); |
@@ -318,7 +321,7 @@ discard block |
||
| 318 | 321 | * Render a child component. |
| 319 | 322 | * |
| 320 | 323 | * @param $handle |
| 321 | - * @return ViewComponentResponse |
|
| 324 | + * @return string |
|
| 322 | 325 | * @throws \Exception |
| 323 | 326 | */ |
| 324 | 327 | 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 ViewComponentResponse |
| 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 ViewComponentResponse )) { |
|
| 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 ViewComponentResponse)) { |
|
| 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,34 +189,34 @@ discard block |
||
| 189 | 189 | * @throws \Exception |
| 190 | 190 | * @return ViewComponentResponse |
| 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 ViewComponentResponse )) { |
|
| 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 ViewComponentResponse)) { |
|
| 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 | } |
| 215 | 215 | |
| 216 | - public function getExecPath( $execMethod ) |
|
| 216 | + public function getExecPath($execMethod) |
|
| 217 | 217 | { |
| 218 | 218 | $path = $this->getPath(); |
| 219 | - return ( $path === null?$execMethod:$path . '.' . $execMethod ); |
|
| 219 | + return ($path === null ? $execMethod : $path . '.' . $execMethod); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | /** |
| 232 | 232 | * @param $string |
| 233 | 233 | */ |
| 234 | - protected function setFlashMessage( $string ) |
|
| 234 | + protected function setFlashMessage($string) |
|
| 235 | 235 | { |
| 236 | 236 | $this->flashMessage = $string; |
| 237 | 237 | } |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | /** |
| 240 | 240 | * @param $string |
| 241 | 241 | */ |
| 242 | - protected function setFlashError( $string ) |
|
| 242 | + protected function setFlashError($string) |
|
| 243 | 243 | { |
| 244 | 244 | $this->flashError = $string; |
| 245 | 245 | } |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | if (null === $this->parent) { |
| 282 | 282 | return null; |
| 283 | 283 | } |
| 284 | - if (null !== ( $pPath = $this->parent->getPath() )) { |
|
| 284 | + if (null !== ($pPath = $this->parent->getPath())) { |
|
| 285 | 285 | return $pPath . '.' . $this->handle; |
| 286 | 286 | }else { |
| 287 | 287 | return $this->handle; |
@@ -297,20 +297,20 @@ discard block |
||
| 297 | 297 | * @return AbstractViewComponent |
| 298 | 298 | * @throws \Exception |
| 299 | 299 | */ |
| 300 | - protected function addOrUpdateChild( $handle, $type, array $props = [ ] ) |
|
| 300 | + protected function addOrUpdateChild($handle, $type, array $props = [ ]) |
|
| 301 | 301 | { |
| 302 | - $this->log( "Adding/updating child '{$handle}' of type {$type}", LogLevel::DEBUG ); |
|
| 303 | - if (!isset( $this->childComponents[ $handle ] )) { |
|
| 304 | - if( ! class_exists( $type ) ){ |
|
| 305 | - throw new \Exception( "Class '{$type}' for sub-component does not exist." ); |
|
| 302 | + $this->log("Adding/updating child '{$handle}' of type {$type}", LogLevel::DEBUG); |
|
| 303 | + if (!isset($this->childComponents[ $handle ])) { |
|
| 304 | + if (!class_exists($type)) { |
|
| 305 | + throw new \Exception("Class '{$type}' for sub-component does not exist."); |
|
| 306 | 306 | } |
| 307 | - $child = new $type( $handle, $this, $this->exec, $this->logger ); |
|
| 307 | + $child = new $type($handle, $this, $this->exec, $this->logger); |
|
| 308 | 308 | $this->childComponents[ $handle ] = $child; |
| 309 | 309 | }else { |
| 310 | 310 | // exec, di and logger are set recursively in rehydrate() |
| 311 | 311 | $child = $this->childComponents[ $handle ]; |
| 312 | 312 | } |
| 313 | - $child->updateProps( $props ); |
|
| 313 | + $child->updateProps($props); |
|
| 314 | 314 | $child->updateState(); |
| 315 | 315 | } |
| 316 | 316 | |
@@ -321,12 +321,12 @@ discard block |
||
| 321 | 321 | * @return ViewComponentResponse |
| 322 | 322 | * @throws \Exception |
| 323 | 323 | */ |
| 324 | - public function renderChild( $handle ) |
|
| 324 | + public function renderChild($handle) |
|
| 325 | 325 | { |
| 326 | 326 | if (!$this->childComponents[ $handle ]) { |
| 327 | 327 | $message = "Attempted to render nonexistent child component with handle '{$handle}'"; |
| 328 | - $this->log( $message, LogLevel::CRITICAL ); |
|
| 329 | - throw new \Exception( $message ); |
|
| 328 | + $this->log($message, LogLevel::CRITICAL); |
|
| 329 | + throw new \Exception($message); |
|
| 330 | 330 | } |
| 331 | 331 | return $this->childComponents[ $handle ]->render()->content; |
| 332 | 332 | } |
@@ -374,29 +374,29 @@ discard block |
||
| 374 | 374 | * @param array $inputs |
| 375 | 375 | * @throws \Exception |
| 376 | 376 | */ |
| 377 | - protected function testInputs( array $inputSpec, array &$inputs ) |
|
| 377 | + protected function testInputs(array $inputSpec, array &$inputs) |
|
| 378 | 378 | { |
| 379 | 379 | |
| 380 | 380 | foreach ($inputSpec as $fieldName => $fieldSpec) { |
| 381 | 381 | // Required field |
| 382 | - if (( count( $fieldSpec ) < 2 )) { |
|
| 383 | - if (!isset( $inputs[ $fieldName ] )) { |
|
| 384 | - $calledFunc = debug_backtrace()[1]['function']; |
|
| 385 | - $callerFunc = debug_backtrace()[2]['function']; |
|
| 386 | - $callerClass = debug_backtrace()[2]['class']; |
|
| 387 | - if( $this->parent !== null ){ |
|
| 388 | - $parentText = " (parent component is ".get_class($this->parent).")"; |
|
| 382 | + if ((count($fieldSpec) < 2)) { |
|
| 383 | + if (!isset($inputs[ $fieldName ])) { |
|
| 384 | + $calledFunc = debug_backtrace()[ 1 ][ 'function' ]; |
|
| 385 | + $callerFunc = debug_backtrace()[ 2 ][ 'function' ]; |
|
| 386 | + $callerClass = debug_backtrace()[ 2 ][ 'class' ]; |
|
| 387 | + if ($this->parent !== null) { |
|
| 388 | + $parentText = " (parent component is " . get_class($this->parent) . ")"; |
|
| 389 | 389 | } |
| 390 | - throw new \Exception( $fieldName . " is a required field for " . get_class( $this )."::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}" ); |
|
| 390 | + throw new \Exception($fieldName . " is a required field for " . get_class($this) . "::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}"); |
|
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | // Set default is unset |
| 394 | - if (!isset( $inputs[ $fieldName ] )) { |
|
| 394 | + if (!isset($inputs[ $fieldName ])) { |
|
| 395 | 395 | $inputs[ $fieldName ] = $fieldSpec[ 1 ]; |
| 396 | 396 | } |
| 397 | 397 | // Check type |
| 398 | 398 | // Any type allowed, continue |
| 399 | - if (!isset( $fieldSpec[ 0 ] ) || $fieldSpec[ 0 ] === null) { |
|
| 399 | + if (!isset($fieldSpec[ 0 ]) || $fieldSpec[ 0 ] === null) { |
|
| 400 | 400 | continue; |
| 401 | 401 | } |
| 402 | 402 | $requiredType = $fieldSpec[ 0 ]; |
@@ -404,48 +404,48 @@ discard block |
||
| 404 | 404 | // Specific type required |
| 405 | 405 | $failed = true; |
| 406 | 406 | // Null is allowed |
| 407 | - if (!is_null( $input )) { |
|
| 407 | + if (!is_null($input)) { |
|
| 408 | 408 | switch ($requiredType) { |
| 409 | 409 | case "boolean": |
| 410 | 410 | case "bool": |
| 411 | - $failed = !is_bool( $input ); |
|
| 411 | + $failed = !is_bool($input); |
|
| 412 | 412 | break; |
| 413 | 413 | case "integer": |
| 414 | 414 | case "int": |
| 415 | - $failed = !is_int( $input+0 ); |
|
| 415 | + $failed = !is_int($input + 0); |
|
| 416 | 416 | break; |
| 417 | 417 | case "double": |
| 418 | - $failed = !is_double( $input+0 ); |
|
| 418 | + $failed = !is_double($input + 0); |
|
| 419 | 419 | break; |
| 420 | 420 | case "float": |
| 421 | - $failed = !is_float( $input+0 ); |
|
| 421 | + $failed = !is_float($input + 0); |
|
| 422 | 422 | break; |
| 423 | 423 | case "string": |
| 424 | - $failed = !is_string( $input ); |
|
| 424 | + $failed = !is_string($input); |
|
| 425 | 425 | break; |
| 426 | 426 | case "array": |
| 427 | - $failed = !is_array( $input ); |
|
| 427 | + $failed = !is_array($input); |
|
| 428 | 428 | break; |
| 429 | 429 | case "object": |
| 430 | - $failed = !is_object( $input ); |
|
| 430 | + $failed = !is_object($input); |
|
| 431 | 431 | break; |
| 432 | 432 | case "resource": |
| 433 | - $failed = !is_resource( $input ); |
|
| 433 | + $failed = !is_resource($input); |
|
| 434 | 434 | break; |
| 435 | 435 | case "callable": |
| 436 | - $failed = !is_callable( $input ); |
|
| 436 | + $failed = !is_callable($input); |
|
| 437 | 437 | break; |
| 438 | 438 | default: |
| 439 | - $failed = !( $input instanceof $requiredType ); |
|
| 439 | + $failed = !($input instanceof $requiredType); |
|
| 440 | 440 | } |
| 441 | 441 | if ($failed) { |
| 442 | - $calledFunc = debug_backtrace()[1]['function']; |
|
| 443 | - $callerFunc = debug_backtrace()[2]['function']; |
|
| 444 | - $callerClass = debug_backtrace()[2]['class']; |
|
| 445 | - if( $this->parent !== null ){ |
|
| 446 | - $parentText = " (parent component is ".get_class($this->parent).")"; |
|
| 442 | + $calledFunc = debug_backtrace()[ 1 ][ 'function' ]; |
|
| 443 | + $callerFunc = debug_backtrace()[ 2 ][ 'function' ]; |
|
| 444 | + $callerClass = debug_backtrace()[ 2 ][ 'class' ]; |
|
| 445 | + if ($this->parent !== null) { |
|
| 446 | + $parentText = " (parent component is " . get_class($this->parent) . ")"; |
|
| 447 | 447 | } |
| 448 | - throw new \Exception( $fieldName . " should be of type " . $requiredType . "in " . get_class( $this )."::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}" ); |
|
| 448 | + throw new \Exception($fieldName . " should be of type " . $requiredType . "in " . get_class($this) . "::{$calledFunc}() called from {$callerClass}::{$callerFunc}(){$parentText}"); |
|
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | } |
@@ -456,9 +456,9 @@ discard block |
||
| 456 | 456 | * |
| 457 | 457 | * @var array $props |
| 458 | 458 | */ |
| 459 | - public function updateView( $props ) |
|
| 459 | + public function updateView($props) |
|
| 460 | 460 | { |
| 461 | - $this->updateProps( $props ); |
|
| 461 | + $this->updateProps($props); |
|
| 462 | 462 | $this->updateState(); |
| 463 | 463 | } |
| 464 | 464 | |
@@ -467,21 +467,21 @@ discard block |
||
| 467 | 467 | * |
| 468 | 468 | * @var array $props |
| 469 | 469 | */ |
| 470 | - protected function updateProps( $props ) |
|
| 470 | + protected function updateProps($props) |
|
| 471 | 471 | { |
| 472 | - $this->log( "Storing new props: " . var_export( $props, true ), LogLevel::DEBUG ); |
|
| 472 | + $this->log("Storing new props: " . var_export($props, true), LogLevel::DEBUG); |
|
| 473 | 473 | $this->props = $props; |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | /** |
| 477 | 477 | * @param ExecHelper $execHelper |
| 478 | 478 | */ |
| 479 | - private function setExec( ExecHelper $execHelper ) |
|
| 479 | + private function setExec(ExecHelper $execHelper) |
|
| 480 | 480 | { |
| 481 | 481 | $this->exec = clone $execHelper; |
| 482 | - $this->exec->setComponent( $this ); |
|
| 483 | - foreach( $this->childComponents as $child ){ |
|
| 484 | - $child->setExec( $execHelper ); |
|
| 482 | + $this->exec->setComponent($this); |
|
| 483 | + foreach ($this->childComponents as $child) { |
|
| 484 | + $child->setExec($execHelper); |
|
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | |
@@ -492,9 +492,9 @@ discard block |
||
| 492 | 492 | // it manually and you still get the advantage that the deps |
| 493 | 493 | // are specified in the optional injectDependencies() method's |
| 494 | 494 | // signature |
| 495 | - $this->log( "Dependency injection...", LogLevel::DEBUG ); |
|
| 496 | - DependencyInjector::instance()->injectIntoMethod( $this ); |
|
| 497 | - foreach( $this->childComponents as $child ){ |
|
| 495 | + $this->log("Dependency injection...", LogLevel::DEBUG); |
|
| 496 | + DependencyInjector::instance()->injectIntoMethod($this); |
|
| 497 | + foreach ($this->childComponents as $child) { |
|
| 498 | 498 | $child->handleDependencyInjection(); |
| 499 | 499 | } |
| 500 | 500 | } |
@@ -502,13 +502,13 @@ discard block |
||
| 502 | 502 | /** |
| 503 | 503 | * @param LoggerInterface $logger |
| 504 | 504 | */ |
| 505 | - private function setLogger( LoggerInterface $logger = null ) |
|
| 505 | + private function setLogger(LoggerInterface $logger = null) |
|
| 506 | 506 | { |
| 507 | - if( null !== $logger ){ |
|
| 507 | + if (null !== $logger) { |
|
| 508 | 508 | $this->logger = $logger; |
| 509 | 509 | /** @var AbstractViewComponent $child */ |
| 510 | - foreach( $this->childComponents as $child ){ |
|
| 511 | - $child->setLogger( $logger ); |
|
| 510 | + foreach ($this->childComponents as $child) { |
|
| 511 | + $child->setLogger($logger); |
|
| 512 | 512 | } |
| 513 | 513 | } |
| 514 | 514 | } |
@@ -69,9 +69,9 @@ |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * @param array|ViewState $state |
|
| 72 | + * @param ViewState $state |
|
| 73 | 73 | * @param array $props |
| 74 | - * @return string |
|
| 74 | + * @return ViewComponentResponse |
|
| 75 | 75 | */ |
| 76 | 76 | protected function doRender( ViewState $state, array $props = [] ) |
| 77 | 77 | { |
@@ -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 ViewComponentResponse( "text/html", $rendered ); |
|
| 92 | + return new ViewComponentResponse("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 | } |
@@ -26,8 +26,8 @@ |
||
| 26 | 26 | public $content; |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | - * @param $mime |
|
| 30 | - * @param $content |
|
| 29 | + * @param string $mime |
|
| 30 | + * @param string $content |
|
| 31 | 31 | */ |
| 32 | 32 | function __construct( $mime, $content ) |
| 33 | 33 | { |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | * @param $mime |
| 30 | 30 | * @param $content |
| 31 | 31 | */ |
| 32 | - function __construct( $mime, $content ) |
|
| 32 | + function __construct($mime, $content) |
|
| 33 | 33 | { |
| 34 | 34 | $this->mime = $mime; |
| 35 | 35 | $this->content = $content; |
@@ -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 | } |