elk-president / calc-component
Component receives string with numbers and math operators and returns result or error.
dev-master
2019-10-27 14:29 UTC
Requires
- php: >=5.4.0
- nxp/math-executor: ^0.8.0
- yiisoft/yii2: ~2.0.14
Requires (Dev)
- codeception/base: ~2.3.0
- codeception/specify: ~0.4.6
- codeception/verify: ~0.4.0
This package is not auto-updated.
Last update: 2025-03-24 10:12:10 UTC
README
behaviors/ contains component behavior classes
config/ contains application configurations
models/ contains model classes
tests/ contains various tests for the basic application
vendor/ contains dependent 3rd-party packages
WORK WORK
Installation
composer require elk-president/calc-component:"dev-master"
Testing
vendor/bin/codecept run
Basic usage
use elkpresident\calccomponent\CalcComponent;
/** $input is your string to be parsed */
$calcComponent = new CalcComponent();
$calcComponent->processMathString($input)
/** In case you need custom behavior */
class YourCalcBehavior extends yii\base\Behavior
{
public function calc($argument)
{
$executor = new YourCalculationClass();
return $executor->yourCalculationClassMethod($argument);
}
}
$calcComponent = new CalcComponent([
'calcBehavior' => YourCalcBehavior
]);
$calcComponent->processMathString($input)
/** Or in Yii app config */
'components' => [
// ...
'calc' => [
'class' => 'elkpresident\calccomponent\CalcComponent',
'calcBehavior' => YourCalcBehavior,
]
// ...
]