Composer.phar Symfony清除缓存

Jam*_*hen 5 symfony

每当我做composer.phar安装时,它都会清除Symfony的开发缓存.

有没有什么方法可以说清楚另一个环境缓存,比如生产?我知道我总是可以运行app/console cache:clear --env = prod.但我希望Composer在抓住依赖项后处理它.

dbr*_*ann 6

在您的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"
    ]
}
Run Code Online (Sandbox Code Playgroud)

如您所见,所有命令都存储在一个文件中,您正在寻找Sensio\Bundle\DistributionBundle\Composer\ScriptHandler :: clearCache().

由于这些脚本是在没有用户干预的情况下运行的,因此您无意添加参数.但是,您可以轻松添加自己的脚本或替换现有脚本.

编辑:我应该改写的最后一段.您可以拥有参数,但它们是在composer.json中静态定义的.额外部分中定义的值,例如"symfony-web-dir",是ScriptHandler使用的参数.可以从作曲家的CommandEvent中检索它们,如ScriptHandler :: getOptions()中所示.因此,您可以定义要在每次安装/更新时清除的环境数组,"extra"在脚本中检索它,然后为每个指定的环境调用clear cache-command.有可能通过环境变量提供值,这可能在您的场景中更有意义,但这需要深入到作曲家,因为配置不解释如何覆盖额外部分中的值.