-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathresultFormats.php
79 lines (70 loc) · 1.28 KB
/
resultFormats.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
<?php
class phpSesame_SparqlRes
{
private $xml;
function __construct($responseBody)
{
$this->xml = simplexml_load_string($responseBody);
}
public function getHeaders()
{
$headers = array();
foreach($this->xml->head->variable as $header)
{
$headers[] = (string) $header['name'];
}
return $headers;
}
/**
* Returns the rows in an array format, false if there are no rows.
*
* @return mixed
*/
public function getRows()
{
$rows = array();
foreach($this->xml->results->result as $result)
{
$row = array();
foreach($result->binding as $binding)
{
$name = (string) $binding['name'];
if($binding->literal)
{
$row[$name] = (string) $binding->literal;
$row[$name . '_type'] = 'literal';
}
else if($binding->uri)
{
$row[$name] = (string) $binding->uri;
$row[$name . '_type'] = 'uri';
}
else if($binding->bnode)
{
$row[$name] = (string) $binding->bnode;
$row[$name . '_type'] = 'bnode';
}
}
$rows[] = $row;
}
if(sizeof($rows) <= 0)
{
return false;
}
return $rows;
}
/**
* Returns whether the result contains any rows
*
* @return bool
*/
public function hasRows()
{
foreach($this->xml->results->result as $result)
{
return true;
}
return false;
}
}
?>