Nette\PhpGenerator\PhpNamespace::__toString PHP Method

__toString() public method

public __toString ( ) : string
return string PHP code
    public function __toString()
    {
        $uses = [];
        asort($this->uses);
        foreach ($this->uses as $alias => $name) {
            $useNamespace = Helpers::extractNamespace($name);
            if ($this->name !== $useNamespace) {
                if ($alias === $name || substr($name, -(strlen($alias) + 1)) === '\\' . $alias) {
                    $uses[] = "use {$name};";
                } else {
                    $uses[] = "use {$name} as {$alias};";
                }
            }
        }
        $body = ($uses ? implode("\n", $uses) . "\n\n" : '') . implode("\n", $this->classes);
        if ($this->bracketedSyntax) {
            return 'namespace' . ($this->name ? ' ' . $this->name : '') . " {\n\n" . Strings::indent($body) . "\n}\n";
        } else {
            return ($this->name ? "namespace {$this->name};\n\n" : '') . $body;
        }
    }