Skip to content
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

Merged
merged 12 commits into from
Feb 19, 2018

Conversation

weaverryan
Copy link
Member

@weaverryan weaverryan commented Feb 10, 2018

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 Support for configurable Flex directories #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!

pink6440 and others added 2 commits February 9, 2018 11:54
This allowed us to more easily support generating into sub-namespaces.
@Coffee2CodeNL
Copy link
Contributor

<3

@weaverryan weaverryan added the Feature New Feature label Feb 11, 2018
@weaverryan weaverryan merged commit 5d1b976 into symfony:master Feb 19, 2018
weaverryan added a commit that referenced this pull request Feb 19, 2018
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
@weaverryan weaverryan deleted the allow-sub-namespaces branch February 19, 2018 18:21
@ghost
Copy link

ghost commented Jul 10, 2018

Hi @weaverryan, it seems that make:controller Admin\MainController generates the controller into the src/Controller/AdminMainController.php namespace instead of src/Controller/Admin. To have it inside the Admin sub-namespace i had to use double backslashes. Is this the default behavior?

public function __construct(Filesystem $fs, string $rootDirectory)
{
$this->fs = $fs;
$this->rootDirectory = $rootDirectory;
$this->rootDirectory = rtrim($this->realpath($rootDirectory).'/');
Copy link
Contributor

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 ?

Copy link
Member Author

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?

@weaverryan
Copy link
Member Author

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 \

@ghost
Copy link

ghost commented Jul 17, 2018

Thank you very much, answering the question works perfectly.

@SeanHolt
Copy link

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 \

Just for clarity, this works precisely as described.
Thanks for everybody's hard work on this project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for configurable Flex directories
5 participants