@@ -34,18 +34,18 @@ public function __construct()
34
34
* @param string $expression
35
35
* @return OperatorInterface
36
36
*/
37
- public function evaluate ($ expression )
37
+ public function evaluate ($ expression, $ defaultField = false )
38
38
{
39
39
if ($ expression [0 ] == '! ' ) {
40
- $ op = $ this ->evaluateNonNegated (substr ($ expression , 1 ));
40
+ $ op = $ this ->evaluateNonNegated (substr ($ expression , 1 ), $ defaultField );
41
41
return new NotOp ($ op );
42
42
}
43
- return $ this ->evaluateNonNegated ($ expression );
43
+ return $ this ->evaluateNonNegated ($ expression, $ defaultField );
44
44
}
45
45
46
- protected function evaluateNonNegated ($ expression )
46
+ protected function evaluateNonNegated ($ expression, $ defaultField = false )
47
47
{
48
- list ($ key , $ op , $ comparitor ) = $ this ->splitOnOperator ($ expression );
48
+ list ($ key , $ op , $ comparitor ) = $ this ->splitOnOperator ($ expression, $ defaultField );
49
49
if (empty ($ key ) || empty ($ op )) {
50
50
throw new \Exception ('Could not parse expression ' . $ expression );
51
51
}
@@ -79,8 +79,13 @@ protected function instantiate($key, $op, $comparitor)
79
79
* @param string @expression
80
80
* @return array
81
81
*/
82
- protected function splitOnOperator ($ expression )
82
+ protected function splitOnOperator ($ expression, $ defaultField = false )
83
83
{
84
+ // If there is a default field, then any expression that is missing
85
+ // an operator will be interpreted as "default field contains value".
86
+ if (preg_match ('#^[a-zA-Z0-9_.:-]+$# ' , $ expression ) && ($ defaultField !== false )) {
87
+ return [$ defaultField , '*= ' , $ expression ];
88
+ }
84
89
if (!preg_match ('#([^!~*=]*)(!?~?\*?=)(.*)# ' , $ expression , $ matches )) {
85
90
return ['' , '' , '' ];
86
91
}
0 commit comments