-
Notifications
You must be signed in to change notification settings - Fork 27
/
SchemaResponse.php
93 lines (85 loc) · 2.15 KB
/
SchemaResponse.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
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
<?php
namespace Factual;
/**
* Represents the response from running a schema request against Factual.
* This is a refactoring of the Factual Driver by Aaron: https://github.com/Factual/factual-java-driver
* @author Tyler
* @package Factual
* @license Apache 2.0
*/
class SchemaResponse extends FactualResponse {
protected $json; //string
private $columnSchemas = array(); //array or ColumnSchema objects
private $title; //string
private $searchEnabled; //bool
private $geoEnabled; //bool
private $description; //string
/**
* Parses JSON as array and assigns object values
* @param string json JSON returned from API
* @return array structured JSON
*/
protected function parseJSON($json){
$rootJSON = parent::parseJSON($json);
$this->title = $rootJSON['response']['view']['title'];
$this->description = $rootJSON['response']['view']['description'];
$this->makeColumnSchemas($rootJSON['response']['view']['fields']);
$this->searchEnabled = (bool)$rootJSON['response']['view']['search_enabled'];
$this->geoEnabled = (bool)$rootJSON['response']['view']['geo_enabled'];
return $rootJSON;
}
/**
* Gets objects describing column schemas
*/
protected function makeColumnSchemas($fields) {
foreach ($fields as $column){
$this->columnSchemas[$column['name']] = new FactualColumnSchema($column);
}
}
/**
* @return string
*/
public function getTitle() {
return $this->title;
}
/**
* @return string
*/
public function getDescription() {
return $this->description;
}
/**
* @return bool
*/
public function isSearchEnabled() {
return $this->searchEnabled;
}
/**
* @return bool
*/
public function isGeoEnabled() {
return $this->geoEnabled;
}
/**
* @return int The size of the schema (that is, the number of columns in the
* table)
*/
public function size() {
return $this->count($this->columnSchemas);
}
/**
* Get all column schemas
* @return array
*/
public function getColumnSchemas() {
return $this->columnSchemas;
}
/**
* @param string columnName Column name
* @return array
*/
public function getColumnSchema($columnName) {
return $this->columnSchemas[$columnName];
}
}
?>