|
1
|
|
|
<?php namespace Scriptotek\Sru; |
|
2
|
|
|
|
|
3
|
|
|
use Danmichaelo\QuiteSimpleXMLElement\QuiteSimpleXMLElement; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Explain response |
|
7
|
|
|
*/ |
|
8
|
|
|
class ExplainResponse extends Response implements ResponseInterface |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var string Server hostname */ |
|
11
|
|
|
public $host; |
|
12
|
|
|
|
|
13
|
|
|
/** @var int Server port */ |
|
14
|
|
|
public $port; |
|
15
|
|
|
|
|
16
|
|
|
/** @var object Server database */ |
|
17
|
|
|
public $database; |
|
18
|
|
|
|
|
19
|
|
|
/** @var array Server indexes */ |
|
20
|
|
|
public $indexes; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Create a new explain response |
|
24
|
|
|
* |
|
25
|
|
|
* @param string $text Raw XML response |
|
26
|
|
|
* @param Client $client SRU client reference (optional) |
|
27
|
|
|
* @param string $url Request URL |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct($text = null, &$client = null, $url = null) |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct($text, $client, $url); |
|
32
|
|
|
|
|
33
|
|
|
$this->indexes = array(); |
|
34
|
|
|
|
|
35
|
|
|
if (is_null($this->response)) { |
|
36
|
|
|
return; |
|
37
|
|
|
} |
|
38
|
|
|
$explain = $this->response->first('/srw:explainResponse/srw:record/srw:recordData/exp:explain'); |
|
39
|
|
|
if (!$explain) { |
|
40
|
|
|
return; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$this->parseExplainResponse($explain); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function parseExplainResponse(QuiteSimpleXMLElement $node) |
|
47
|
|
|
{ |
|
48
|
|
|
$serverInfo = $node->first('exp:serverInfo'); |
|
49
|
|
|
$dbInfo = $node->first('exp:databaseInfo'); |
|
50
|
|
|
$indexInfo = $node->first('exp:indexInfo'); |
|
51
|
|
|
|
|
52
|
|
|
$this->host = $serverInfo->text('exp:host'); |
|
53
|
|
|
$this->port = (int) $serverInfo->text('exp:port'); |
|
54
|
|
|
$this->database = new \StdClass; |
|
55
|
|
|
$this->database->identifier = $serverInfo->text('exp:database'); |
|
56
|
|
|
$this->database->title = $dbInfo->text('exp:title'); |
|
57
|
|
|
$this->database->description = $dbInfo->text('exp:description'); |
|
58
|
|
|
|
|
59
|
|
|
foreach ($indexInfo->xpath('exp:index') as $index) { |
|
60
|
|
|
$ind = new \StdClass; |
|
61
|
|
|
$ind->scan = ($index->attr('scan') == 'true'); |
|
62
|
|
|
$ind->search = ($index->attr('search') == 'true'); |
|
63
|
|
|
$ind->sort = ($index->attr('sort') == 'true'); |
|
64
|
|
|
$ind->title = $index->text('exp:title'); |
|
65
|
|
|
$ind->maps = array(); |
|
66
|
|
|
foreach ($index->xpath('exp:map') as $map) { |
|
67
|
|
|
$set = $map->first('exp:name')->attr('set'); |
|
68
|
|
|
$name = $map->text('exp:name'); |
|
69
|
|
|
$ind->maps[] = $set . '.' . $name; |
|
70
|
|
|
} |
|
71
|
|
|
$this->indexes[] = $ind; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
// TODO |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|