PHP code example of glendemon / dadata-suggestions
1. Go to this page and download the library: Download glendemon/dadata-suggestions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
glendemon / dadata-suggestions example snippets
$service = new \DadataSuggestions\DadataSuggestionsService();
$service->setUrl('https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/');
$service->setToken('...');
public function testSuggestAddressFlat()
{
$service = $this->getService();
$response = $service->suggestAddress('мск балтийская 6к1 5');
foreach ($response->getSuggestions() as $suggestion) {
$this->assertEquals('г Москва, ул Балтийская, д 6 к 1, кв 5', $suggestion->getValue());
$this->assertEquals('г Москва, ул Балтийская, д 6 к 1, кв 5', $suggestion->getUnrestrictedValue());
$data = $suggestion->getData();
$this->assertInstanceOf(\DadataSuggestions\Data\Address::class, $data);
$this->assertEquals('Россия', $data->country);
$this->assertEquals('Москва', $data->city);
$this->assertEquals('ул Балтийская', $data->street_with_type);
$this->assertEquals('6', $data->house);
$this->assertEquals('1', $data->block);
$this->assertEquals('5', $data->flat);
}
}
/**
* @return \DadataSuggestions\DadataSuggestionsService
*/
protected function getService()
{
$service = new \DadataSuggestions\DadataSuggestionsService();
$service->setToken('...');
return $service;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.