Create a bundle in vendors in Symfony2 - symfony

I am trying to create a bundle in vendors in Symfony2.
MyBundle(MineUserBundle) needs to inherit other two bundle in vendors FOSUserBundle and HWIOAuthBundle.
How to get inherit both bundles properties, templates etc in Mybundle?
vendors
FOSUserBundle
HWIOAuthBundle
MineUserBundle
Here MineUserBundle needs to have all features of other two bundle.
How to get the process work?

Since you are using namespaces it does not mater into which folder you are going to deploy your Bundle. Just include use statements in your bundle with ones you need:
use Path\To\FOS\UserBundle;
use Path\ToHWIO\AuthBundle;
And you can extend whatever you need.
But if you really want to install your bundle to vendor directory, then you have to configure define it in your deps file.
[YourVendorYouBundle]
git=git#github.com:yourRepository/YourVendorYouBundle.git
target=/bundles/YourVendor/YouBundle

Related

Can Symfony Bundle be used in non-Symfony project (f.e. Zend)?

Can I reuse my Bundle created in Symfony in non-Symfony project, f.e. Zend? (Or I only can reuse Components?)
What about services from that Bundle?
A Symfony bundle can certainly be included in with other projects, via a composer.json & composer.lock file - it doesn't mean that there is any useful code to run within that bundle however.
If there is useful code as part of the bundle, then you can use it directly, but a Symfony Bundle is just a library that will usually include some Symfony-specific configuration.
Best practice for a bundle is to put any useful, common code, into a separate library (which could be used independently - such as what Symfony calls a 'Component'), and then enable that code (for example creating Symfony services, or configuration) with the bundle configuration.
There have been projects that are Symfony bundles, and also have the configurations for other frameworks as well, such as Silex, and also appropriate Laravel configurations within the same codebase.

How to use variables in Symfony Doctrine ORM annotations?

In short, I would like to use something like:
#ORM\Table(name="schemaname.tablename")
but replacing the "schemaname" string with a variable, that can be set as a configuration parameter somewhere (like in parameters.yml file)
I understand your context as a reusable bundle entity with cross domain relation to an other bundle.
I don't find anything about doctrine mapping customisation, but as your bundle can only be included once per project, I recommand you to use your bundle name as a prefix for the table.
Like yourapp_tablename
For the crossdomain constraint, your bundle, if it is reusable can't have dependencies to external bundles. It is your business bundles which have to use the reusable bundle, not the way around. I guess you have to use interfaces if you want an external bundle to be extending your model class

Where to save your TWIG templates in Symfony framework

What is the best place to keep your TWIG template and why?
app/Resources/views folder
or
YourBundle/Resources/views
Traditionally, Symfony developers stored the application templates in
the Resources/views/ directory of each bundle. Then they used the
logical name to refer to them (e.g.
AcmeDemoBundle:Default:index.html.twig).
But for the templates used in your application, it's much more
convenient to store them in the app/Resources/views/ directory.
Syfmony Documentation
In Symfony 2, auto generated twig files were located in YourBundle/Resources/views
In Symfony 3, auto generated twig files are located in app/Resources/views
When developing your application, best place is YourBundle/Resources/views. It will be more consistent and probably it will be easier to maintain and eventually, decouple your bundle for installation in other projects.
I find app/Resources/views useful to override other bundle's templates, for example when creating Error pages http://symfony.com/doc/current/cookbook/controller/error_pages.html
It depends of your bundles architecture. The point is to be consistent with your current architecture.
From the official doc:
For most projects, you should store everything inside the AppBundle
If you use a main bundle structure (like a big AppBundle with many small domain bundles) then you probably want to centralize your templates in App or the ressources of your main Bundle.
But if you use a functionnal bundles (like EmailBundle, UserBundle, Invoice Bundle) then you probably want to ignore the symfony best practice and put the concerned twig in these bundles.

About the default AppBundle in Symfony2

When creating a new SF2 project, the project contains an AppBundle by default. Should this be removed like the AcmeDemoBundle?
Symfony best practice
For most projects, you should store everything inside the AppBundle.
http://symfony.com/doc/current/best_practices/business-logic.html
Multiple bundles
I tend to create multiple bundles, e.g. I have these bundles in src/:
MyProjectEntityBundle
MyProjectBackendBundle
MyProjectHomePageBundle
And for reusable components I create a symfony bundle that I put into a git repository and load it via composer using satis. So for example I have some bundles in vendor/:
VendorCmsUtilBundle
VendorImageThumbnailBundle
"Domain Driven Design (DDD)"
I have yet to try this approach (I will soon):
http://williamdurand.fr/2013/08/07/ddd-with-symfony2-folder-structure-and-code-first/
As #Marcel Burkhard pointed out, the AppBundle is where you should put all your application logic according to Symfony best practices. Of course you can throw it away and build your own, but it's definitely not like the Acme Demo bundle.
I disagree with the strategy of splitting Entities and Frontend / Backend in different bundles.
I agree with the strategy of creating your own "utility" bundle(s) so that you can reuse your code in different projects via composer.

Best place for other php.class in symfony2?

i have a php.class that handle gd-functions in my symfony2-project. Where i can find the best place for this classes?
Regards
Create a folder in src/. To autoload the classes that are in the folder you will create, use Composer Autoload feature (https://getcomposer.org/doc/04-schema.md#classmap) or autoload it in /app/ (https://github.com/symfony/symfony-standard/blob/2.7/app/autoload.php)
If your Class is also useable without an Symfony2 context you should not place it in Acme\Bundles\DemoBundle but rater under Acme\Components\ChangeThisToWhateverYourLibsNameIs. Then you can define an service in your bundle for this class to use this as an service in an Symfony context.
Why?
Because with this way you can reuse the library in that namespace in other frameworks two. You could maybe create a new composer package for it and add it as an dependency of your bundle.
As you see the Symfony core team does it the same way:
https://github.com/symfony/symfony/blob/2.7/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml
Add it to any of your bundles. You sure must have bundles created. Add a directory to your bundle. The directory can be named anything. I normally name it Services. Add namespace to your class. Lets say if your bundle name is AcmeDemoBundle and your directory name is Services, your namespace would be Acme\Bundles\DemoBundles\Services
You can then register this class as a service and access via DI.

Resources