I was wondering what order does Symfony use when loading config files, and I can't seem to find the answer. The config is later flattened using processConfiguration method from Extension class.
Symfony loads app/config/config.yml first;
config_{environment}.yml afterwards for it to be able to overwrite default settings;
afterwards all bundle configuration is loaded in the order of the bundles being registered in app/AppKernel.php.
Related
My goal is to add to a new Symfony 4.4 project an extra config file to define some behavior of the system. It could be anything, like, pancakes.yaml:
pancakes:
enablePancakes: false
I wish to know how can I load that config file. find a way to read its parameters and values to change some custom behavior the system might have but honestly I think I'm not smart enough to understand what the documentation says.
For now it could be anything, like printing the configuration file values, for now I only need to know how to load it.
you can update the following file :
# config/service.yaml
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.
parameters:
locale: 'en'
chat_update_interval: 10000
and use service decoration in your new application to override your parameters.
I have a line in a sample Symfony app that reads:
$seo = $this->get('sonata.seo.page');
However the config.yml file reads:
sonata_seo:
page:
metas:
property: ... etc ...
I've read http://symfony.com/doc/current/service_container.html but I'm not clear how exactly the get('sonata.seo.page') works. Does it somehow equate to the key / values in the config file? i.e. does the underscore in sonata_seo get magically changed to a period?
You cannot access values in config.yml direcly, like values in parameters.yml.
That file can store configuration values for bundles thought.
Read more here
What it is 'getting' in this instance, usually within a controller action, is a Symfony Service.
In this instance, sonata.seo.page is a reference to a service, setup in the sonata-project/seo-bundle, which returns an instance of the SeoPage class. Normally, this information is set within your local configuration file (config.yml, or a file that it includes), but the service returns the class that allows you to change the values at runtime.
No service are (directly) defined inside config.yml. It's the bundle that define the service. With $this->get('sonata.seo.page'); you get those.
The config.yml file it's just used to customize the bundles.
The SeoBundle defines the semantic configuration section sonata_seo from config.yml and registers the own Extension of DI container.
Extension implements the load() method. Configuration values from sonata_seo are passed as its first argument.
Method loads various resources including service definition from Resources/config/service.xml:
<parameter key="sonata.seo.page.default.class">Sonata\SeoBundle\Seo\SeoPage</parameter>
...
<service id="sonata.seo.page.default" class="%sonata.seo.page.default.class%"/>
Next, extension set up sonata.seo.page definition with given configuration parameters.
This process will be invoked during the container compilation, when the service definition and its settings will be embedded in the container. Result of this process you can find in the dumped container in the cache directory.
This is a typical scheme of work for the Symfony bundles: define the configuration structure, make an extension, set up the services.
I am trying to override the translations in the default FOSUserBundle.en.yml. I have my User bundle as a child of the FOSUserBundle using the getParent method and I copied the FOSUserBundle.en.yml into the translations folder of the child bundle and nothing is being overridden. Can someone help me find out why this is?
I know I have to be missing something because I was able to override the layout.html.twig file easily doing the same thing.
I tried using php app/console cache:clear and that did not help.
It turned out that the translation file was overriding but the FOSUserBundle was after the child bundle in the AppKernel file. Because of how translations work the translation file from the FOSUserBundle was being loaded after the childs translation file, in turn overriding the child.
All I had to do was move the child bundle in the AppKernel file after the parent. This way it was the last translation file to be loaded.
Here is the documentation page I found this at:
http://symfony.com/doc/current/cookbook/bundles/override.html#override-translations
I've run into this before as well. Try manually deleting your cache/dev directory. I'm guessing your talking about the dev environment as cache:clear without parameters defaults to dev.
Is it possible to define a different Auth config for a bundle ? application/config/auth.php is default for bundles as well but I need to use different auth modules for different bundles of the system.
Also, creating a new one on the BUNDLE/config/ folder doesn't affect anything. So, it loads the default one in any case.
The short answer is that you cannot... Neither Auth nor Config were designed to be extended per bundle.
The long answer is that you could use your bundle's start.php file to override each config setting, for example
// bundles/my-bundle/start.php
Config::set('auth.driver', 'fluent');
Config::set('auth.table', 'my_users');
In Symfony 1.4, is it possible for one to define a custom config file (e.g. my_config.yml) that allows cascading; for instance, having a global custom config file and a module level analogue?
Yes.
Define a config handler in config_handlers.yml. It'll probably look like:
config/my_config.yml:
class: myConfigHandler
Write your config handler. You can look at many of the other config handlers in lib/config for examples. You'll likely want to extend sfYamlConfigHandler.
To access your config values:
sfContext::getInstance()->getConfigCache()->checkConfig('/config/my_config.yml');