- 🇮🇱Israel jkdev
Just override the parameter from your own
ServiceProvider
.Instead of using symfony magic and replace the way the container is being built, use the drupal/symfony way to alter services/parameters in the container:
https://www.drupal.org/docs/drupal-apis/services-and-dependency-injectio... →In essence what we did is to create file: my_module/src/MyModuleServiceProvider.php (the name matters) looks like this:
namespace Drupal\my_module; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceProviderBase; class MyModuleServiceProvider extends ServiceProviderBase { /** * {@inheritdoc} */ public function alter(ContainerBuilder $container) { $cors_config = $container->getParameter('cors.config'); $cors_config['allowedOrigins'] = ['https://' . $_ENV['CONSUMER_HOST']]; $container->setParameter('cors.config', $cors_config); } }
Make sure clear cache (so container will be compiled fresh) -
drush cr
/drush cc container
- First commit to issue fork.
@bircher
I added some basic test coverage for resolving the env variable at compile time.I'm also playing around with the idea to support using environment variables during runtime, see the --runtime branch.
This is clearly a bit more involved, and I think belongs really into its own issue in the first place.- 🇧🇪Belgium DieterHolvoet Brussels
@jkdev by doing it that way the values from environment variables are cached in the container, which means you need to rebuild caches anytime an environment variable is changed. I don't think we want that.
@duadua looks like you haven't pushed anything yet to the
issue-3249970--runtime
and3249970-support-setting-service
branches. I'm not sure why, but it contains some commits from other issues. Onlyissue-3249970
contains relevant commits.