Example #1
0
 /**
  * Adds a ViewHelper node using the Format\HtmlspecialcharsViewHelper to the given node.
  * If "escapingInterceptorEnabled" in the ViewHelper is FALSE, will disable itself inside the ViewHelpers body.
  *
  * @param NodeInterface $node
  * @param integer $interceptorPosition One of the INTERCEPT_* constants for the current interception point
  * @param ParsingState $parsingState the current parsing state. Not needed in this interceptor.
  * @return NodeInterface
  */
 public function process(NodeInterface $node, $interceptorPosition, ParsingState $parsingState)
 {
     $resolver = $parsingState->getViewHelperResolver();
     if ($interceptorPosition === InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER) {
         /** @var ViewHelperNode $node */
         if (!$node->getUninitializedViewHelper()->isChildrenEscapingEnabled()) {
             $this->childrenEscapingEnabled = FALSE;
             $this->viewHelperNodesWhichDisableTheInterceptor[] = $node;
         }
     } elseif ($interceptorPosition === InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER) {
         if (end($this->viewHelperNodesWhichDisableTheInterceptor) === $node) {
             array_pop($this->viewHelperNodesWhichDisableTheInterceptor);
             if (count($this->viewHelperNodesWhichDisableTheInterceptor) === 0) {
                 $this->childrenEscapingEnabled = TRUE;
             }
         }
         /** @var ViewHelperNode $node */
         if ($this->childrenEscapingEnabled && $node->getUninitializedViewHelper()->isOutputEscapingEnabled()) {
             $node = $this->wrapNode($node, $resolver, $parsingState);
         }
     } elseif ($this->childrenEscapingEnabled && $node instanceof ObjectAccessorNode) {
         $node = $this->wrapNode($node, $resolver, $parsingState);
     }
     return $node;
 }
Example #2
0
 /**
  * @param NodeInterface $node
  * @param RenderingContextInterface $renderingContext
  * @param boolean $cast
  * @return mixed
  */
 protected function evaluateChildNode(NodeInterface $node, RenderingContextInterface $renderingContext, $cast)
 {
     $output = $node->evaluate($renderingContext);
     if ($cast && is_object($output)) {
         if (!method_exists($output, '__toString')) {
             throw new Parser\Exception('Cannot cast object of type "' . get_class($output) . '" to string.', 1273753083);
         }
         $output = (string) $output;
     }
     return $output;
 }
Example #3
0
 /**
  * @param NodeInterface $root
  */
 function __construct(NodeInterface $root)
 {
     // First, evaluate everything that is not an ObjectAccessorNode, ArrayNode
     // or ViewHelperNode so we get all text, numbers, comparators and
     // groupers from the text parts of the expression. All other nodes
     // we leave intact for later processing
     if ($root instanceof RootNode) {
         $this->stack = $root->getChildNodes();
     } else {
         $this->stack = array($root);
     }
 }
 /**
  * @param NodeInterface $node
  * @return boolean
  */
 protected function isCaseNode(NodeInterface $node)
 {
     return $node instanceof ViewHelperNode && $node->getViewHelperClassName() === 'NamelessCoder\\Fluid\\ViewHelpers\\CaseViewHelper';
 }
Example #5
0
 /**
  * @param NodeInterface $node
  * @return array
  * @see convert()
  */
 public function convertListOfSubNodes(NodeInterface $node)
 {
     switch (count($node->getChildNodes())) {
         case 0:
             return array('initialization' => '', 'execution' => 'NULL');
         case 1:
             return $this->convert(current($node->getChildNodes()));
         default:
             $outputVariableName = $this->variableName('output');
             $initializationPhpCode = sprintf('%s = \'\';', $outputVariableName) . chr(10);
             foreach ($node->getChildNodes() as $childNode) {
                 $converted = $this->convert($childNode);
                 $initializationPhpCode .= $converted['initialization'] . chr(10);
                 $initializationPhpCode .= sprintf('%s .= %s;', $outputVariableName, $converted['execution']) . chr(10);
             }
             return array('initialization' => $initializationPhpCode, 'execution' => $outputVariableName);
     }
 }