Vulpo One

Adding Java Style

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

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

 1 <?php
 2 
 3 use SimplePHPEasyPlus\Number\NumberCollection;
 4 use SimplePHPEasyPlus\Number\SimpleNumber;
 5 use SimplePHPEasyPlus\Number\CollectionItemNumberProxy;
 6 use SimplePHPEasyPlus\Parser\SimpleNumberStringParser;
 7 use SimplePHPEasyPlus\Iterator\CallbackIterator;
 8 use SimplePHPEasyPlus\Operator\AdditionOperator;
 9 use SimplePHPEasyPlus\Operation\ArithmeticOperation;
10 use SimplePHPEasyPlus\Operation\OperationStream;
11 use SimplePHPEasyPlus\Engine;
12 use SimplePHPEasyPlus\Calcul\Calcul;
13 use 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/

Comments