1 | <?php |
||
23 | class Entities implements EntitiesContract |
||
24 | { |
||
25 | protected $client; |
||
26 | protected $mapper; |
||
27 | |||
28 | public function __construct(GuzzleClient $client, MapperContract $mapper) |
||
33 | |||
34 | /** |
||
35 | * Get countries. |
||
36 | * |
||
37 | * @param array $parameters |
||
38 | * @return Collection |
||
39 | */ |
||
40 | public function getCountries(array $parameters = []): Collection |
||
44 | |||
45 | /** |
||
46 | * Get currencies. |
||
47 | * |
||
48 | * @param array $parameters |
||
49 | * @return Collection |
||
50 | */ |
||
51 | public function getCurrencies(array $parameters = []): Collection |
||
55 | |||
56 | /** |
||
57 | * Get products. |
||
58 | * |
||
59 | * @param array $parameters |
||
60 | * @return Collection |
||
61 | */ |
||
62 | public function getProducts(array $parameters = []): Collection |
||
66 | |||
67 | /** |
||
68 | * Get country by id. |
||
69 | * |
||
70 | * @param int $id |
||
71 | * @param array $parameters |
||
72 | * @return Country|null |
||
73 | */ |
||
74 | public function getCountry(int $id, array $parameters = []): ?Country |
||
78 | |||
79 | /** |
||
80 | * Get currency by id. |
||
81 | * |
||
82 | * @param int $id |
||
83 | * @param array $parameters |
||
84 | * @return Currency|null |
||
85 | */ |
||
86 | public function getCurrency(int $id, array $parameters = []): ?Currency |
||
90 | |||
91 | /** |
||
92 | * Get product by id. |
||
93 | * |
||
94 | * @param int $id |
||
95 | * @param array $parameters |
||
96 | * @return Product|null |
||
97 | */ |
||
98 | public function getProduct(int $id, array $parameters = []): ?Product |
||
102 | |||
103 | /** |
||
104 | * Get site by product id. |
||
105 | * |
||
106 | * @param int $productId |
||
107 | * @param array $parameters |
||
108 | * @return Site|null |
||
109 | */ |
||
110 | public function getSite(int $productId, array $parameters = []): ?Site |
||
117 | |||
118 | /** |
||
119 | * Get merchant by product id. |
||
120 | * |
||
121 | * @param int $productId |
||
122 | * @param array $parameters |
||
123 | * @return Merchant|null |
||
124 | */ |
||
125 | public function getMerchant(int $productId, array $parameters = []): ?Merchant |
||
132 | |||
133 | /** |
||
134 | * Get entities list. |
||
135 | * |
||
136 | * @param string $entityName |
||
137 | * @param array $params |
||
138 | * @return stdClass |
||
139 | */ |
||
140 | public function getList(string $entityName, array $params = []): stdClass |
||
146 | |||
147 | /** |
||
148 | * Get entity. |
||
149 | * |
||
150 | * @param string $entityName |
||
151 | * @param $id |
||
152 | * @param array $params |
||
153 | * @return stdClass |
||
154 | */ |
||
155 | public function get(string $entityName, $id, array $params = []): stdClass |
||
161 | |||
162 | /** |
||
163 | * Get entity as collection. |
||
164 | * |
||
165 | * @param string $className |
||
166 | * @param array $params |
||
167 | * @return Collection |
||
168 | */ |
||
169 | protected function getEntityCollection(string $className, array $params): Collection |
||
178 | |||
179 | protected function getEntity(Entity $entity, $id, array $params): ?Entity |
||
185 | |||
186 | protected function makeGetRequest(string $url, array $params): stdClass |
||
190 | |||
191 | /** |
||
192 | * @param string $method |
||
193 | * @param string $url |
||
194 | * @param array $options |
||
195 | * @return mixed |
||
196 | * @throws RuntimeException |
||
197 | * @throws InvalidArgumentException |
||
198 | */ |
||
199 | protected function makeRequest(string $method, string $url, array $options) |
||
207 | |||
208 | protected function resource(string $className): string |
||
214 | |||
215 | protected function response2Entity($resp, Entity $entity): ?Entity |
||
225 | } |
||
226 |