Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 - how to extend a vendor bundle (e.g. of FOSFacebookBundle)
    primarykey
    data
    text
    <p><strong>Scenario:</strong></p> <p>I'm using a bundle (FOSFacebookBundle) that allows me to set parameters for exactly one facebook app in my configuration. Everything works perfectly fine, but now I need to set not only one app, but multiple.</p> <p><strong>My approach:</strong></p> <p>I've created a AcmeFacebookBundle, which allows multiple apps to be defined (configuration defined in <em>Acme\FacebookBundle\DependencyInjection\Configuration</em>) in an array like so:</p> <pre><code>acme_facebook: apps: some_competition: server_url: %acme.facebook.some_competition.server_url% file: %kernel.root_dir%/../vendor/facebook/php-sdk/src/base_facebook.php alias: facebook app_id: %acme.facebook.some_competition.app_id% secret: % acme .facebook.some_competition.secret% cookie: true permissions: [email, user_birthday, user_location] some_other_competition: server_url: %acme.facebook. some_other_competition.server_url% file: %kernel.root_dir%/../vendor/facebook/php-sdk/src/base_facebook.php alias: facebook app_id: %acme.facebook. some_other_competition.app_id% secret: % acme .facebook. some_other_competition.secret% cookie: true permissions: [email, user_birthday, user_location] </code></pre> <p>In <em>Acme\FacebookBundle\DependencyInjection\AcmeFacebookExtension</em> I am then looping through all apps. The idea is to compare the server_url parameter against the current URL and override the fos_facebook configuration with mine. </p> <pre><code>class AcmeFacebookExtension extends Extension { ... /** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this-&gt;processConfiguration($configuration, $configs); foreach ($config['apps'] as $app) { // check for matching path here? foreach (array('file', 'app_id', 'secret', 'cookie', 'domain', 'logging', 'culture', 'permissions') as $attribute) { $container-&gt;setParameter('fos_facebook.' . $attribute, $app[$attribute]); } } } </code></pre> <p><strong>Problem:</strong></p> <p>But this is exactly where I'm stuck. Obviously, I have no access to the Request object or the DiC from within AcmeFacebookExtension to do this comparison. Am I going completely wrong in my approach? Do you have any better idea on how to tackle this problem?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload