-
Notifications
You must be signed in to change notification settings - Fork 27
/
ResolveQuery.php
executable file
·65 lines (58 loc) · 1.28 KB
/
ResolveQuery.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
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
<?php
namespace Factual;
/**
* Represents a Factual Resolve query.
* This is a refactoring of the Factual Driver by Aaron: https://github.com/Factual/factual-java-driver
* @author Tyler
*/
class ResolveQuery extends FactualQuery {
const RESPONSETYPE = "ResolveResponse";
private $values = array();
/**
* Whether this lib must perform URL encoding.
* Set to avoid double or absent encoding
*/
const URLENCODE = true;
/**
* Adds name/key pair to query for eventual resolution
* @param string key Attribute name
* @param mixed val Attribute value
* $return object This query object
*/
public function add($key, $val) {
$this->values[$key]=$val;
return $this;
}
/**
* @return string
*/
public function toUrlQuery() {
return $this->urlPair("values", $this->toJsonStr($this->values));
}
/**
* @return string
*/
private function toJsonStr($var) {
try {
return json_encode($this->values);
} catch (\Exception $e) {
throw new \Exception($e);
}
}
private function urlPair($name, $val) {
if ($val != null) {
try {
if (self::URLENCODE){
return $name."=".urlencode($val);
} else {
return $name."=".$val;
}
} catch (\Exception $e) {
throw $e;
}
} else {
return null;
}
}
}
?>