Symfony reusable bundle default configuration - php

I'm playing with Symfony reusable bundles and I want to make some bundle with default configuration for all my other projects like common entities, controllers etc. But the problem is taht I want to keep some default configuration for 3rd party bundles in that bundle too (easy admin, fos user bundle,...).
I would like to set some default configuration in my bundle and in case of need override it in app/config... Is this possible and if yes, how can I achieve that.
Thanks in advance

You need use prepend extension config for keep other extension configurations.
Follow the documantation
https://symfony.com/doc/current/bundles/prepend_extension.html

You can maybe write a compiler pass that will set parameters in your 3rd party bundle.
Here is an example of compiler pass I did here.
so in your compiler pass you would have something like:
$fosParameters = ['db_driver' => 'orm', 'firewall_name' => 'main'];
$container->setParameter(
'fos_user',
$fosParameters
);
also, do not forget to add your compiler pass to your bundle file like I did here.
I am not 100% sure this will work but I do not see why it would not work.

Related

SonataMediaBundle: change default filesystem s3 adapter

Is it possible to use a different class for sonata.media.adapter.filesystem.s3 service? Right now I can see it's hardcoded in gaufrette.php:
->set('sonata.media.adapter.filesystem.s3', AwsS3::class)
->args(['', '', ''])
Is it possible to override this behaviour and set any other adapter class, e.g. Gaufrette\Adapter\AsyncAwsS3?
According to Symfonys architecture it should be possible to override pretty much everything: https://symfony.com/doc/current/bundles/override.html#services-configuration
If you want to modify the services created by a bundle, you can use service decoration. If you want to do more advanced manipulations, like removing services created by other bundles, you must work with service definitions inside a compiler pass.
Most probably you solution is the latter. Here is an existing question on how to do that: Symfony: Overriding Symfony service ( compiler pass )

Symfony2 bypassing default locale in parameters.yml

i am newbee in Symfony2.
I'm wondering if it is possible to override default hardcoded locale in parameters.yml and set one i.e from a #service ??
The task is to manage languages and locales from admin area (e.g. added and stored in database). And to use default one, based on this data.
I've tried to use LocaleListener described here http://symfony.com/doc/current/cookbook/session/locale_sticky_session.html
but anyway it takes %default_locale% from parameters for the first request.
Also, there are a lot of nice bundles for route translations as JMSI18nRoutingBundle
and LexikTranslationBundle for translations, but all of them use in configuration hardcoded %default_locale% and/or locale lists.
Is it possible to solve this somehow with Symfony2? Thanks in advance.

Symfony2 bundle as a plugin

Consider situation where I have some default bundle that hypothetically create some empty page with menu on left and some content (if there is any). Then I create a new bundle and I normally turn it on in AppKernel. Now should magic start: bundle by his own (no need to add any options in default bundle etc.) hooks up and creates his menu entry (and if chosen, renders his content). How should I do this, is there any proper way to do this? What if I want to have multiple "hooks", for example, adding also new form in user profile edit, or adding new tab on some other place?
I'm thinking about looking for some "initialize bundle event" that I could listen to and pass data thru it. But maybe there is better solution. I would love to see your ideas :)
Looking at the initializeBundles method of the Kernel, it doesn't look easy or intended to dynamically add bundles during the bootup process.
However, the AppKernel.php file is on the forefront, it is an override of Kernel and can be customized to supply a dynamic set of bundles to the implemented registerBundles method.
You will need to make sure the imported content is properly added to the autoloader, but avoid modifying the distribution source at runtime, try to make it as imported as possible.
I don't want to go into great detail on the technicalities as I have not done this myself and it will require a lot of experimentation. I do know that Drupal 8 uses Symfony2 and has its own plugin system, but I don't think it takes bundles as plugins.
If you manage to pull this off I suspect it will allow 100% integration between the application and the plugins, but just be aware that it also allows 100% overriding access to said plugins.

Symfony - What is required to create a plugin?

I've been going through the Symfony documentation in order to find out how to create a plugin. However, the two tutorials seem to give a lot of extra information (for example models etc).
What I'd like to know is, what is the absolute minimum requirement in order to get a controller and template working from a plugin directory?
For example, just an index action and a corresponding 'Hello World' template.
Also, is the routing for this automatic or do I have to manually change something?
Any advice appreciated.
Thanks.
To do what youre askign you would need the following:
MyPlugin/
modules/
my_module/
actions/
actions.class.php
templates/
indexSuccess.php
You would then need to enable the plugin in you ProjectConfiguration and also enable the module in your settings.yml for any apps you want to use it.
Routing is not automatic. You need to add routes manually to routing.yml or you can create a listener and appends/prepends the routes when routing.load_configuration is fired. USing the second option would also imply creating a PluginConfiguration class where you listeners connect to the event via the event dispatcher.
Basically a Plugin follows the same basic structure as an application - except pretty much everything is optional. Whether or not you need to do somethign really depends on what your plugin does. Also you might want to take a look at using sfTaskExtraPlugin it has a task for generating a basic plugin skeleton and a plugin module skeleton.
some examples
enable the plugin in you ProjectConfiguration
go to 'core\config\ProjectConfiguration.class.php' and add next code in setup()
$this->enablePlugins('MyPlugin');
enable the module in your settings.yml
all:
.settings:
enabled_modules: [my_module]

Zend framework Internal structure modification?

What class(FrontController , Bootstrap, Dispacher....) sets up the default structure path in ZF?
There is no single instance that has all the paths. Each component has it's own defaults, e.g. the FrontController knows that the controller directory should be named controllers, but it doesn't know how to make a full path from it (Dispatcher does it) or where to find the Action Helpers. That's defined in ActionHelper Broker. Consequently, Zend_View_Abstract holds the paths for View filters, helpers and scripts, etc.
Like #Pascal mentioned in his comment, you should not modify ZF at it's core. You will lose the changes once you update to a newer version anyway. Configure the paths through the API in your bootstrap or through the application.ini instead.
Actually it's the dispatcher's job to find the requested action controller.
So you'll have to extend either Zend_Controller_Dispatcher_Abstract or Zend_Controller_Dispatcher_Standard or even create a completely new one based on Zend_Controller_Dispatcher_Interface to fit your requirements.
But be aware that you'll have to change the way Zend_Controller_Action_Helper_ViewRenderer tries to find the required view files, too.

Categories