【问题标题】:Composer.phar Symfony clear cacheComposer.phar Symfony 清除缓存
【发布时间】:2013-02-20 18:32:32
【问题描述】:

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

有什么方法可以清除其他环境的缓存,比如生产环境吗?我知道我总是可以运行 app/console cache:clear --env=prod。但我希望 Composer 在获取依赖项后处理它。

【问题讨论】:

    标签: symfony


    【解决方案1】:

    在您的 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 使用的参数。它们可以从作曲家的 CommandEvent 中检索,如 ScriptHandler::getOptions() 所示。因此,您可以例如在"extra" 中定义每次安装/更新时要清除的环境数组,在脚本中检索它,然后为每个指定的环境调用清除缓存命令。可能可以通过environment variables 提供值,这在您的场景中可能更有意义,但这需要深入研究作曲家,因为配置没有解释例如如何覆盖额外部分中的值。

    【讨论】:

      【解决方案2】:

      我在寻找如何在作曲家更新后设置资产符号链接选项时找到了这个答案。

      您可以在 composer.json 文件的额外节点中添加“symfony-assets-install”条目

      "extra": {
          "symfony-app-dir": "app",
          "symfony-web-dir": "web",
          "symfony-assets-install": "symlink"
      }
      

      src:Updating Vendors

      【讨论】:

      • 说明要添加哪个条目会很有用。
      猜你喜欢
      • 2017-12-21
      • 2013-03-26
      • 2015-07-21
      • 2021-07-07
      • 2016-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-22
      相关资源
      最近更新 更多