-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Use render() as primary ViewHelper method
- Loading branch information
Showing
4 changed files
with
33 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,7 +258,7 @@ public function initializeArgumentsAndRender() | |
$this->validateArguments(); | ||
$this->initialize(); | ||
|
||
return $this->callRenderMethod(); | ||
return $this->render(); | ||
} | ||
|
||
/** | ||
|
@@ -491,6 +491,31 @@ public function validateAdditionalArguments(array $arguments) | |
} | ||
} | ||
|
||
public function render() | ||
{ | ||
return static::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext); | ||
} | ||
|
||
/** | ||
* @param array $arguments | ||
* @param \Closure $renderChildrenClosure | ||
* @param RenderingContextInterface $renderingContext | ||
* @return string | ||
* @throws ViewHelper\Exception | ||
* @deprecated | ||
*/ | ||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) | ||
Check failure on line 507 in src/Core/ViewHelper/AbstractViewHelper.php GitHub Actions / build (8.2)
Check failure on line 507 in src/Core/ViewHelper/AbstractViewHelper.php GitHub Actions / build (8.3)
Check failure on line 507 in src/Core/ViewHelper/AbstractViewHelper.php GitHub Actions / build (8.2)
Check failure on line 507 in src/Core/ViewHelper/AbstractViewHelper.php GitHub Actions / build (8.3)
|
||
{ | ||
throw new Exception( | ||
sprintf( | ||
'ViewHelper class "%s" does not declare a "render()" method and inherits the default "renderStatic". ' . | ||
'Executing this ViewHelper would cause infinite recursion - please either implement "render()" or ' . | ||
'"renderStatic()" on your ViewHelper class', | ||
static::class, | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* You only should override this method *when you absolutely know what you | ||
* are doing*, and really want to influence the generated PHP code during | ||
|
@@ -528,7 +553,7 @@ public function validateAdditionalArguments(array $arguments) | |
public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler) | ||
{ | ||
$execution = sprintf( | ||
'%s::renderStatic(%s, %s, $renderingContext)', | ||
'$renderingContext->getViewHelperInvoker()->invoke(%s::class, %s, $renderingContext, %s)', | ||
static::class, | ||
$argumentsName, | ||
$closureName, | ||
|
@@ -551,22 +576,6 @@ public function compile($argumentsName, $closureName, &$initializationPhpCode, V | |
return $execution; | ||
} | ||
|
||
/** | ||
* Default implementation of static rendering; useful API method if your ViewHelper | ||
* when compiled is able to render itself statically to increase performance. This | ||
* default implementation will simply delegate to the ViewHelperInvoker. | ||
* | ||
* @param array<string, mixed> $arguments | ||
* @param \Closure $renderChildrenClosure | ||
* @param RenderingContextInterface $renderingContext | ||
* @return mixed | ||
*/ | ||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) | ||
{ | ||
$viewHelperClassName = get_called_class(); | ||
return $renderingContext->getViewHelperInvoker()->invoke($viewHelperClassName, $arguments, $renderingContext, $renderChildrenClosure); | ||
} | ||
|
||
/** | ||
* Save the associated ViewHelper node in a static public class variable. | ||
* called directly after the ViewHelper was built. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters