使用 alice fixtures 函数计算值

Using alice fixtures function to calculate values

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

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

你懂的。它将创建 5 个实体,第一个值为 100,第二个值为 200 等。有没有办法做到这一点?

不可能,也不太可能以本地方式添加到捆绑包中!

但是,创建一个 custom provider, as per the suggestion of theofidry 包的贡献者并不是一件容易的事。

theofidry:

The problem with what you would like to do is that the string <current()> * @offer_price_<current()>value must, besides being parsed and the value resolved, be evaluated. That's not something that will be added. If you want to do this kind of thing, you should add a custom provider:

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

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