rezzza/formulate
最新稳定版本:v1.0.6
Composer 安装命令:
composer require rezzza/formulate
包简介
Making life easier while writing complex math formulas, take a breath
关键字:
README 文档
README
Making life easier while writing complex math formulas, take a breath
Install via composer
# composer.json
"rezzza/formulate": "dev-master"
# shell
php composer.phar update # or install
Usage
<?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
Mathematic operations
Works as above + constant Formula::CALCULABLE, it'll use Hoa\Math arithmetic grammar to evaluate your operation. Example:
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
Look at Hoa Math repository.
Tests
php composer install --dev bin/atoum -d tests/units
Todo
- Add more tests
统计信息
- 总下载量: 35.3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-08-17