Skip to content

Feature: add PhpNamespace to PhpFile #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 13, 2020
Merged

Feature: add PhpNamespace to PhpFile #68

merged 3 commits into from
Oct 13, 2020

Conversation

ghostwriter
Copy link

Description

Add PhpNamespace classes to a PhpFile class.

  • bug fix? no
  • new feature? yes
  • BC break? no

Example

<?php declare(strict_types=1); 

use Nette\PhpGenerator\ClassType;
use Nette\PhpGenerator\PhpFile;
use Nette\PhpGenerator\PhpNamespace;

$phpFile= new PhpFile();
$namespace = new PhpNamespace('FooBar');
$class = new ClassType('Foo');

$method = $class->addMethod('baz');
$method->setReturnType('FooBar\\Bar');
$method->setBody('return new Bar();');

$namespace->add($class);
$namespace->add(new ClassType('Bar'));

$phpFile->add($namespace);

echo $phpFile;

Result:

<?php

namespace FooBar;

class Foo
{
    public function baz(): Bar
    {
        return new Bar();
    }
}

class Bar
{
}

closes #67

Nathan E added 3 commits October 11, 2020 18:31
@dg
Copy link
Member

dg commented Oct 13, 2020

Thanks

@dg dg merged commit c9480f7 into nette:master Oct 13, 2020
@ghostwriter ghostwriter deleted the feature-create-phpfile-from-phpnamespace branch October 13, 2020 17:48
dg pushed a commit that referenced this pull request Oct 21, 2020
dg pushed a commit that referenced this pull request Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: add PhpNamespace to PhpFile
2 participants