|
10 | 10 |
|
11 | 11 | abstract class Resource |
12 | 12 | { |
13 | | - /** @var Hal\Resource $resource */ |
14 | 13 | protected $resource; |
15 | | - /** @var ArrayProxy $state */ |
16 | 14 | protected $state; |
17 | | - |
18 | | - protected static $href; |
19 | 15 | protected $client; |
20 | | -// protected static $client; |
| 16 | + protected static $href; |
21 | 17 | protected static $registry; |
22 | 18 |
|
23 | 19 | /** |
@@ -105,18 +101,29 @@ public function __isset($name) |
105 | 101 | * @throws Hal\Exception\HalRedirectionException |
106 | 102 | * @throws Hal\Exception\HalServerErrorException |
107 | 103 | */ |
108 | | - public static function retrieve($id) |
| 104 | + public static function retrieve($id_or_url) |
109 | 105 | { |
110 | | - $uri = self::getHrefSpec()->collection_uri . '/' . $id; |
| 106 | + |
| 107 | + $uri = filter_var($id_or_url, FILTER_VALIDATE_URL) || (strpos($id_or_url, '/') !== false) ? |
| 108 | + $id_or_url : self::getHrefSpec()->collection_uri . '/' . $id_or_url; |
111 | 109 | $resource = Bootstrap::createClient()->sendRequest(new Request($uri)); |
112 | 110 | $class = get_called_class(); |
113 | | - return new $class($resource->getState(), $resource->getAllLinks()); |
| 111 | + $state = $resource->getState(); |
| 112 | + if (sizeof($resource->getAllEmbeddedResources()) > 0) { |
| 113 | + $items = $resource->getAllEmbeddedResources(); |
| 114 | + $items = reset($items); |
| 115 | + if (sizeof($items) == 1) { |
| 116 | + $state = $items[0]->getState(); |
| 117 | + } |
| 118 | + } |
| 119 | + return new $class($state, $resource->getAllLinks()); |
114 | 120 | } |
115 | 121 |
|
116 | | - public static function getPagination($href) |
| 122 | + public static function getPagination($resource) |
117 | 123 | { |
118 | | - $resource = Bootstrap::createClient()->sendRequest(new Request($href)); |
119 | | - return new Pagination($resource, get_called_class()); |
| 124 | + $cls = get_called_class(); |
| 125 | + $halResource = Bootstrap::createClient()->sendRequest(new Request($resource->getHref($cls::getHrefSpec()->name))); |
| 126 | + return new Pagination($halResource, $cls); |
120 | 127 | } |
121 | 128 |
|
122 | 129 | public function refresh() |
|
0 commit comments