Exemple #1
0
 public function render(array $args = array())
 {
     $code = Indenter::indent($this->indentLevel) . $this->scope . ' $' . $this->name;
     if ($this->value) {
         $code .= ' = ' . var_export($this->value, true);
     }
     return $code . ';';
 }
Exemple #2
0
 public function render(array $args = array())
 {
     $tab = Indenter::indent($this->indentLevel);
     $this->increaseIndentLevel();
     // increaseIndentLevel to indent the inner block.
     $body = '';
     $body .= $tab . "{\n";
     $body .= parent::render($args);
     $body .= $tab . "}\n";
     return $body;
 }
Exemple #3
0
 public function render(array $args = array())
 {
     $out = Indenter::indent($this->indentLevel) . "use " . join(', ', $this->classes);
     if (empty($this->definitions)) {
         $out .= ";";
     } else {
         $block = new BracketedBlock();
         foreach ($this->definitions as $def) {
             $block[] = $def;
         }
         $out .= $block->render($args);
     }
     return $out;
 }
Exemple #4
0
 public function render(array $args = array())
 {
     $tab = Indenter::indent($this->indentLevel);
     $out = $tab . '// ';
     if (is_string($this->comment)) {
         $out .= $this->comment;
     } else {
         if ($this->comment instanceof Renderable) {
             $out .= $this->comment->render($args);
         } else {
             throw new InvalidArgumentTypeException('Invalid type for comment.', $this->comment, ['string', 'Renderable']);
         }
     }
     return $out;
 }
Exemple #5
0
 public function render(array $args = array())
 {
     $tab = Indenter::indent($this->indentLevel);
     $body = '';
     $body .= $tab . "/**\n";
     foreach ($this->lines as $line) {
         if (is_string($line)) {
             $body .= $tab . ' * ' . $line . "\n";
         } else {
             if ($line instanceof Renderable) {
                 $subbody = rtrim($line->render());
                 // trim the trailing white-space
                 $sublines = explode("\n", $subbody);
                 foreach ($sublines as $subline) {
                     $body .= $tab . ' * ' . $subline . "\n";
                 }
             } else {
                 throw new Exception("Unsupported line object.");
             }
         }
     }
     $body .= " */\n";
     return Utils::renderStringTemplate($body, array_merge($this->args, $args));
 }
Exemple #6
0
 public function render(array $args = array())
 {
     $tab = Indenter::indent($this->indentLevel);
     $body = '';
     foreach ($this->lines as $line) {
         if (is_string($line)) {
             $body .= $tab . $line . "\n";
         } else {
             if ($line instanceof Renderable) {
                 $subbody = rtrim($line->render());
                 // trim the trailing white-space
                 $sublines = explode("\n", $subbody);
                 foreach ($sublines as $subline) {
                     $body .= $tab . $subline . "\n";
                 }
             } else {
                 var_dump($line);
                 throw new InvalidArgumentTypeException("Unsupported line object type", $line, array('string', 'Renderable'));
             }
         }
     }
     return Utils::renderStringTemplate($body, array_merge($this->args, $args));
 }
Exemple #7
0
 public function render(array $args = array())
 {
     $block = $this->getBlock();
     $block->setIndentLevel($this->indentLevel);
     return Indenter::indent($this->indentLevel) . $this->scope . ' function ' . $this->name . '(' . $this->renderArguments() . ")\n" . $block->render($args);
 }
Exemple #8
0
 public function render(array $args = array())
 {
     return Indenter::indent($this->indentLevel) . 'const ' . $this->name . ' = ' . var_export($this->value, true) . ';';
 }
Exemple #9
0
 public function render(array $args = array())
 {
     $lines = array();
     // Add an option to render with a php tag
     if ($this->class->namespace) {
         $lines[] = 'namespace ' . $this->class->namespace . ';';
     }
     // When there is no namespace, we should skip the first-level class use statement.
     if ($this->uses) {
         foreach ($this->uses as $u) {
             // If we are not in a namespace, just skip these one component use statement
             if (!$this->class->namespace && count($u->getComponents()) == 1) {
                 continue;
             }
             $lines[] = $u->render();
         }
     }
     $lines[] = 'class ' . $this->class->name;
     if ($this->extends) {
         $lines[] = Indenter::indent(1) . 'extends ' . $this->extends->render();
     }
     if ($this->interfaces) {
         $lines[] = Indenter::indent(1) . 'implements ' . join(', ', array_map(function ($class) {
             return $class->name;
         }, $this->class->interfaces));
     }
     $block = new BracketedBlock();
     foreach ($this->traits as $trait) {
         $block[] = $trait;
     }
     foreach ($this->consts as $const) {
         $block[] = $const;
     }
     foreach ($this->staticVars as $var) {
         $block[] = $var;
     }
     foreach ($this->properties as $property) {
         $block[] = $property;
     }
     foreach ($this->methods as $method) {
         $method->getBlock()->setIndentLevel(1);
         $block[] = $method;
     }
     $lines[] = $block->render($args);
     return join("\n", $lines);
 }