每当我安装 composer.phar 时,它都会清除 Symfony 的开发缓存。
有什么方法可以清除另一个环境缓存,比如生产?我知道我总是可以运行 app/console cache:clear --env=prod。但我希望 Composer 在获取依赖项后处理它。
最佳答案
在您的 composer.json 中,您将找到一个“脚本”部分,它应该如下所示:
"scripts": {
"post-install-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
}
如您所见,所有命令都存储在一个文件中,Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache()就是你要找的。
由于这些脚本是在没有用户干预的情况下运行的,因此您不打算添加参数。但是,您可以轻松添加自己的脚本或替换现有脚本。
编辑:最后一段我应该改写。您可以有参数,但它们是在您的 composer.json 中静态定义的。在额外部分中定义的值,例如“symfony-web-dir”,是 ScriptHandler 使用的参数。它们可以从 Composer 的 CommandEvent 中检索,如 ScriptHandler::getOptions() 所示。 .因此,例如,您可以在
"extra"
中定义要在每次安装/更新时清除的环境数组。 ,在您的脚本中检索它,然后为每个指定的环境调用 clear cache-command。可以通过 environment variables 提供这些值。这在您的场景中可能更有意义,但这需要深入研究 Composer,因为配置没有解释例如如何覆盖额外部分中的值。
关于symfony - Composer.phar Symfony 清除缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14987368/