Dieses Blog durchsuchen

Montag, 31. Oktober 2016

symfony 3: get bundleconfiguration from everywhere. Authenticationprovider

In some cases you need to access your bundleconfiguration in contexts, where you have no container, or the container does not contain the configuration, because you are in a firewall livecycle like in the authentication provider context.

So there is hope. After 2 hours dumping arround, I found a working solution.

We simply have to install a Bundleextension in your bundle and implement the "PrependExtensionInterface". This one allows to prepend configurations.


Step 1) Add a BundleExtension to your bundle like that:


As you can see, there is a prepend method. This method loads your bundleconfiguration and adds the needed items to the container from which you can get the config item later. In Authenticationcontexts the bundleconfig isn`t loaded by default, so you have to do that all to inject the configitems.


Step 2) Add a config.yml to <Bundlename>/Resources/config:
This is done to keep your bundleconfigs only in the bundlecontext. So you can later access your bundleconfig. And only that.

Step 3) Now you can get your config:

At last we have to publish our new configitems in the <BundleName>/DependencyInjection/Configuration.php

That is it!

Keine Kommentare:

Kommentar veröffentlichen