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; }
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); }