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

This package is not auto-updated.

Last update: 2024-04-22 05:42:58 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,
  ]
  // ...
]