Ejemplo n.º 1
0
 /**
  * Note: The source code in $code must be loaded/created before passing it to this parser.
  *
  * @param ezcTemplateSourceCode $source
  * @param ezcTemplate $template
  */
 function __construct(ezcTemplateSourceCode $source, ezcTemplate $template)
 {
     $this->source = $source;
     $this->template = $template;
     $this->textElements = array();
     $this->trimWhitespace = $template->trimWhitespace;
     $this->symbolTable = ezcTemplateSymbolTable::getInstance();
     $this->symbolTable->reset();
     $this->whitespaceRemoval = new ezcTemplateWhitespaceRemoval();
 }
 public function checkAndSetTypeHint()
 {
     $symbolTable = ezcTemplateSymbolTable::getInstance();
     $this->typeHint = $this->parameters[1]->typeHint;
     if ($this->parameters[0] instanceof ezcTemplateVariableAstNode) {
         if ($symbolTable->retrieve($this->parameters[0]->name) == ezcTemplateSymbolTable::IMPORT) {
             // It can be anything.
             $symbolTable->setTypeHint($this->parameters[0]->name, self::TYPE_ARRAY | self::TYPE_VALUE);
         } else {
             $symbolTable->setTypeHint($this->parameters[0]->name, $this->typeHint);
         }
     }
 }
 public function push($name, $astNode = null)
 {
     if ($astNode === null) {
         $astNode = new ezcTemplateVariableAstNode($name);
         $symbolTable = ezcTemplateSymbolTable::getInstance();
         if ($symbolTable->getTypeHint($name) == false) {
             $astNode->typeHint = ezcTemplateAstNode::TYPE_ARRAY | ezcTemplateAstNode::TYPE_VALUE;
         } else {
             // Will this work, values from this function is different than AST constants?
             $astNode->typeHint = $symbolTable->getTypeHint($name);
         }
     }
     array_push($this->outputVariables, array('name' => $name, 'ast' => $astNode, 'is_used' => false));
     ++$this->stackSize;
 }
 public function visitDynamicBlockTstNode(ezcTemplateDynamicBlockTstNode $node)
 {
     // Write the variables introduced in the static part to the cache.
     $symbolTable = ezcTemplateSymbolTable::getInstance();
     $symbols = $symbolTable->retrieveSymbolsWithType(array(ezcTemplateSymbolTable::VARIABLE, ezcTemplateSymbolTable::CYCLE));
     $newStatement = array();
     foreach ($symbols as $s) {
         if (array_key_exists($s, $this->declaredVariables)) {
             $newStatement[] = $this->_fwriteVarExportVariable("t_" . $s, false, false);
         }
     }
     $newStatement[] = $this->_comment(" ---> start {dynamic}");
     // $total .= $_ezcTemplate_output
     $newStatement[] = $this->_concatAssignVariable(self::INTERNAL_PREFIX . "output", "total" . $this->cacheLevel);
     // fwrite( $fp, "\\\<variableName> .= " . var_export( <variableName>, true) . ";" );
     $newStatement[] = $this->_fwriteVarExportVariable(self::INTERNAL_PREFIX . "output", true, false);
     // $_ezcTemplate_output = "";
     $newStatement[] = $this->_assignEmptyString(self::INTERNAL_PREFIX . "output");
     // $output .= $_ezcTemplate_output;
     $newStatement[] = $this->_concatAssignVariable(self::INTERNAL_PREFIX . "output", "total" . $this->cacheLevel);
     // Place everything in the code block.
     $newStatement[] = new ezcTemplatePhpCodeAstNode("\$code = '");
     $this->isInDynamicBlock = true;
     $tmp = new ezcTemplateDynamicBlockAstNode($this->createBody($node->children));
     $tmp->escapeSingleQuote = true;
     $newStatement[] = $tmp;
     $this->isInDynamicBlock = false;
     // $newStatement = array();
     $newStatement[] = new ezcTemplatePhpCodeAstNode("';\n");
     // fwrite( $fp, $code );
     $newStatement[] = $this->_fwriteVariable("code");
     // eval( $code );
     $retTypeVariable = $this->createVariableNode(self::INTERNAL_PREFIX . "retType");
     $newStatement[] = new ezcTemplateGenericStatementAstNode(new ezcTemplateAssignmentOperatorAstNode($retTypeVariable, new ezcTemplateFunctionCallAstNode("eval", array($this->createVariableNode("code")))));
     // $total .= _ezcTemplate_output
     $newStatement[] = $this->_concatAssignVariable(self::INTERNAL_PREFIX . "output", "total" . $this->cacheLevel);
     // $ezcTemplate_output = "";
     $newStatement[] = $this->_assignEmptyString(self::INTERNAL_PREFIX . "output");
     $retTypeIf = new ezcTemplateIfAstNode();
     $retTypeIf->conditions[] = $cb = new ezcTemplateConditionBodyAstNode();
     $cb->condition = new ezcTemplateNotIdenticalOperatorAstNode($retTypeVariable, new ezcTemplateLiteralAstNode(null));
     $cb->body = new ezcTemplateBodyAstNode();
     $cb->body->statements = array();
     $cb->body->statements[] = $this->_fclose();
     $cb->body->statements[] = new ezcTemplateReturnAstNode(new ezcTemplateVariableAstNode("total" . $this->cacheLevel));
     $newStatement[] = $retTypeIf;
     $newStatement[] = $this->_comment(" <--- stop {/dynamic}");
     return $newStatement;
 }
Ejemplo n.º 5
0
 /**
  * Return the existing instance of the symbol table if it exists. 
  * Otherwise a new instance is created. (Singleton)
  *
  * @return ezcTemplateSymbolTable
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new ezcTemplateSymbolTable();
     }
     return self::$instance;
 }
Ejemplo n.º 6
0
 /**
  * This creates a new AST node which holds a template variable (from the template source).
  *
  * @see createVariableNode()
  * @param string $name
  * @return ezcTemplateVariableAstNode
  */
 private function createTemplateVariableNode($name)
 {
     $astName = self::EXTERNAL_PREFIX . $name;
     $node = new ezcTemplateVariableAstNode($astName);
     $symbolTable = ezcTemplateSymbolTable::getInstance();
     if ($symbolTable->getTypeHint($astName) == false) {
         $node->typeHint = ezcTemplateAstNode::TYPE_ARRAY | ezcTemplateAstNode::TYPE_VALUE;
     } else {
         // Will this work, values from this function is different than AST contants?
         $node->typeHint = $symbolTable->getTypeHint($astName);
     }
     return $node;
 }