Overriding .yml parameter values ​​dynamically after linker launch in symfony

It:

parameters_dev.yml.dist my_key: todays_timestamp_{$timestamp} 

will generate:

 parameters.yml my_key: todays_timestamp_9845712365 

after running composer install

Is this possible or some kind of workaround? What I'm trying to achieve, every time I run composer install , my_key will have a unique value.


UPDATE

config.yml

 doctrine_cache: providers: my_memcached_cache: namespace: %cache_namespace% 

parameters.yml

 parameters: cache_namespace: todays_timestamp_ 

Memcache statistics will always be like this:

 Server 127.0.0.1:11211 stats cachedump 12 100 Server 127.0.0.1:11211 ITEM todays_timestamp_[My\Bundle\Acc][1] [1807 b; 1438597305 s] ITEM todays_timestamp_[My\Bundle\Mer][1] [1707 b; 1438597305 s] ..... ..... END 

but I want todays_timestamp_ change all the time with a unique suffix attached to it.

+4
source share
2 answers

Since the parameters of your container are usually created only when overclocking the cache, you can create a parameter in your XxxExtension for each deployment. From here, you can use prepend your configuration for doctrine_cache , instead of doing it the other way around.

In your extension you can do the following ...

 namespace Acme\HelloBundle\DependencyInjection; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; // implement the PrependExtensionInterface so it gets picked up by the DI class AcmeHelloExtension extends Extension implements PrependExtensionInterface { // Add your usual extension stuff // add the prepend method to prepend your config onto the doctrine_cache config public function prepend(ContainerBuilder $container) { // check for the presence of the doctrine_cache bundle and throw an exception if (!$container->hasExtension('doctrine_cache')) { throw new \Exception('DoctrineCacheBundle must be registered in kernel'); } // add your config with your timestamp to the doctrine_cache config $container->prependExtensionConfig( 'doctrine_cache', array( 'providers' => array( 'my_memcached_cache' => array( 'namespace' => sprintf( // your cache key with timestamp 'memcache_timestamp_%s', \DateTime::getTimestamp() ), ), ), ) ); } } 

Thus, every time the container is compiled, it must rebuild the configuration for doctrine_cache with an updated cache key, which now “stops” when you need to cling to the composer's updates or something like that.

For more information about PrependExtension check your documents .

+6
source

I also think for asset versioning. In practice, I offer you the following approach:

 <?php // app/config/cache_namespace_version.php $container->loadFromExtension('doctrine_cache', array( 'providers' => array( 'my_memcached_cache' => array( 'namespace' => exec('git rev-parse --short HEAD'), // Or the current timestamp ), ))); 

And import into config_prod.ml

 # app/config/config.yml imports: - { resource: config.yml } - { resource: cache_namespace_version.php } 

You can use the current timestamp instead of a git hash commit, it depends on whether you want to change the key, each of which is cleared by the cache, or only when changing the code.

Make sure I enter the correct doctrine_cache key into the container. Inspired by this article.

Hope for this help

+4
source

All Articles