Vulpo One

Adding Java Style

Оппа, оппа, Java Style

Что делает эта программа?

 1<?php
 2
 3use SimplePHPEasyPlus\Number\NumberCollection;
 4use SimplePHPEasyPlus\Number\SimpleNumber;
 5use SimplePHPEasyPlus\Number\CollectionItemNumberProxy;
 6use SimplePHPEasyPlus\Parser\SimpleNumberStringParser;
 7use SimplePHPEasyPlus\Iterator\CallbackIterator;
 8use SimplePHPEasyPlus\Operator\AdditionOperator;
 9use SimplePHPEasyPlus\Operation\ArithmeticOperation;
10use SimplePHPEasyPlus\Operation\OperationStream;
11use SimplePHPEasyPlus\Engine;
12use SimplePHPEasyPlus\Calcul\Calcul;
13use SimplePHPEasyPlus\Calcul\CalculRunner;
14
15
16$numberCollection = new NumberCollection();
17
18$numberParser = new SimpleNumberStringParser();
19
20$firstParsedNumber = $numberParser->parse('1');
21$firstNumber = new SimpleNumber($firstParsedNumber);
22$firstNumberProxy = new CollectionItemNumberProxy($firstNumber);
23
24$numberCollection->add($firstNumberProxy);
25
26$secondParsedNumber = $numberParser->parse('1');
27$secondNumber = new SimpleNumber($secondParsedNumber);
28$secondNumberProxy = new CollectionItemNumberProxy($secondNumber);
29
30$numberCollection->add($secondNumberProxy);
31
32$addition = new AdditionOperator('SimplePHPEasyPlus\Number\SimpleNumber');
33
34$operation = new ArithmeticOperation($addition);
35
36$engine = new Engine($operation);
37
38$calcul = new Calcul($engine, $numberCollection);
39
40$runner = new CalculRunner();
41
42$runner->run($calcul);
43
44$result = $calcul->getResult();
45$numericResult = $result->getValue(); // 2

Она вычисляет 1+1!!!

https://habr.com/ru/post/172119/