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
Feature request: add builders for namespace, use, and traits. #62
Comments
One note: probably uses() should be replaced with _use() and ns() with _namespace() for consistency. |
Agree, though I think having separate builder classes for things like uses excessive (it just has the getNode method and nothing else). Maybe in these cases we can directly return the constructed node from the method in the factory? Or would that not be so good design-wise (not all values that are returned will have a getNode() method)? @Trismegiste What do you think about this? |
I agree it seems excessive to create one builder and to call 2 methods ("ns" & "getNode") instead of chaining 2 "new". Furthermore, I think this kind of factories must be placed at the "file level". That's why I'm planning to create a builder for PHP files (with some PSR-0/1/2 guidances) and I've put this factories for "namespace" and "use" in that builder. It's currently unfinished and unshaped and I don't believe I must be placed in PHPParser but you can see it in : In the end you can make $fac = new BuilderFactory();
$file = $fac->file('sample.php')
->ns('Kitty')
->declaring(
$fac->class('Soft')
->implement('Warm')
->addStmt(
$fac
->method('purr')
)
)->getNode(); |
I agree with both points:
|
I am looking for the same features. It seems more logical to separate them from other builders. Any schedule to port this feature? |
The changes above were implemented here: https://github.com/myak/framework/tree/master/lib/Myak/Code/CodeGen. I would be happy to move of them to the PhpParser, probably with some changes. |
Any news on this one? I'm looking for the same features, but the repo from hinikato seems to be gone |
Trait builder has been added: 4387454 |
Namespace builder has also been added: 01643e0 |
Is it a possible to generate the following code using BuilderFactory and PrettyPrinter? <?php
namespace {
use Foo\BarTrait;
use PHPUnit_Framework_TestCase as TestCase;
class Test
{
}
class MyTest extends TestCase
{
}
} If I try to use namespace with empty name I get LogicException:
If no please consider ability to add support of this case. |
"Use" builder added as well in 0c34706, so closing this FR. |
I have similar to #61 feature request: It would be nice to add builders for namespace and use statements as well to add a capability to generate a whole PHP file: https://github.com/myak/framework/blob/master/lib/Myak/Code/CodeGenerator.php (see ns() and uses() methods). Probably builder for traits would be also useful.
The text was updated successfully, but these errors were encountered: