forked from slot/factual-php-driver
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFieldFilter.php
38 lines (30 loc) · 805 Bytes
/
FieldFilter.php
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
<?php
class FieldFilter implements FactualFilter {
private $fieldName; //string
private $op; //sting
private $arg; //obj
/**
* Creates filters on specific field criteria
* @param string op Operator
* @param string fieldName Field Name
* @param string object Argument
*/
public function __construct($op, $fieldName, $arg) {
$this->op = $op;
$this->fieldName = $fieldName;
$this->arg = $arg;
return true;
}
/**
* Produces JSON representation of the represented filter logic. For example:
* <pre>
* {"first": {"$eq":"Jack"}}
* {"first": {"$in":["a, b, c"]}}
* </pre>
* @return string
*/
public function toJsonStr() {
return "{\"" . $this->fieldName . "\":{\"" . $this->op . "\":" . json_encode($this->arg) . "}}";
}
}
?>