|
1
|
|
|
<?php |
|
2
|
|
|
namespace ApigilityClient\Resource; |
|
3
|
|
|
|
|
4
|
|
|
use Level3\Resource\Resource as Level3Resource, |
|
5
|
|
|
Level3\Resource\Link as Level3Link; |
|
6
|
|
|
|
|
7
|
|
|
use ApigilityClient\Exception\RuntimeException, |
|
8
|
|
|
ApigilityClient\Resource\Pagination, |
|
9
|
|
|
ApigilityClient\Resource\Content; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class Resource |
|
13
|
|
|
{ |
|
14
|
|
|
private $uri = ''; |
|
15
|
|
|
|
|
16
|
|
|
private $pagination; |
|
17
|
|
|
|
|
18
|
|
|
private $links; |
|
19
|
|
|
|
|
20
|
|
|
private $data = array(); |
|
21
|
|
|
|
|
22
|
2 |
|
public function __construct(Level3Resource $resource) |
|
23
|
|
|
{ |
|
24
|
2 |
|
$this->config($resource); |
|
25
|
2 |
|
} |
|
26
|
|
|
|
|
27
|
2 |
|
private function config(Level3Resource $resource) |
|
28
|
|
|
{ |
|
29
|
2 |
|
$this->setUri($resource->getUri()); |
|
30
|
2 |
|
$this->setLinks($resource->getAllLinks()); |
|
31
|
2 |
|
$this->setPagination($resource->getData()); |
|
32
|
2 |
|
$this->setData($resource); |
|
33
|
2 |
|
} |
|
34
|
|
|
|
|
35
|
2 |
|
private function setUri($input) |
|
36
|
|
|
{ |
|
37
|
2 |
|
$this->uri = (string) $input; |
|
38
|
|
|
|
|
39
|
2 |
|
return $this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getUri() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->uri; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
2 |
|
private function setLinks(array $links) |
|
48
|
|
|
{ |
|
49
|
2 |
|
$links['self'] = new Level3Link($this->uri); |
|
50
|
|
|
|
|
51
|
2 |
|
$this->links = new Links($links); |
|
52
|
|
|
|
|
53
|
2 |
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
1 |
|
public function getLinks() |
|
57
|
|
|
{ |
|
58
|
1 |
|
return $this->links; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
2 |
|
private function setPagination(array $input) |
|
62
|
|
|
{ |
|
63
|
2 |
|
$this->pagination = new Pagination($input); |
|
64
|
|
|
|
|
65
|
2 |
|
return $this; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
1 |
|
public function getPagination() |
|
69
|
|
|
{ |
|
70
|
1 |
|
return $this->pagination; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
2 |
|
public function isCollection() |
|
74
|
|
|
{ |
|
75
|
2 |
|
return (bool) ($this->pagination->getPageSize() > 0); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
2 |
|
private function setData(Level3Resource $input) |
|
79
|
|
|
{ |
|
80
|
2 |
|
if ($this->isCollection()) { |
|
81
|
2 |
|
$resources = $input->getAllResources(); |
|
82
|
2 |
|
foreach ($resources as $keyContent) { |
|
83
|
2 |
|
foreach ($keyContent as $resource) { |
|
84
|
2 |
|
$this->data[] = $resource->getData(); |
|
85
|
2 |
|
} |
|
86
|
2 |
|
} |
|
87
|
2 |
|
} else { |
|
88
|
|
|
$this->data[] = $input->getData(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
2 |
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function getData() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->data; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|