1: <?php
2:
3: namespace Scopus\Response;
4:
5: class SearchResults
6: {
7: /** @var array */
8: protected $data;
9:
10: /** @var SearchLinks */
11: protected $links;
12:
13: /** @var Entry[] */
14: protected $entries;
15:
16: public function __construct(array $data)
17: {
18: $this->data = $data;
19: }
20:
21: public function getTotalResults()
22: {
23: return $this->data['opensearch:totalResults'];
24: }
25:
26: public function getStartIndex()
27: {
28: return $this->data['opensearch:startIndex'];
29: }
30:
31: public function getItemsPerPage()
32: {
33: return $this->data['opensearch:itemsPerPage'];
34: }
35:
36: public function getQuery()
37: {
38: return $this->data['opensearch:Query'];
39: }
40:
41: public function getNextCursor()
42: {
43: return $this->data['cursor']['@next'];
44: }
45:
46: public function getLinks()
47: {
48: return $this->links ?: $this->links = new SearchLinks($this->data['link']);
49: }
50:
51: /**
52: * @return Entry[]
53: */
54: public function getEntries()
55: {
56: if (isset($this->data['entry'])) {
57: return $this->entries ?: $this->entries = array_map(function ($entry) {
58: return new Entry($entry);
59: }, $this->data['entry']);
60: }
61: }
62:
63: public function countEntries()
64: {
65: return isset($this->data['entry']) ? count($this->data['entry']) : 0;
66: }
67: }
68: