Skip to content
This repository was archived by the owner on Jan 6, 2020. It is now read-only.

[DX] Re-work generate:bundle for simple app bundles #290#299

Closed
rafix wants to merge 12 commits into
sensiolabs:masterfrom
rafix:shared
Closed

[DX] Re-work generate:bundle for simple app bundles #290#299
rafix wants to merge 12 commits into
sensiolabs:masterfrom
rafix:shared

Conversation

@rafix

@rafix rafix commented Aug 23, 2014

Copy link
Copy Markdown
Contributor

@weaverryan please review my pull request ;)

@weaverryan

Copy link
Copy Markdown
Contributor

Relates to issue #290 :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first line, for example, should be:

array(array('--dir' => $tmp, '--format' => 'annotation', '--shared=true'), "Foo/BarBundle\n", array('Foo\BarBundle', 'FooBarBundle', $tmp.'/', 'annotation', false)),

I removed true from the third argument (which is not the input, but is used for asserting things) and passed --shared just as an option. This makes it not hang :)

Comment thread Generator/BundleGenerator.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a $shared = false. I'm not sure if it's needed, but it will protect backwards compatibility

@s7anley

s7anley commented Aug 27, 2014

Copy link
Copy Markdown

Not sure about this change. Maybe I'm creating application bundle but, I still will define custom services without need to manual load them config.yml. Maybe just omit configuration of bundle?

@weaverryan

Copy link
Copy Markdown
Contributor

@s7anley In that case, it's just up to you to create those classes. But for most devs who are building an app bundle, try should just import the yaml file if they want to define services in the bundle. In other words, you're use-case is legitimate, but we want to discourage the average dev from having the DI directory :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could expand a little bit this explanation (needs reword from a English native):

* ``--shared``: set this option if you are creating a bundle that will be shared
  across several of your applications or if you are developing a third-party
  bundle. Don't set this option if you are developing a bundle that will be
  used solely in your application (e.g. ``AppBundle``).

@javiereguiluz

Copy link
Copy Markdown
Contributor

@rafix @weaverryan I've tested this PR and here are some comments.

When using the command non-interactively, everything works perfectly:

# bundle without vendor
$ php app/console generate:bundle --namespace=AppBundle --dir=src --format=annotation --no-interaction

# bundles with vendor
$ php app/console generate:bundle --namespace=Acme\AppBundle --dir=src --format=annotation --no-interaction

$ php app/console generate:bundle --namespace=Acme\Bundle\AppBundle --dir=src --format=annotation --no-interaction

When using it interactively, everything still works, but I think it's confusing:

  Welcome to the Symfony2 bundle generator

# the command starts with a very direct question ...
Are you planning on using/sharing this bundle across multiple applications [no]?

# ... but then I see the same boring comments about vendors
Your application code must be written in bundles. This command helps
you generate them easily.

Each bundle is hosted under a namespace (like Acme/Bundle/BlogBundle).
The namespace should begin with a "vendor" name like your company name, your
project name, or your client name, followed by one or more optional category
sub-namespaces, and it should end with the bundle name itself
(which must have Bundle as a suffix).

See http://symfony.com/doc/current/cookbook/bundles/best_practices.html#index-1 for more
details on bundle naming conventions.

Use / instead of \  for the namespace delimiter to avoid any problem.

Bundle namespace: AppBundle

...

So basically, the question disables the vendor requirement but all the other things remain the same. Here it is my proposal: why don't we remove the question to the user about the shared/non-shared bundles and we just reword a bit the paragraphs before the AppBundle question? This could be a really quick and simple rewording because soon we're going to revamp this command from scratch. So let's not waste too much time on this.

@weaverryan

Copy link
Copy Markdown
Contributor

@javiereguiluz Hmm, the issue is also that a few other changes will be made based on the question Are you planning on using/sharing this bundle across multiple applications. For example, the DependencyInjection directory is only created for shared bundles.

I propose:

  1. Keep the first question about sharing the bundle
  2. If "no shared", then remove all of the text before the "Bundle namespace" question and simply ask the question: "Give your new bundle a name (e.g. AppBundle):"
  3. If "yes shared", then we have 2 options:

