-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path111-AddressMatch.php
More file actions
83 lines (71 loc) · 2.6 KB
/
111-AddressMatch.php
File metadata and controls
83 lines (71 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Example how to use the AddressMatch service method.
*
* @var string $apiEndpoint
* @var string $apiUserKey
* @var string $apiKey
* @var \Symfony\Component\Console\Output\ConsoleOutput $output
*/
use DigipolisGent\Flanders\BasicRegisters\BasicRegister;
use DigipolisGent\Flanders\BasicRegisters\Client\Client;
use DigipolisGent\Flanders\BasicRegisters\Configuration\Configuration;
use DigipolisGent\Flanders\BasicRegisters\Filter\BusNumberFilter;
use DigipolisGent\Flanders\BasicRegisters\Filter\Filters;
use DigipolisGent\Flanders\BasicRegisters\Filter\HouseNumberFilter;
use DigipolisGent\Flanders\BasicRegisters\Filter\MunicipalityNameFilter;
use DigipolisGent\Flanders\BasicRegisters\Filter\PostalCodeFilter;
use DigipolisGent\Flanders\BasicRegisters\Filter\StreetNameFilter;
use Symfony\Component\Console\Helper\Table;
require_once __DIR__ . '/bootstrap.php';
printTitle('Get a list of all addresses in Gent with belle in the street name.');
printStep('Create the API client configuration.');
$configuration = new Configuration($apiEndpoint, $apiUserKey, $apiKey);
printStep('Create the Guzzle client.');
$guzzleClient = new GuzzleHttp\Client(['base_uri' => $configuration->getUri()]);
printStep('Create the HTTP client.');
$client = new Client($guzzleClient, $configuration);
printStep('Create the Service wrapper.');
$service = new BasicRegister($client);
printStep('Create the filters.');
$filters = new Filters(
new MunicipalityNameFilter('gent'),
new PostalCodeFilter(9000),
new StreetNameFilter('Ter Platen'),
new HouseNumberFilter(64),
new BusNumberFilter('')
);
printStep('List of address that match the search.');
$addressMatches = $service->address()->match($filters);
$table = new Table($output);
$table->setHeaders(
[
'Match',
'Address ID',
'Municipality (ID)',
'Street name (ID)',
'Score',
]
);
foreach ($addressMatches as $addressMatch) {
/** @var \DigipolisGent\Flanders\BasicRegisters\Value\Address\AddressMatch $addressMatch */
$table->addRow(
[
(string) $addressMatch,
$addressMatch->addressDetail() ? (string) $addressMatch->addressDetail()->addressId() : 'NA',
sprintf(
'%s (%s)',
$addressMatch->municipalityName(),
$addressMatch->municipalityName()->municipalityNameId()
),
sprintf(
'%s (%s)',
$addressMatch->streetName(),
$addressMatch->streetName()->streetNameId()
),
$addressMatch->score(),
]
);
}
$table->render();
printFooter();