-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.php
More file actions
118 lines (104 loc) · 4.09 KB
/
Factory.php
File metadata and controls
118 lines (104 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* Copyright (c) 2018 Webbing Brasil (http://www.webbingbrasil.com.br)
* All Rights Reserved
*
* This file is part of the NomadLog Portal project.
*
* @project NomadLog Portal
* @file Factory.php
* @author Danilo Andrade <danilo@webbingbrasil.com.br>
* @date 06/03/18 at 18:09
* @copyright Copyright (c) 2018 Webbing Brasil (http://www.webbingbrasil.com.br)
*/
namespace App\MathParser;
use App\MathParser\Contracts\ExpressionContract;
use App\MathParser\Contracts\NullContract;
use App\MathParser\Contracts\VariableContract;
/**
* Class Factory
* @package App\MathParser
*/
final class Factory
{
protected static $operators = [
'App\\MathParser\\Operators\\Logical\\AndOperator',
'App\\MathParser\\Operators\\Logical\\OrOperator',
'App\\MathParser\\Operators\\Logical\\Parameter',
'App\\MathParser\\Operators\\Comparison\\GreaterThan',
'App\\MathParser\\Operators\\Comparison\\GreaterOrEqual',
'App\\MathParser\\Operators\\Comparison\\LessOrEqual',
'App\\MathParser\\Operators\\Comparison\\LessThan',
'App\\MathParser\\Operators\\Comparison\\Equal',
'App\\MathParser\\Operators\\Comparison\\NotEqual',
'App\\MathParser\\Operators\\Arithmetic\\Unary',
'App\\MathParser\\Operators\\Arithmetic\\Addition',
'App\\MathParser\\Operators\\Arithmetic\\Subtraction',
'App\\MathParser\\Operators\\Arithmetic\\Multiplication',
'App\\MathParser\\Operators\\Arithmetic\\Division',
'App\\MathParser\\Operators\\Arithmetic\\Modulus',
'App\\MathParser\\Operators\\Arithmetic\\Power',
'App\\MathParser\\Operators\\Arithmetic\\Abs',
'App\\MathParser\\Operators\\Arithmetic\\Acos',
'App\\MathParser\\Operators\\Arithmetic\\Acosh',
'App\\MathParser\\Operators\\Arithmetic\\Asin',
'App\\MathParser\\Operators\\Arithmetic\\Asinh',
'App\\MathParser\\Operators\\Arithmetic\\Atan',
'App\\MathParser\\Operators\\Arithmetic\\Atanh',
'App\\MathParser\\Operators\\Arithmetic\\Atan2',
'App\\MathParser\\Operators\\Arithmetic\\Cbrt',
'App\\MathParser\\Operators\\Arithmetic\\Ceil',
'App\\MathParser\\Operators\\Arithmetic\\Cos',
'App\\MathParser\\Operators\\Arithmetic\\Cosh',
'App\\MathParser\\Operators\\Arithmetic\\Exp',
'App\\MathParser\\Operators\\Arithmetic\\Floor',
'App\\MathParser\\Operators\\Arithmetic\\Log',
'App\\MathParser\\Operators\\Arithmetic\\Pow',
'App\\MathParser\\Operators\\Arithmetic\\Round',
'App\\MathParser\\Operators\\Arithmetic\\Sin',
'App\\MathParser\\Operators\\Arithmetic\\Sinh',
'App\\MathParser\\Operators\\Arithmetic\\Sqrt',
'App\\MathParser\\Operators\\Arithmetic\\Tan',
'App\\MathParser\\Operators\\Arithmetic\\Tanh',
'App\\MathParser\\Operators\\FixFunction\\FixBase',
'App\\MathParser\\Operators\\FixFunction\\FixMax',
'App\\MathParser\\Operators\\FixFunction\\FixMin',
'App\\MathParser\\Operators\\FixFunction\\FixAvg',
];
/**
* @param mixed $value
* @return Expression
*/
public static function create($value)
{
if ($value instanceof ExpressionContract) {
return $value;
}
if ($value instanceof VariableContract) {
return $value;
}
if($value instanceof NullContract){
return $value;
}
if(empty($value)) {
$expression = new Nullable();
}
if (is_numeric($value)) {
$expression = new Number($value);
}
if (in_array($value, array('(', ')'))) {
$expression = new Parenthesis($value);
}
if (!isset($expression)) {
foreach (self::$operators as $operator) {
if ($operator::SYMBOL == $value) {
$expression = new $operator($value);
}
}
if (!isset($expression)) {
throw new \InvalidArgumentException('Undefined Value ' . $value);
}
}
return $expression;
}
}