Quantcast
Channel: Hacker News 50
Viewing all articles
Browse latest Browse all 9433

Herzult/SimplePHPEasyPlus · GitHub

$
0
0

Comments:"Herzult/SimplePHPEasyPlus · GitHub"

URL:https://github.com/Herzult/SimplePHPEasyPlus


This awesome yet simple and pragmatic PHP library performs an addition of two numbers.

In early stages of Internet, developers were forced to work with poor, dry, functional, horrific languages. Everything had to be done through austere functions and operators. There was no objects. No interfaces. No dependency injection.

For example, to make something as simple as an addition, our dads had to write: 1+1. Yeah, really.

Hopefuly now, we have PHP 5.3 and its solid OOP implementation. SimplePHPEasyPlus lets you make this addition in a more fashionable way, using real OOP. It is fast, simple, flexible and tested. To add 1 to 1, all you have to do is:

useSimplePHPEasyPlus\Number\NumberCollection;useSimplePHPEasyPlus\Number\SimpleNumber;useSimplePHPEasyPlus\Number\CollectionItemNumberProxy;useSimplePHPEasyPlus\Parser\SimpleNumberStringParser;useSimplePHPEasyPlus\Iterator\CallbackIterator;useSimplePHPEasyPlus\Operator\AdditionOperator;useSimplePHPEasyPlus\Operation\ArithmeticOperation;useSimplePHPEasyPlus\Operation\OperationStream;useSimplePHPEasyPlus\Engine;useSimplePHPEasyPlus\Calcul\Calcul;useSimplePHPEasyPlus\Calcul\CalculRunner;$numberCollection=newNumberCollection();$numberParser=newSimpleNumberStringParser();$firstParsedNumber=$numberParser->parse('1');$firstNumber=newSimpleNumber($firstParsedNumber);$firstNumberProxy=newCollectionItemNumberProxy($firstNumber);$numberCollection->add($firstNumberProxy);$secondParsedNumber=$numberParser->parse('1');$secondNumber=newSimpleNumber($secondParsedNumber);$secondNumberProxy=newCollectionItemNumberProxy($secondNumber);$numberCollection->add($secondNumberProxy);$addition=newAdditionOperator('SimplePHPEasyPlus\Number\SimpleNumber');$operation=newArithmeticOperation($addition);$engine=newEngine($operation);$calcul=newCalcul($engine,$numberCollection);$runner=newCalculRunner();$runner->run($calcul);$result=$calcul->getResult();$numericResult=$result->getValue();// 2

This library is now available for production purposes. Enjoy!


Viewing all articles
Browse latest Browse all 9433

Trending Articles