Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New option asked about Multiple Application when generating a bundle since Symfony 2.8

Tags:

symfony

Before Symfony 2.8 and because I was in need of a multiApp system in Symfony,

I followed these two posts to achieve this :

-http://jolicode.com/blog/multiple-applications-with-symfony2

-http://mihai-stancu.ro/2015/10/03/multiple-apps-in-one-repo-with-symfony2/

It's not really supported by SensioLabs but it works well, with a attached console option (php app/console generate:bundle --app=app1 for example) to select on which app you need to use a command.

I see now since Symfony 2.8 that a new question is asked when generating a bundle :

Welcome to the Symfony bundle generator!
Are you planning on sharing this bundle across multiple applications? [no]:

But I don't find anything about this feature nowhere across the net. Is it related to a MultiApp functionality ? Any information about that ?

Thanks anyway & Best Regards !

like image 936
NoX Avatar asked Dec 16 '15 14:12

NoX


People also ask

What is a Symfony bundle?

A Symfony bundle is a collection of files and folders organized in a specific structure. The bundles are modeled in such a way that it can be reused in multiple applications. The main application itself is packaged as a bundle and it is generally called AppBundle.

What is the difference between a bundle and a main application?

The bundles are modeled in such a way that it can be reused in multiple applications. The main application itself is packaged as a bundle and it is generally called AppBundle. A bundle may be packaged specific to an application such as AdminBundle (admin section), BlogBundle (site's blog), etc.

What is an appbundle?

The bundles are modeled in such a way that it can be reused in multiple applications. The main application itself is packaged as a bundle and it is generally called AppBundle.

What is a bundle in Salesforce?

A bundle may be packaged specific to an application such as AdminBundle (admin section), BlogBundle (site's blog), etc. Such bundles cannot be shared between an application.


2 Answers

answer of @michael-sivolobov is very Good.

But, I want to add more clarity in answering the Question:

Are you planning on sharing this bundle across multiple applications? [no]:

The Symfony Bundle generator needs to decide the useage of the generated bundle.

If this question is answered with yes : That means your generated Bundle will be Used "as is" with multiple projects, not Just for your current project, so you need to prefix a "vendor" name for your generated bundle, and also add the prefix to the namespace of the generated bundle.

Upon not following the convention, a message will print from the Console which reads:

Each bundle is hosted under a namespace (like Acme/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 Best Practice for Bundle Name for more details on bundle naming conventions.

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

File structure for the generated Bundle under src/ dirctory will Be:

├─ src/
│  └─ yourVendor/
│     └─ yourBundle/
│        └─ Controller/ 
│        └─ DependencyInjection/
│        └─ Resources/
│        └─ Tests/
│        └─ yourVendorYourBundle.php/

If you answer this question with a No : This means you intend to use your generated Bundle only for your Current Project, so you do not need the "vendor" name as the prefix as it is never going to be shared.

File structure for the generated Bundle under src/ dirctory will Be:

├─ src/
│  └─ yourBundle/
│     └─ Controller/ 
│     └─ Resources/
│     └─ Tests/
│     └─ yourBundle.php/

Here is some good documentation on Best Practices for creating projects .

like image 84
ahmed hamdy Avatar answered Oct 19 '22 06:10

ahmed hamdy


If you don't know how to answer use the default value.

This question is here because you can create bundle for sharing and you must name it with vendor name (like everyone did before best practices had been posted).

But you also can create bundle for internal usage only as a main bundle of your application or some helpful bundle. And so you don't need vendor name in the name of your bundle. And answering no on this question generator will generate you not YourVendorName/AppBundle but simple AppBundle.

Also if answering yes configuration will be generated in xml format while answering no leads to annotation format.

So you don't need to worry about multiple apps if you generate them as separate bundles.

like image 4
Michael Sivolobov Avatar answered Oct 19 '22 07:10

Michael Sivolobov