Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Dadata
- {
- public function suggest($type, $fields)
- {
- $result = false;
- if ($ch = curl_init("http://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/$type"))
- {
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json',
- 'Accept: application/json',
- 'Authorization: Token ertert'
- ));
- curl_setopt($ch, CURLOPT_POST, 1);
- // json_encode
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
- $result = curl_exec($ch);
- $result = json_decode($result);
- curl_close($ch);
- }
- return $result;
- }
- public function getFirstElement($type, $fields)
- {
- $result = $this->suggest($type, $fields);
- return $result[0];
- }
- }
- // Как сделать так?
- $dadata = new Dadata();
- $dadata->suggest($type, $fields)->first(); // Должен возвратить первый элемент массива. Как getFirstElement выше
- $dadata->suggest($type, $fields)->all(); // Должен возвратить весь результат, как suggest выше
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement