【问题标题】:Using alice fixtures function to calculate values使用 alice fixtures 函数计算值
【发布时间】:2016-10-06 16:45:40
【问题描述】:

我正在使用 alice 固定装置https://github.com/nelmio/alice,我很好奇是否可以将<current()> 相乘。让我们有这个代码:

entity{1..5}:
    value: <current()> * 100

你明白了。它将首先创建 5 个实体,其值为 100,第二个值为 200,等等。有没有办法做到这一点?

【问题讨论】:

    标签: php nelmio-alice alice-fixtures


    【解决方案1】:

    不可能,也不可能被原生添加到包中!

    但是,根据捆绑包贡献者 theofidry 的建议,创建 custom provider 并不是一件容易的事。

    theofidry:

    您想要做的问题是字符串&lt;current()&gt; * @offer_price_&lt;current()&gt;value 除了被解析和解析值之外,还必须被评估。那不是要添加的东西。如果你想做这种事情,你应该添加一个自定义提供者:

    total_item_price_{1..4}:
       value: <calculateItemValue(<current()>, @offer_price_<current()>)>
    

    来源:https://github.com/nelmio/alice/issues/295#issuecomment-217748524

    【讨论】:

    • 正如我所检查的,嵌套函数在现在处于测试阶段的版本 3 中工作,所以我必须找到另一种解决方法。我没有想到使用自定义提供程序,所以我将使用它构建某种解决方案。谢谢!
    猜你喜欢
    • 2023-03-16
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多