A) Keep things like they are now, print this big long thing
B) Fix this by splitting it up into 2 questions:

Give your new bundle a vendor namespace (e.g. Acme):
Give your new bundle a name (e.g. AppBundle):

Obviously, (B) is better, but we could do that in a different PR too :).

@javiereguiluz

Copy link
Copy Markdown
Contributor

I like your proposal Ryan. I agree that for now we should go for the option (A). Thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use $shared here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to re-assign it to $shared here

@stof

stof commented Oct 15, 2014

Copy link
Copy Markdown
Contributor

you also need to avoid creating the services.xml file when it is not shared, as the file would not be imported anymore, and the best practice book asks to define services in app/config

@xabbuh

xabbuh commented Oct 16, 2014

Copy link
Copy Markdown
Contributor

I think @javiereguiluz already raised this question in one of the related issues, but let's discuss it here: is it really needed to have the Resources directory in a non-shared bundle at all? Apparently, in most of the use cases there is no need for it when templates and translation files are stored in app/Resources, services are configured directly in app/config/services.yml, routes are configured using annotations and assets will be paced directly in web.

@javiereguiluz

Copy link
Copy Markdown
Contributor

@xabbuh thanks for bringing up this concern. The thing I'm not sure about is the following: for the already generated AppBundle that will be included in Symfony 2.6 standard edition, we definitely don't need the Resources/ dir.

But since this tool is used to generate any bundle, one company can decide to use it to generate several "application bundles" without vendors (UserBundle instead of AcmeUserBundle, etc.) In this case, if they don't follow strictly the official best practices, they may need the Resources/views/ and Resources/config/ dirs.

That's why right now I'm thinking about removing Resources/ dir only for the AppBundle. Any other thoughts about this?

@stof

stof commented Oct 16, 2014

Copy link
Copy Markdown
Contributor

@javiereguiluz I agree. It should be done based on the --shared flag, like other changes

@weaverryan

Copy link
Copy Markdown
Contributor

@javiereguiluz For a non-shared bundle, if we keep the Resources/ directory, would anything be inside of it? Or would we just be creating an empty directory?

@felds

felds commented Nov 3, 2014

Copy link
Copy Markdown

Wouldn't removing the Resources folder mess up with the generators that rely on it? (e.g. generate:controller and doctrine:generate:crud)?

In that case, should we rewrite those to use the app/Resources folder structure and include/extends statements for templates whenever the target bundle is un-prefixed (not shared)?

@ksn135

ksn135 commented Nov 12, 2014

Copy link
Copy Markdown

@felds +1 for new app/Resources folder structure

@javiereguiluz

Copy link
Copy Markdown
Contributor

People keep posting bug reports because they cannot generate bundles without vendors (see the latest: symfony/symfony-docs#4470).

Could we please treat this PR as a high priority PR and merge it as soon as possible? Thanks!

@fabpot

fabpot commented Nov 15, 2014

Copy link
Copy Markdown
Member

AFAIU, this is not ready to be merged yet, right?

@samsonasik

Copy link
Copy Markdown

ping @rafix

@weaverryan

Copy link
Copy Markdown
Contributor

I've continued this on #312, so this can be closed! @rafix had a great start, but this includes some deeper changes and conversation.

Thanks!

@fabpot

fabpot commented Nov 19, 2014

Copy link
Copy Markdown
Member

Thanks @rafix. Closing this one in favor of #312

@fabpot fabpot closed this Nov 19, 2014
fabpot added a commit that referenced this pull request Mar 23, 2015
…rafix, weaverryan)

This PR was merged into the 3.0.x-dev branch.

Discussion
----------

Update generate:bundle for non-shared bundles and more

Hi guys!

