How to configure bundle in your?

For example LiipImagineBundle - he has a lot of settings in its own configuration register.

I want to make a separate bundle in which almost everything should be already configured.
How to do it correctly?

1. To import the config file from your bundle into the application.
2. $container->prependExtensionConfig($name, $config);

Or how is it?
April 19th 20 at 12:41
1 answer
April 19th 20 at 12:43
Overriding configuration in Symfony outside of the basic process of loading configuration files is not an easy thing. This process is closed from the line of customization as the main process of loading and processing of configuration bundles entirely at the mercy of them. The reason for this restriction is that the configuration loading is one of the earliest stages and, as with all similar parts of the code - there is rather little room to maneuver. In this regard, the path (and the ability) to override the configuration will very much depend on what exactly you want to override.

In order to better understand how this happens - you need to examine in more detail the question of how it is organized loading and processing configuration in Symfony.

In a nutshell:
  1. In the configuration container is the collection of configuration data from the configuration files. These data are stored in container e through ContainerBuilder::loadFromExtension().
  2. Further, the collected data are passed as a basis in the bundle extension (using the method load()). Is the bundle extension will work with the data collected is entirely dependent on the code bundle'and so they can happen anywhere.

As I hope you understand from p. 2 a common approach to overriding of data in Symfony does not exist. So, as I wrote above, you need to decide what you want to override, and then look at the code of the corresponding bundle loader (here it is for LiipImagineBundle).

As can be seen in the case of LiipImagineBundle in General, nothing terrible happens, the resulting configuration is immediately sent to processing and then is used to register services and parameters.

Since the process of assembling the container starts with a merge pass, you can't interfere in this process through a compiler pass, as is usual, however, you can use this piece of logic in order to achieve your goal: you need to define your own bundle extension and note that it implements PrependExtensionInterface. This will allow your extension to get an instance of the ContainerBuilder before how to load other extensions, it will allow you to use ContainerBuilder::loadFromExtension() to add configuration settings to your desired bundle.

Several non-trivial, but should work :)
I look at this design from the manuals
$loader = new loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
 $loader->load('services.yml');

He normally loads the description of the services. And if I can upload your Resources/config/packages/liip_imagine.yaml from the bundle? - Torey commented on April 19th 20 at 12:46
Did not work((
There is no extension able to load the configuration for "liip_imagine" ... Looked for namespace "liip_imagine", found "none".

Like this
$container->import('../config/{packages}/*.yaml');

Is it possible to bundle for crank /../Resources/config ?
To shove their configs directly from a yaml file.
If they correspond exactly to what he wants LiipImagineBundle - Torey commented on April 19th 20 at 12:49
@Zander_Grah, You'll decide what you want to achieve... If you just place the configuration files for bundles - the application must be connected to the bundle that will be uploaded, otherwise you will get an error that there is no appropriate extension.

Exactly how and where you will download the data really matters, you can use the loader and any other arrangements, if only for the moment of downloading of the configuration through the extension of the desired bundle required data was in the extension config in container E. - demarco_Fra commented on April 19th 20 at 12:52
@jazmyn, the response you got contains a lot of information on the configuration process. It is somewhere described in detail? The documentation for the Symphony so it seems not painted any where.

the application must be connected to the bundle that will be loaded

Vich\UploaderBundle\VichUploaderBundle::class => ['all' => true],
 Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],

Flex connects automatically all bundles from the bundle in the application(bundles.php).

you can use loader and any other arrangements, if only for the moment of downloading of the configuration via extension


Well, this is how I understand it is nowhere described. I myself do not hold out how to do it. The Symphony gives the folder
DependencyInjection and two file BundleExtension.php + Configuration.php

For example, I will describe the configs LiipImagineBundle and VichUploaderBundle inside your bundle in the relevant yaml files. How to load them into container of the bundle(DependencyInjection)? - Torey commented on April 19th 20 at 12:55
@Zander_Grah, No, this information in the documentation no, otherwise I wouldn't have to specify references to sources. How to do I wrote directly in the reply: "you only need to define your own bundle extension and note that it implements PrependExtensionInterface. This will allow your extension to get an instance of the ContainerBuilder before to load other extensions, it will allow you to use ContainerBuilder::loadFromExtension() to add configuration settings to your desired bundle." - demarco_Fra commented on April 19th 20 at 12:58
Yes. Thank you. I found the Doc. It seems to be described in the same component DependencyInjection. There is about the compilation process and about the expansion. also there is a funny footnote

When loading a config file that uses an extension alias as a key, the extension must already have been registered with the container builder or an exception will be thrown.


In General read, understand yet.

https://symfony.com/doc/current/components/depende...
https://symfony.com/doc/current/components/depende... - Torey commented on April 19th 20 at 13:01

Find more questions by tags Symfony