rezzza / formulate
在编写复杂的数学公式时使生活更简单,深呼吸
v1.0.6
2016-05-17 13:00 UTC
Requires
- php: >=5.3.2
- hoa/math: <2.0
Requires (Dev)
- atoum/atoum: ~2.0
This package is not auto-updated.
Last update: 2024-09-21 13:14:30 UTC
README
在编写复杂的数学公式时使生活更简单,深呼吸
通过composer安装
# composer.json
"rezzza/formulate": "dev-master"
# shell
php composer.phar update # or install
用法
<?php use Rezzza\Formulate\Formula; $formula = new Formula('{{ variable1 }} + {{ variable2 }}'); $formula->setParameter('variable1', 10); $formula->setParameter('variable2', 13); echo $formula->render(); // "10 + 13" $formula->setIsCalculable(true); echo $formula->render(); // "23" // Works with sub formulas $formula = new Formula('{{ subformula1 }} + {{ variable2 }}'); $formula->setSubFormula('subformula1', new Formula('({{ variable1 }} - {{ variable2 }} / 100)')); $formula->setParameter('variable1', 10); $formula->setParameter('variable2', 13); echo $formula->render(); // (10 - 13 / 100) + 13
数学运算
如上所示加常数Formula::CALCULABLE
,它将使用Hoa\Math
算术语法来评估您的操作。示例
use Rezzza\Formulate\Formula; $formula = new Formula('{{ subformula1 }} + {{ variable2 }}'); $formula->setSubFormula('subformula1', new Formula('(30 / 2) * -10', Formula::CALCULABLE)); $formula->setParameter('variable2', '10'); echo $formula->render(); // -150 + 10 $formula->setIsCalculable(true); echo $formula->render(); // -140
查看Hoa Math存储库。
测试
php composer install --dev bin/atoum -d tests/units
待办事项
- 添加更多测试