If you're reading this, please try this out and offer any feedback! There are so many different cases, it will make @fabpot's life much much easier (and that's always good).

This replaces (adds to) @rafix's work on #299. The task ended up being a bit larger, because there are so many things we *could* change, and we need to communicate things well.

Fortunately, the changes here alter the generation process very little - most changes are to *how* we ask the questions. Here are the highlights:

* if a bundle is non-shared, we only ask for a bundle name, not a namespace
* removed "generate full directory structure" functionality entirely. This added only a few extra files, which I don't think add value.
* make `.yml` the service configuration format if you choose annotation format. If you're using annotation for routing, it's likely you're following the best practices are you might be surprised by XML :)
* many small output changes

BC breaks:

* `BundleGenerator::generate` is now gone
* The `structure` option was removed
* You now get `services.yml` if you choose annotation as your format

In #299, we asked the question "should a non-shared bundle have a `Resources/` directory?". I think it should. Why? I think the `AppBundle` is special - it's the one bundle that's truly coupled to your kernel (e.g. `app/` directory), which is why it's ok to store the templates in `app/`. If we also stored templates from other bundles in `app/`, it gets a crowded. If you had a `DefaultController` in 2 bundles, their templates would "want" to occupy the same space (e.g. `app/Resources/views/default/*`).  So, I think it makes sense to have only one special bundle (per kernel) that you really *couple* to the kernel. *IF* you choose to add other bundles (which you don't need to do), I think you should organize them more along the lines of traditional bundle, at least for templates.

### TODOS

* [x] Import services.xml/yml manually from config.yml for non-shared bundle
* [x] Can we break BC in the ways described above? Or do I need to re-add somethings?
* [x] Fix the GenerateBundleCommandTest
* [x] Add more cases to BundleGeneratorTest for no DI directory
* [x] Fix BundleGeneratorTest

What does everyone think? /cc @javiereguiluz

Thanks!

Commits
-------

e632cb8 Removing docs for now-gone option
712235e updating the test because we now ALWAYS ask questions, unless you pass --no-interactive
483ab4b Coding standards
1dd31e3 Removing an extra / in the target directory (was ok, but looked bad in messaging)
8ee423b Fixing a bug where we required the vendor namespace in the exact wrong situation
a802785 Displaying path to AppKernel in messaging
2673bb4 Fixing wrong separator for namespace
079250f Not asking for the bundle if you're in non-shared mode - it was asking twice
ae3db97 Fixing default value to be dependent on the "shared" value
baab95e Cleaning some things up and changing the behavior to ask questions even if they're passed to the command line (it simplifies the code a lot)
c5785e4 Trying to fix my rebase
89d3ee6 Fixing coding standards
5ae77db Fixing another test now that the Bundle object is being passed
c66ed09 Fixing bad indentation (caught by tests!)
de0c682 Fixing test by using new Bundle object
8a768ac Fixing bad base class for test
cb4b1b9 Tweaking language based on comment from @samsonasik
7a41f5c Adding the ability to import a configuration file from app/config/config.yml
7a6033b Adding a Bundle model object to help centralize its metadata
48ced20 Removing an old, unused method
955fae6 Fixing code standards
5fa687a Fixing a number of tests!
e7645da Improving error message on the validator - just a bit more helpful when I'm doing tests
5537e9c Revert "fixing a bug where we'd ask shared even if it were passed as false"
e935050 fixing a bug where we'd ask shared even if it were passed as false
e388b40 Fixing bug that caused paths to be missing a slash
a55f65f Adding line breaks, but no changes
bfd1916 Fixing coding standards
f0d0b95 Tweaks thanks to @javiereguiluz
ad28da8 Major overhaul of the interaction part of the generate:bundle command
42c32d4 Very minor code tweaks (no functional stuff)
4af1618 CS fix
3d65d3c better explanation for --shared option
bc058c7  = false in generate method :)
1b5f7fb [WIP] optional vendor's name
8e4e023 shared option set to false by default
5f3233b droped shared element from parameters array in Generator/BundleGenerator.php
5f4d06c docs fixed
763e2f1 more on test
1d4600c [WIP] more on test
f541d16 fix test errors in Tests/Command/GenerateBundleCommandTest.php
ac39c7a patch applied
778caf2 [DX] Re-work generate:bundle for simple app bundles #290
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants