|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace MoveMoveIo\DaData; |
| 4 | + |
| 5 | +use MoveMoveIo\DaData\Enums\Language; |
| 6 | + |
| 7 | +/** |
| 8 | + * Class DaDataAddressService |
| 9 | + * @package MoveMoveIo\DaData |
| 10 | + */ |
| 11 | +class DaDataAddressService extends DaDataService |
| 12 | +{ |
| 13 | + |
| 14 | + /** |
| 15 | + * Standardization address from string to FIAS address object |
| 16 | + * |
| 17 | + * Splits an address from a string into fields (region, city, street, house, apartment) |
| 18 | + * according to KLADR/FIAS. Determines the postal code, time zone, nearest subway stations, |
| 19 | + * coordinates, apartment cost and other information about the address. |
| 20 | + * |
| 21 | + * @param string $address |
| 22 | + * @return array |
| 23 | + * @throws \Exception |
| 24 | + */ |
| 25 | + public function standardization(string $address) : array |
| 26 | + { |
| 27 | + return $this->cleanerApi()->post('clean/address', [$address]); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Auto detection by part of address |
| 32 | + * |
| 33 | + * Helps the person quickly enter the correct address on a web form or app. |
| 34 | + * For Russian Federation and the whole world. |
| 35 | + * |
| 36 | + * @param string $query |
| 37 | + * @param int $count |
| 38 | + * @param int $language |
| 39 | + * @param array $locations |
| 40 | + * @param array $locations_geo |
| 41 | + * @param array $locations_boost |
| 42 | + * @param array $from_bound |
| 43 | + * @param array $to_bound |
| 44 | + * @return array |
| 45 | + * @throws \Exception |
| 46 | + */ |
| 47 | + public function prompt( |
| 48 | + string $query, |
| 49 | + int $count = 10, |
| 50 | + int $language = Language::RU, |
| 51 | + array $locations = [], |
| 52 | + array $locations_geo = [], |
| 53 | + array $locations_boost = [], |
| 54 | + array $from_bound = [], |
| 55 | + array $to_bound = [] |
| 56 | + ) : array |
| 57 | + { |
| 58 | + |
| 59 | + return $this->suggestApi()->post('rs/suggest/address', [ |
| 60 | + 'query' => $query, |
| 61 | + 'count' => $count, |
| 62 | + 'language' => Language::$map[$language] ?? Language::$map[Language::RU], |
| 63 | + 'locations' => $locations, |
| 64 | + 'locations_geo' => $locations_geo, |
| 65 | + 'locations_boost' => $locations_boost, |
| 66 | + 'from_bound' => $from_bound, |
| 67 | + 'to_bound' => $to_bound, |
| 68 | + ]); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * GEOcoding |
| 73 | + * |
| 74 | + * Determines coordinates by address from a string. At the same time it returns the |
| 75 | + * postal code and, in general, all data on the address |
| 76 | + * |
| 77 | + * @param string $address |
| 78 | + * @return array |
| 79 | + * @throws \Exception |
| 80 | + */ |
| 81 | + public function geocoding(string $address) : array |
| 82 | + { |
| 83 | + return $this->cleanerApi()->post(''. [$address]); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Revert GEOcoding |
| 88 | + * |
| 89 | + * Returns all information about the address by coordinates. |
| 90 | + * Works for homes, streets and cities. |
| 91 | + * |
| 92 | + * @param string $address |
| 93 | + * @return array |
| 94 | + * @throws \Exception |
| 95 | + */ |
| 96 | + public function revertGeocoding(string $address) : array |
| 97 | + { |
| 98 | + return $this->cleanerApi()->post(''. [$address]); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Define city by IPv4 |
| 103 | + * |
| 104 | + * @param string $ipv4 |
| 105 | + * @return array |
| 106 | + * @throws \Exception |
| 107 | + */ |
| 108 | + public function ipv4coding(string $ipv4) : array |
| 109 | + { |
| 110 | + return $this->cleanerApi()->post(''. [$ipv4]); |
| 111 | + } |
| 112 | + |
| 113 | +} |
0 commit comments