1 | <?php |
||
23 | class Entities implements EntitiesContract |
||
24 | { |
||
25 | protected $client; |
||
26 | protected $mapper; |
||
27 | |||
28 | protected $resources = [ |
||
29 | Country::class => 'countries', |
||
30 | Currency::class => 'currencies', |
||
31 | Merchant::class => 'merchants', |
||
32 | Product::class => 'products', |
||
33 | Site::class => 'sites', |
||
34 | Agent::class => 'agents', |
||
35 | ]; |
||
36 | |||
37 | public function __construct(GuzzleClient $client, MapperContract $mapper) |
||
42 | |||
43 | /** |
||
44 | * Get countries. |
||
45 | * |
||
46 | * @param array $parameters |
||
47 | * @return Collection |
||
48 | */ |
||
49 | public function getCountries(array $parameters = []): Collection |
||
53 | |||
54 | /** |
||
55 | * Get currencies. |
||
56 | * |
||
57 | * @param array $parameters |
||
58 | * @return Collection |
||
59 | */ |
||
60 | public function getCurrencies(array $parameters = []): Collection |
||
64 | |||
65 | /** |
||
66 | * Get products. |
||
67 | * |
||
68 | * @param array $parameters |
||
69 | * @return Collection |
||
70 | */ |
||
71 | public function getProducts(array $parameters = []): Collection |
||
75 | |||
76 | /** |
||
77 | * Get agents. |
||
78 | * |
||
79 | * @param array $parameters |
||
80 | * @return Collection |
||
81 | */ |
||
82 | public function getAgents(array $parameters = []): Collection |
||
86 | |||
87 | /** |
||
88 | * Get country by id. |
||
89 | * |
||
90 | * @param int $id |
||
91 | * @param array $parameters |
||
92 | * @return Country|null |
||
93 | */ |
||
94 | public function getCountry(int $id, array $parameters = []): ?Country |
||
98 | |||
99 | /** |
||
100 | * Get currency by id. |
||
101 | * |
||
102 | * @param int $id |
||
103 | * @param array $parameters |
||
104 | * @return Currency|null |
||
105 | */ |
||
106 | public function getCurrency(int $id, array $parameters = []): ?Currency |
||
110 | |||
111 | /** |
||
112 | * Get product by id. |
||
113 | * |
||
114 | * @param int $id |
||
115 | * @param array $parameters |
||
116 | * @return Product|null |
||
117 | */ |
||
118 | public function getProduct(int $id, array $parameters = []): ?Product |
||
122 | |||
123 | /** |
||
124 | * Get site by product id. |
||
125 | * |
||
126 | * @param int $productId |
||
127 | * @param array $parameters |
||
128 | * @return Site|null |
||
129 | */ |
||
130 | public function getSite(int $productId, array $parameters = []): ?Site |
||
137 | |||
138 | /** |
||
139 | * Get merchant by product id. |
||
140 | * |
||
141 | * @param int $productId |
||
142 | * @param array $parameters |
||
143 | * @return Merchant|null |
||
144 | */ |
||
145 | public function getMerchant(int $productId, array $parameters = []): ?Merchant |
||
152 | |||
153 | /** |
||
154 | * Get entities list. |
||
155 | * |
||
156 | * @param string $entityName |
||
157 | * @param array $params |
||
158 | * @return stdClass |
||
159 | */ |
||
160 | public function getList(string $entityName, array $params = []): stdClass |
||
166 | |||
167 | /** |
||
168 | * Get entity. |
||
169 | * |
||
170 | * @param string $entity |
||
171 | * @param $id |
||
172 | * @param array $params |
||
173 | * @return stdClass |
||
174 | */ |
||
175 | public function get(string $entity, $id, array $params = []): stdClass |
||
181 | |||
182 | /** |
||
183 | * Get entity as collection. |
||
184 | * |
||
185 | * @param string $className |
||
186 | * @param array $params |
||
187 | * @return Collection |
||
188 | */ |
||
189 | protected function getEntityCollection(string $className, array $params): Collection |
||
198 | |||
199 | protected function getEntity(Entity $entity, $id, array $params): ?Entity |
||
205 | |||
206 | protected function makeGetRequest(string $url, array $params): stdClass |
||
210 | |||
211 | /** |
||
212 | * @param string $method |
||
213 | * @param string $url |
||
214 | * @param array $options |
||
215 | * @return mixed |
||
216 | * @throws RuntimeException |
||
217 | * @throws InvalidArgumentException |
||
218 | */ |
||
219 | protected function makeRequest(string $method, string $url, array $options) |
||
227 | |||
228 | protected function response2Entity($resp, Entity $entity): ?Entity |
||
238 | } |
||
239 |