/**
  * Initialize operator code constructor with 1 parameter (unary).
  *
  * @param ezcTemplateAstNode $parameter 
  */
 public function __construct(ezcTemplateAstNode $parameter = null)
 {
     parent::__construct(self::OPERATOR_TYPE_UNARY, false);
     if ($parameter) {
         $this->appendParameter($parameter);
     }
 }
 /**
  * Constructs a new ezcTemplateBinaryOperatorAstNode
  *
  * @param ezcTemplateAstNode $parameter1
  * @param ezcTemplateAstNode $parameter2
  */
 public function __construct($parameter1 = null, $parameter2 = null)
 {
     parent::__construct(self::OPERATOR_TYPE_BINARY);
     if ($parameter1 !== null && $parameter2 !== null) {
         $this->appendParameter($parameter1);
         $this->appendParameter($parameter2);
     } elseif ($parameter1 != null) {
         throw new ezcTemplateInternalException("The binary operator expects zero or two parameters.");
     }
 }
 /**
  * Initialize operator code constructor with 2 parameters (binary).
  *
  * @param ezcTemplateAstNode $array
  * @param array(ezcTemplateAstNode) $fetches
  */
 public function __construct(ezcTemplateAstNode $array = null, array $fetches = null)
 {
     parent::__construct(self::OPERATOR_TYPE_BINARY);
     // This is a special binary operator since it allows more than two parameters.
     // Each extra parameter will be considered an additional array lookup
     $this->maxParameterCount = false;
     if ($array !== null) {
         $this->appendParameter($array);
         if ($fetches !== null) {
             foreach ($fetches as $fetch) {
                 $this->appendParameter($fetch);
             }
         }
     }
 }
示例#4
0
 /**
  * visitBinaryOperatorAstNode
  *
  * @param ezcTemplateOperatorAstNode  $operator
  * @return void
  */
 public function visitBinaryOperatorAstNode(ezcTemplateOperatorAstNode $operator)
 {
     $parameters = $operator->getParameters();
     if (count($parameters) < $operator->minParameterCount) {
         throw new ezcTemplateInternalException("The operator <" . get_class($operator) . " contains only " . count($parameters) . " parameters but should at least have {$operator->minParameterCount} parameters.");
     }
     array_unshift($this->nodePath, $operator);
     $this->acceptAndUpdate($operator->parameters[0]);
     $this->acceptAndUpdate($operator->parameters[1]);
     array_shift($this->nodePath);
 }
示例#5
0
 /**
  * Creates an unary operator.
  *
  * @param ezcTemplateOperatorTstNode $type
  * @param ezcTemplateOperatorAstNode $astNode
  * @param bool $addParenthesis
  */
 private function createUnaryOperatorAstNode($type, ezcTemplateOperatorAstNode $astNode, $addParenthesis = true)
 {
     $astNode->appendParameter($type->parameters[0]->accept($this));
     return $addParenthesis ? new ezcTemplateParenthesisAstNode($astNode) : $astNode;
 }
示例#6
0
 /**
  * Visits a code element containing a binary operator type.
  * Binary operators take two parameters and consist of a symbol.
  *
  * @param ezcTemplateOperatorAstNode $operator The code element containing the operator with parameters.
  * @return void
  */
 public function visitBinaryOperatorAstNode(ezcTemplateOperatorAstNode $operator)
 {
     $parameters = $operator->getParameters();
     if (count($parameters) < $operator->minParameterCount) {
         throw new ezcTemplateInternalException("The operator <" . get_class($operator) . " contains only " . count($parameters) . " parameters but should at least have {$operator->minParameterCount} parameters.");
     }
     // Generate code for first operand
     $parameters[0]->accept($this);
     // Generate the operator symbol in between parameters.
     if ($operator instanceof ezcTemplateReferenceOperatorAstNode) {
         // No spaces around the '->'.  PHP cannot handle: $myObj -> class
         $this->write($operator->getOperatorPHPSymbol());
     } else {
         $this->write(" " . $operator->getOperatorPHPSymbol() . " ");
     }
     // Generate code for second operand
     $parameters[1]->accept($this);
 }