SimplePHPEasyPlus: Add up numbers in PHP
In the early stages of the Internet, developers had to use poor, miserable programming languages. I had to use only functions and operators. No objects, no interfaces, no dependency injection!
Say, in order to perform a simple addition operation, our fathers had to write: 1 + 1. Yes seriously.
But now we have PHP 5.3 with excellent OOP implementation! Introducing the SimplePHPEasyPlus Library ! SimplePHPEasyPlus allows you to add two numbers in a modern way, using OOP. It is fast, simple, flexible and tested. To add 1 to 1, you just need to do the following:
The library is suitable for use with production. Enjoy it!
Say, in order to perform a simple addition operation, our fathers had to write: 1 + 1. Yes seriously.
But now we have PHP 5.3 with excellent OOP implementation! Introducing the SimplePHPEasyPlus Library ! SimplePHPEasyPlus allows you to add two numbers in a modern way, using OOP. It is fast, simple, flexible and tested. To add 1 to 1, you just need to do the following:
use SimplePHPEasyPlus\Number\NumberCollection;
use SimplePHPEasyPlus\Number\SimpleNumber;
use SimplePHPEasyPlus\Number\CollectionItemNumberProxy;
use SimplePHPEasyPlus\Parser\SimpleNumberStringParser;
use SimplePHPEasyPlus\Iterator\CallbackIterator;
use SimplePHPEasyPlus\Operator\AdditionOperator;
use SimplePHPEasyPlus\Operation\ArithmeticOperation;
use SimplePHPEasyPlus\Operation\OperationStream;
use SimplePHPEasyPlus\Engine;
use SimplePHPEasyPlus\Calcul\Calcul;
use SimplePHPEasyPlus\Calcul\CalculRunner;
$numberCollection = new NumberCollection();
$numberParser = new SimpleNumberStringParser();
$firstParsedNumber = $numberParser->parse('1');
$firstNumber = new SimpleNumber($firstParsedNumber);
$firstNumberProxy = new CollectionItemNumberProxy($firstNumber);
$numberCollection->add($firstNumberProxy);
$secondParsedNumber = $numberParser->parse('1');
$secondNumber = new SimpleNumber($secondParsedNumber);
$secondNumberProxy = new CollectionItemNumberProxy($secondNumber);
$numberCollection->add($secondNumberProxy);
$addition = new AdditionOperator('SimplePHPEasyPlus\Number\SimpleNumber');
$operation = new ArithmeticOperation($addition);
$engine = new Engine($operation);
$calcul = new Calcul($engine, $numberCollection);
$runner = new CalculRunner();
$runner->run($calcul);
$result = $calcul->getResult();
$numericResult = $result->getValue(); // 2
The library is suitable for use with production. Enjoy it!