-
-
Notifications
You must be signed in to change notification settings - Fork 406
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
Allow generation into sub-namespaces #120
Conversation
This allowed us to more easily support generating into sub-namespaces.
<3 |
This also means that the App\ prefix is now hardcoded in exactly *one* place, and could be moved to configuration very easily.
This PR was merged into the 1.0-dev branch. Discussion ---------- Allow generation into sub-namespaces Three changes: 1) Generation is now allowed into sub-namespaces: e.g. `make:controller` passing it `Admin\MainController` would generate into `src/Controller/Admin/MainController.php`. 2) You can pass absolute class names now too - e.g. `OtherNamespace\Controller\FooController`. Maker reads the Composer autoloader to figure out where this should live - e.g. `lib/Controller/FooController.php`. This fixes #2: Maker follows your autoloading rules to find *where* to generate things. 3) [BC] Break for anyone with custom makes: the `MakerInterface` was updated to be much simpler. Instead of `getParameters()`, `getFiles()` and `writeSuccessMessage()`, you just implement `generate()` and do it all in one method. I think using this library to create custom maker commands is still quite uncommon (we are listed as dependencies of VERY few projects on Packagist), so I think we should make this change versus keeping BC code paths for a long time in the future. Cheers! Commits ------- 5d1b976 Fixing possible non-existent dir in test 38f7887 fixing tests 6b2f56f phpcs dccaea1 Fixing bad method & only generating entity if it exists 9e90cbc Adding support for passing \Absolute\Class\Paths as class names c9617ba Minor tweaks - removing extra "." in text and making twig extension interactive 7f02ed1 Maker error message show the relative paths f8d3e09 Making the maker write changes so they can control message ordering 2da8b65 removing php 7.1 code 27ac258 doc'ing BC break aabbedf Refactoring MakerInterface to be more straightforward 5261d6d Updating templates
Hi @weaverryan, it seems that |
public function __construct(Filesystem $fs, string $rootDirectory) | ||
{ | ||
$this->fs = $fs; | ||
$this->rootDirectory = $rootDirectory; | ||
$this->rootDirectory = rtrim($this->realpath($rootDirectory).'/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there must be a comma, not dot ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, looks like you might be right. Could you open a PR?
Yes, the double back slash thing is just because that’s how arguments work on the terminal - you need two \ to be seen as one. Nothing we can do about that :/. However, if you just run make:controller and then answer the question (instead of passing as an arg), I believe it works with a single \ |
Thank you very much, answering the question works perfectly. |
Just for clarity, this works precisely as described. |
Three changes:
Generation is now allowed into sub-namespaces: e.g.
make:controller
passing itAdmin\MainController
would generate intosrc/Controller/Admin/MainController.php
.You can pass absolute class names now too - e.g.
OtherNamespace\Controller\FooController
. Maker reads the Composer autoloader to figure out where this should live - e.g.lib/Controller/FooController.php
. This fixes Support for configurable Flex directories #2: Maker follows your autoloading rules to find where to generate things.[BC] Break for anyone with custom makes: the
MakerInterface
was updated to be much simpler. Instead ofgetParameters()
,getFiles()
andwriteSuccessMessage()
, you just implementgenerate()
and do it all in one method. I think using this library to create custom maker commands is still quite uncommon (we are listed as dependencies of VERY few projects on Packagist), so I think we should make this change versus keeping BC code paths for a long time in the future.Cheers!