예제 #1
0
파일: type_cast.php 프로젝트: bmdevel/ezc
 /**
  * Construct a new type cast.
  *
  * @param string $castToType
  * @param ezcTemplateAstNode $value
  */
 public function __construct($castToType, $value)
 {
     parent::__construct();
     // TODO, check for int, string, array, etc.
     $this->type = $castToType;
     $this->value = $value;
 }
예제 #2
0
 /**
  * Constructs a new variable.
  *
  * @param string $name The name of the variable.
  */
 public function __construct($name)
 {
     parent::__construct();
     if (!is_string($name)) {
         throw new ezcBaseValueException("name", $name, 'string');
     }
     $this->name = $name;
     $this->typeHint = self::TYPE_VALUE;
 }
예제 #3
0
 /**
  * Constructs the ezcTemplateParameterizedAstNode.
  *
  * @param int $minParameterCount The minimum parameters the operator can have, set to false to remove limit.
  * @param int $maxParameterCount The maximum parameters the operator can have, set to false to remove limit.
  */
 public function __construct($minParameterCount = 1, $maxParameterCount = 1)
 {
     parent::__construct();
     if (!is_int($minParameterCount) && $minParameterCount !== false) {
         throw new ezcTemplateInternalException("The parameter \$minParameterCount needs be an integer.");
     }
     if (!is_int($maxParameterCount) && $maxParameterCount !== false) {
         throw new ezcTemplateInternalException("The parameter \$maxParameterCount needs be an integer.");
     }
     $this->minParameterCount = $minParameterCount;
     $this->maxParameterCount = $maxParameterCount;
     $this->parameters = array();
 }
예제 #4
0
 /**
  * Initialize with function name code and optional arguments
  *
  * @param array(ezcTemplateStatementAstNode) $statements
  */
 public function __construct(array $statements = null)
 {
     parent::__construct();
     $this->statements = array();
     if ($statements !== null) {
         foreach ($statements as $statement) {
             if (!$statement instanceof ezcTemplateStatementAstNode) {
                 throw new ezcTemplateInternalException("Body code element can only use objects of instance ezcTemplateStatementAstNode as statements");
             }
         }
         $this->statements = $statements;
     }
 }
예제 #5
0
 /**
  * Constructs a new Literal
  *
  * @param mixed $value The value of PHP type to be stored in code element.
  */
 public function __construct($value)
 {
     parent::__construct();
     $this->value = $value;
     if (is_resource($value)) {
         throw new ezcTemplateInternalException("Cannot use resource for type codes, resources cannot be exported as text strings");
     }
     // Check if the __set_state magic method is implemented
     if (is_object($value) && !method_exists($value, "__set_state")) {
         throw new ezcTemplateInternalException("The magic method __set_state is not implemented for passed object, the type code cannot create a representation of the object without it.");
     }
     $this->checkAndSetTypeHint();
 }
예제 #6
0
 /**
  * Visits the program TST node.
  *
  * Note: This is the first node in the TST tree.
  *
  * @see handleProgramHeader()
  * @param ezcTemplateProgramTstNode $type
  * @return ezcTemplateAstNode
  */
 public function visitProgramTstNode(ezcTemplateProgramTstNode $type)
 {
     if ($this->programNode === null) {
         $this->prepareProgram();
         foreach ($type->children as $element) {
             $astNode = $element->accept($this);
             if (!is_array($astNode)) {
                 $astNode = array($astNode);
             }
             foreach ($astNode as $ast) {
                 if ($ast instanceof ezcTemplateStatementAstNode) {
                     $this->programNode->appendStatement($ast);
                 } else {
                     throw new ezcTemplateInternalException("Expected an ezcTemplateStatementAstNode: " . __FILE__ . ":" . __LINE__);
                 }
             }
         }
         $this->programNode->appendStatement(new ezcTemplateReturnAstNode($this->outputVariable->getAst()));
     }
 }
예제 #7
0
 /**
  * Internal function called to  call the accept function and change the given node.
  *
  * @param ezcTemplateAstNode $node  Notice that the parameter will be changed.
  * @return void
  */
 protected function acceptAndUpdate(ezcTemplateAstNode &$node)
 {
     $ret = $node->accept($this);
     if ($ret !== null) {
         $node = $ret;
     }
 }
예제 #8
0
 /**
  * Constructs a new ezcTemplate Literal array.
  */
 public function __construct()
 {
     parent::__construct();
     $this->checkAndSetTypeHint();
 }
예제 #9
0
 /**
  * Initialize with function name code and optional arguments
  *
  * @param ezcTemplateAstNode $expression
  */
 public function __construct(ezcTemplateAstNode $expression = null)
 {
     parent::__construct();
     $this->expression = $expression;
 }
예제 #10
0
 /**
  * Constructs a new ezcTemplateConstantAstNode
  *
  * @param mixed $value The value of constant.
  */
 public function __construct($value)
 {
     parent::__construct();
     $this->value = $value;
 }
예제 #11
0
 /**
  * Convenience function for outputting a node.
  * Instantiates the ezcTemplateAstTreeOutput class and calls accept() on
  * $node, the resulting text is returned.
  *
  * @param ezcTemplateAstNode $node
  * @return string
  */
 public static function output(ezcTemplateAstNode $node)
 {
     $treeOutput = new ezcTemplateAstTreeOutput();
     $node->accept($treeOutput);
     return $treeOutput->text . "\n";
 }
예제 #12
0
 /**
  * Initialize with condition and body statement.
  *
  * @param ezcTemplateAstNode $condition
  * @param ezcTemplateBodyAstNode $body
  */
 public function __construct(ezcTemplateAstNode $condition = null, ezcTemplateBodyAstNode $body = null)
 {
     parent::__construct();
     $this->condition = $condition;
     $this->body = $body;
 }