gpt4 book ai didi

symfony - 在 symfony 中运行 composer install 后动态覆盖 parameters.yml 值

转载 作者:行者123 更新时间:2023-12-04 16:36:31 24 4
gpt4 key购买 nike

这个:

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

会产生:
parameters.yml
my_key: todays_timestamp_9845712365

运行后 composer install
这可能还是任何解决方法?我想要实现的是,每次运行时 composer install , my_key将具有独特的值(value)。

更新

配置文件
doctrine_cache:
providers:
my_memcached_cache:
namespace: %cache_namespace%

参数.yml
parameters:
cache_namespace: todays_timestamp_

Memcache 统计信息将始终是这样的:
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

但我想要 todays_timestamp_通过附加一个唯一的后缀来随时更改。

最佳答案

由于您的容器参数通常仅在缓存预热时创建,您可以在 XxxExtension 中创建参数。在每次部署时。从这里你可以使用然后 prepend您对 doctrine_cache 的配置而不是需要反过来做。

在您的扩展程序中,您可以执行以下操作...

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()
),
),
),
)
);
}
}

这样每次编译容器时,它应该重建 doctrine_cache 的配置。随着您的时间戳缓存 key 更新为“现在”,您就不需要 Hook Composer 更新或类似的东西。

有关 PrependExtension stuff check out the docs 的更多信息.

关于symfony - 在 symfony 中运行 composer install 后动态覆盖 parameters.yml 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31859005/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com