【问题标题】:How can I conditionally replace tokens in a config file with Capistrano or Phing?如何使用 Capistrano 或 Phing 有条件地替换配置文件中的令牌?
【发布时间】:2012-03-23 12:20:10
【问题描述】:

我想尝试 Capistrano 来部署 PHP 应用程序,但看不到用于在不同环境的配置文件中替换令牌的选项。

我正在使用 Slim 微框架,它只使用 index.php 中的数组作为数据库用户名等配置变量。我想在其中放置 %dbuser% 等令牌,这些令牌将在部署时根据是否替换我正在部署到登台或生产环境。

这在 Capistrano 中可行吗?还是我会使用像 Phing 这样的东西来做到这一点?

【问题讨论】:

    标签: php deployment capistrano phing


    【解决方案1】:

    在 Phing 中,如果您的部署基于 Phing,您可以使用 ReplaceTokens filter

    示例(未测试)

    <target name="-modify-config"
            hidden="true" description="Modifies the xyz.conf ">
      <copy file="${some.directory}/xyz.conf.dist"
            tofile="${some.directory}/xyz.conf"
            overwrite="true" >
        <filterchain>
          <replacetokens begintoken="%" endtoken="%">
            <token key="KEY_A" value="${value.a}" />
            <token key="KEY_B" value="${value.b}" /> 
          </replacetokens>
        </filterchain>
      </copy>
    </target>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-29
      • 1970-01-01
      • 2020-11-12
      • 2019-12-15
      • 2016-03-15
      • 1970-01-01
      相关资源
      最近更新 更多