Ejemplo n.º 1
0
 /**
  * Appends a do/while control structure to the current body and returns $this.
  * The $expression parameter can either be a code element or a PHP type
  * which is turned into an ezcTemplateLiteralAstNode object.
  * The $body parameter can either be an ezcTemplateBodyAstNode element or
  * an ezcTemplateAstBuilder object in which case the body is taken from
  * the builder.
  *
  * Usually you will call body() and use the result as the $body parameter,
  * this allows you to specify the statements for the body of the if.
  * <code>
  * $cb->_doWhile( true,
  *                $cb->body()
  *                   ->assign( "a", 5 )
  *                   ->_break() );
  * </code>
  * This represents the code:
  * <code>
  * do
  * {
  *     $a = 5;
  *     break;
  * } while ( true );
  * </code>
  *
  * @param mixed $expression The evaluated expression for the 'do/while'.
  * @param mixed $body       The body of the 'do/while' structure.
  * @return ezcTemplateAstBuilder
  */
 public function _doWhile($expression, $body)
 {
     if (!is_object($expression) || !$expression instanceof ezcTemplateAstNode) {
         $expression = new ezcTemplateLiteralAstNode($expression);
     }
     if ($body instanceof ezcTemplateAstBuilder) {
         $body = $body->getAstNode();
     }
     $conditionBody = new ezcTemplateConditionBodyAstNode($expression, $body);
     $while = new ezcTemplateDoWhileAstNode($conditionBody);
     $this->currentBody->appendStatement($while);
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Initialize with function name code and optional arguments
  *
  * @param array(ezcTemplateAstNode) $statements
  * @param bool $startProgram
  */
 public function __construct(array $statements = null, $startProgram = true)
 {
     parent::__construct();
     $this->startProgram = $startProgram;
 }
Ejemplo n.º 3
0
 /**
  * It's an implementation that creates a new body part.
  * Convenience method for creating a Body AST node from an
  * array of AST nodes. Each element in the array can be a sub-array containing nodes.
  * For each node in the array it will call
  * ezcTemplateBodyAstNode::appendStatement().
  *
  * <code>
  * $list[] = new ezcTemplateGenericStatementAstNode( $node );
  * $body = $this->createBody( $list );
  * </code>
  *
  * @param array $elements
  * @return ezcTemplateBodyAstNode
  * @throws ezcTemplateInternalException if the node is not of the interface ezcTemplateStatementAstNode.
  */
 protected function createBody(array $elements)
 {
     $body = new ezcTemplateBodyAstNode();
     foreach ($elements as $element) {
         $astNode = $element->accept($this);
         if (is_array($astNode)) {
             foreach ($astNode as $ast) {
                 if ($ast instanceof ezcTemplateStatementAstNode) {
                     $body->appendStatement($ast);
                 } else {
                     throw new ezcTemplateInternalException(sprintf("Expected an ezcTemplateStatementAstNode, got %s: " . __FILE__ . ":" . __LINE__, get_class($ast)));
                 }
             }
         } else {
             if ($astNode instanceof ezcTemplateStatementAstNode) {
                 $body->appendStatement($astNode);
             } else {
                 throw new ezcTemplateInternalException("Expected an ezcTemplateStatementAstNode: " . __FILE__ . ":" . __LINE__);
             }
         }
     }
     return $body;
 }