2 namespace TYPO3\CMS\Fluid\Core\ViewHelper;
134 $this->templateVariableContainer = $renderingContext->getTemplateVariableContainer();
135 if ($renderingContext->getControllerContext() !== null) {
136 $this->controllerContext = $renderingContext->getControllerContext();
138 $this->viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
176 protected function registerArgument($name, $type, $description, $required =
false, $defaultValue = null)
178 if (array_key_exists($name, $this->argumentDefinitions)) {
179 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'Argument "' . $name .
'" has already been defined, thus it should not be defined again.', 1253036401);
181 $this->argumentDefinitions[$name] = new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition($name, $type, $description, $required, $defaultValue);
199 protected function overrideArgument($name, $type, $description, $required =
false, $defaultValue = null)
201 if (!array_key_exists($name, $this->argumentDefinitions)) {
202 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
'Argument "' . $name .
'" has not been defined, thus it can\'t be overridden.', 1279212461);
204 $this->argumentDefinitions[$name] = new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition($name, $type, $description, $required, $defaultValue);
218 $this->viewHelperNode = $node;
253 $renderMethodParameters = array();
254 foreach ($this->argumentDefinitions as $argumentName => $argumentDefinition) {
255 if ($argumentDefinition->isMethodParameter()) {
256 $renderMethodParameters[$argumentName] = $this->arguments[$argumentName];
261 return call_user_func_array(array($this,
'render'), $renderMethodParameters);
264 $this->
getLogger()->error(
'A Fluid ViewHelper Exception was captured: ' . $exception->getMessage() .
' (' . $exception->getCode() .
')', array(
'exception' => $exception));
301 if ($this->renderChildrenClosure !== null) {
305 return $this->viewHelperNode->evaluateChildNodes($this->renderingContext);
319 return function () use ($self) {
320 return $self->renderChildren();
331 if (!$this->argumentsInitialized) {
332 $thisClassName = get_class($this);
333 if (isset(self::$argumentDefinitionCache[$thisClassName])) {
334 $this->argumentDefinitions = self::$argumentDefinitionCache[$thisClassName];
340 $this->argumentsInitialized =
true;
353 $methodParameters = $this->reflectionService->getMethodParameters(get_class($this),
'render');
354 if (count($methodParameters) === 0) {
359 $methodTags = $this->reflectionService->getMethodTagsValues(get_class($this),
'render');
361 $paramAnnotations = array();
362 if (isset($methodTags[
'param'])) {
363 $paramAnnotations = $methodTags[
'param'];
368 foreach ($methodParameters as $parameterName => $parameterInfo) {
370 if (isset($parameterInfo[
'type'])) {
371 $dataType = $parameterInfo[
'type'];
372 }
elseif ($parameterInfo[
'array']) {
375 if ($dataType === null) {
376 throw new \TYPO3\CMS\Fluid\Core\Parser\Exception(
'could not determine type of argument "' . $parameterName .
'" of the render-method in ViewHelper "' . get_class($this) .
'". Either the methods docComment is invalid or some PHP optimizer strips off comments.', 1242292003);
380 if (\TYPO3\CMS\
Fluid\Fluid::$debugMode && isset($paramAnnotations[$i])) {
381 $explodedAnnotation = explode(
' ', $paramAnnotations[$i]);
382 array_shift($explodedAnnotation);
383 array_shift($explodedAnnotation);
384 $description = implode(
' ', $explodedAnnotation);
386 $defaultValue = null;
387 if (isset($parameterInfo[
'defaultValue'])) {
388 $defaultValue = $parameterInfo[
'defaultValue'];
390 $this->argumentDefinitions[$parameterName] = new \TYPO3\CMS\Fluid\Core\ViewHelper\ArgumentDefinition($parameterName, $dataType, $description, ($parameterInfo[
'optional'] ===
false), $defaultValue,
true);
409 if ($this->arguments[$argumentName] === $registeredArgument->getDefaultValue()) {
413 $type = $registeredArgument->getType();
414 if ($type ===
'array') {
415 if (!is_array($this->arguments[$argumentName]) && !$this->arguments[$argumentName] instanceof \ArrayAccess && !$this->arguments[$argumentName] instanceof \Traversable) {
416 throw new \InvalidArgumentException(
'The argument "' . $argumentName .
'" was registered with type "array", but is of type "' . gettype($this->arguments[$argumentName]) .
'" in view helper "' . get_class($this) .
'"', 1237900529);
418 }
elseif ($type ===
'boolean') {
419 if (!is_bool($this->arguments[$argumentName])) {
420 throw new \InvalidArgumentException(
'The argument "' . $argumentName .
'" was registered with type "boolean", but is of type "' . gettype($this->arguments[$argumentName]) .
'" in view helper "' . get_class($this) .
'".', 1240227732);
422 }
elseif (class_exists($type,
false)) {
423 if (!($this->arguments[$argumentName] instanceof $type)) {
424 if (is_object($this->arguments[$argumentName])) {
425 throw new \InvalidArgumentException(
'The argument "' . $argumentName .
'" was registered with type "' . $type .
'", but is of type "' . get_class($this->arguments[$argumentName]) .
'" in view helper "' . get_class($this) .
'".', 1256475114);
427 throw new \InvalidArgumentException(
'The argument "' . $argumentName .
'" was registered with type "' . $type .
'", but is of type "' . gettype($this->arguments[$argumentName]) .
'" in view helper "' . get_class($this) .
'".', 1256475113);
466 return isset($this->arguments[$argumentName]) && $this->arguments[$argumentName] !== null;
485 public function compile($argumentsVariableName, $renderChildrenClosureVariableName, &$initializationPhpCode, \TYPO3\CMS\
Fluid\Core\Parser\SyntaxTree\AbstractNode $syntaxTreeNode, \TYPO3\CMS\
Fluid\Core\Compiler\TemplateCompiler $templateCompiler)
487 return sprintf(
'%s::renderStatic(%s, %s, $renderingContext)',
488 get_class($this), $argumentsVariableName, $renderChildrenClosureVariableName);