1 | <?php |
||
12 | class LogicalOpFactory implements FactoryInterface |
||
13 | { |
||
14 | protected $factory; |
||
15 | |||
16 | /** |
||
17 | * Factory constructor |
||
18 | * @param FactoryInterface|null $factory |
||
19 | * @return FactoryInterface |
||
|
|||
20 | */ |
||
21 | public function __construct($factory = null) |
||
25 | |||
26 | /** |
||
27 | * Factory factory |
||
28 | * @return FactoryInterface |
||
29 | */ |
||
30 | public static function get() |
||
34 | |||
35 | /** |
||
36 | * Create an operator or a set of operators from the expression. |
||
37 | * |
||
38 | * @param string $expression |
||
39 | * @return OperatorInterface |
||
40 | */ |
||
41 | public function evaluate($expression, $default_field = false) |
||
55 | |||
56 | /** |
||
57 | * Given an expression in a form similar to 'a=b&c=d|x=y', |
||
58 | * produce a result as : |
||
59 | * |
||
60 | * [ |
||
61 | * [ |
||
62 | * 0 => 'a=b', |
||
63 | * 1 => '', |
||
64 | * 2 => 'a=b', |
||
65 | * ], |
||
66 | * [ |
||
67 | * 0 => '&&c=d', |
||
68 | * 1 => '&&', |
||
69 | * 2 => 'c=d', |
||
70 | * ], |
||
71 | * [ |
||
72 | * 0 => '||x=y', |
||
73 | * 1 => '||', |
||
74 | * 2 => 'x=y', |
||
75 | * ], |
||
76 | * ] |
||
77 | * |
||
78 | * This is the data structure returned by the former preg_match_all call |
||
79 | * used, which was: |
||
80 | * |
||
81 | * preg_match_all('#([&|]*)([^&|]+)#', $expression, $exprSet, PREG_SET_ORDER) |
||
82 | * |
||
83 | * The new algorithm splices the expressions together manually, as it was |
||
84 | * difficult to get preg_match_all to match && and || reliably. |
||
85 | * |
||
86 | * @param string $expression |
||
87 | * @return array |
||
88 | */ |
||
89 | protected function splitByLogicOp($expression) |
||
104 | |||
105 | /** |
||
106 | * Given the left-hand-side operator, a logical operator, and a |
||
107 | * string expression, create the right-hand-side operator and combine |
||
108 | * it with the provided lhs operator. |
||
109 | * |
||
110 | * @param Operator|false $lhs Left-hand-side operator |
||
111 | * @param string $logicOp '&' or '|' |
||
112 | * @param OperatorInterface $rhs Right-hand-side operator |
||
113 | * @return Operator |
||
114 | */ |
||
115 | protected function combineUsingLogicalOp($lhs, $logicOp, OperatorInterface $rhs) |
||
126 | |||
127 | /** |
||
128 | * Given the left-hand-side operator, a logical operator, and a |
||
129 | * string expression, create the right-hand-side operator and combine |
||
130 | * it with the provided lhs operator. |
||
131 | * |
||
132 | * @param Operator|false $lhs Left-hand-side operator |
||
133 | * @param string $logicOp '&' or '|' |
||
134 | * @param OperatorInterface $rhs Right-hand-side operator |
||
135 | * @return Operator |
||
136 | */ |
||
137 | protected function createLogicalOp(OperatorInterface $lhs, $logicOp, OperatorInterface $rhs) |
||
147 | } |
||
148 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.