/** * Handler for everything which is not a ViewHelperNode. * * This includes Text, array syntax, and object accessor syntax. * * @param ParsingState $state Current parsing state * @param string $text Text to process * @param integer $context one of the CONTEXT_* constants, defining whether we are inside or outside of ViewHelper arguments currently. * @return void */ protected function textAndShorthandSyntaxHandler(ParsingState $state, $text, $context) { $sections = preg_split(Patterns::$SPLIT_PATTERN_SHORTHANDSYNTAX, $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); foreach ($sections as $section) { $matchedVariables = array(); $expressionNode = NULL; if (preg_match(Patterns::$SCAN_PATTERN_SHORTHANDSYNTAX_OBJECTACCESSORS, $section, $matchedVariables) > 0) { $this->objectAccessorHandler($state, $matchedVariables['Object'], $matchedVariables['Delimiter'], isset($matchedVariables['ViewHelper']) ? $matchedVariables['ViewHelper'] : '', isset($matchedVariables['AdditionalViewHelpers']) ? $matchedVariables['AdditionalViewHelpers'] : ''); } elseif ($context === self::CONTEXT_INSIDE_VIEWHELPER_ARGUMENTS && preg_match(Patterns::$SCAN_PATTERN_SHORTHANDSYNTAX_ARRAYS, $section, $matchedVariables) > 0) { // We only match arrays if we are INSIDE viewhelper arguments $this->arrayHandler($state, $this->recursiveArrayHandler($matchedVariables['Array'])); } else { // We ask custom ExpressionNode instances from ViewHelperResolver // if any match our expression: foreach ($this->renderingContext->getExpressionNodeTypes() as $expressionNodeTypeClassName) { $detetionExpression = $expressionNodeTypeClassName::$detectionExpression; $matchedVariables = array(); preg_match_all($detetionExpression, $section, $matchedVariables, PREG_SET_ORDER); if (is_array($matchedVariables) === TRUE) { foreach ($matchedVariables as $matchedVariableSet) { $expressionStartPosition = strpos($section, $matchedVariableSet[0]); /** @var ExpressionNodeInterface $expressionNode */ $expressionNode = new $expressionNodeTypeClassName($matchedVariableSet[0], $matchedVariableSet, $state); if ($expressionStartPosition > 0) { $state->getNodeFromStack()->addChildNode(new TextNode(substr($section, 0, $expressionStartPosition))); } $state->getNodeFromStack()->addChildNode($expressionNode); $expressionEndPosition = $expressionStartPosition + strlen($matchedVariableSet[0]); if ($expressionEndPosition < strlen($section)) { $this->textAndShorthandSyntaxHandler($state, substr($section, $expressionEndPosition), $context); break; } } } } if ($expressionNode) { // Trigger initial parse-time evaluation to allow the node to manipulate the rendering context. $expressionNode->evaluate($this->renderingContext); } else { // As fallback we simply render the expression back as template content. $this->textHandler($state, $section); } } } }