コード例 #1
0
ファイル: ClassProperty.php プロジェクト: Ronmi/CodeGen
 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 . ';';
 }
コード例 #2
0
ファイル: BracketedBlock.php プロジェクト: Ronmi/CodeGen
 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;
 }
コード例 #3
0
ファイル: ClassTrait.php プロジェクト: Ronmi/CodeGen
 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;
 }
コード例 #4
0
ファイル: Comment.php プロジェクト: Ronmi/CodeGen
 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;
 }
コード例 #5
0
ファイル: CommentBlock.php プロジェクト: Ronmi/CodeGen
 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));
 }
コード例 #6
0
ファイル: Block.php プロジェクト: Ronmi/CodeGen
 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));
 }
コード例 #7
0
ファイル: ClassMethod.php プロジェクト: Ronmi/CodeGen
 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);
 }
コード例 #8
0
ファイル: ClassConst.php プロジェクト: Ronmi/CodeGen
 public function render(array $args = array())
 {
     return Indenter::indent($this->indentLevel) . 'const ' . $this->name . ' = ' . var_export($this->value, true) . ';';
 }
コード例 #9
0
ファイル: UserClass.php プロジェクト: Ronmi/CodeGen
 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);
 }