/** * Gets the value of this argument, formatted in pure PHP code. Will * return the PHP necessary to get the contents of a context variable * if this argument holds a variable, or a quoted string for most * anything else. No post-processing is required on the returned data * to turn it into PHP code. * * @param \hydrogen\view\engines\hydrogen\PHPFile $phpFile The instance * of PHPFile being used to render this template. This is required * to handle the rare case that this argument contains a VariableNode * that has filters that need to be applied. * @return string a string of pure PHP code that represents the contents of * this argument. */ public function getValue($phpFile) { if (is_object($this->data)) { $var = new VariableNode($this->data->varLevels, $this->data->filters, false, $this->data->origin); return $var->getVariablePHP($phpFile); } return "'" . str_replace("'", '\\\'', $this->data) . "'"; }
/** * Turns a variable string (similar to what might be found in a variable * tag within a template) into pure PHP. * * @param string $varString The variable string to be parsed into PHP. * @param \hydrogen\view\engines\hydrogen\PHPFile $phpFile The instance * of PHPFile being used to render this template. * @param string $origin The name of the template from which this variable * string was taken. * @param boolean $nullIfNotFound true if a variable should evaluate to * NULL if it's not found, false if it should throw an exception in * that case. * @return string the pure PHP code that will evaluate the provided * variable string. */ protected static function parseVariableString($varString, $phpFile, $origin, $nullIfNotFound = false) { $token = Lexer::getVariableToken($origin, $varString); $vNode = new VariableNode($token->varLevels, $token->filters, false, $origin); return $vNode->getVariablePHP($phpFile, false, $nullIfNotFound); }