-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAddress.php
88 lines (69 loc) · 2.47 KB
/
Address.php
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
84
85
86
87
88
<?php
require '../../vendor/autoload.php';
use CommerceGuys\Addressing\Repository\AddressFormatRepository;
use CommerceGuys\Addressing\Repository\SubdivisionRepository;
use SerendipityHQ\Component\ValueObjects\Address\Address;
echo '<h1>Example usage of PHPValueObjects Address.</h1>';
// ucfirst is applied automatically to find the right setter
$values = [
'countryCode' => 'IT',
'AdministrativeArea' => 'SA',
'Locality' => 'Nocera Inferiore',
'dependentLocality' => '',
'PostalCode' => '84014',
'Street' => 'Piazza la bomba e scappa',
'ExtraLine' => 'Non ce l\'hai fatta'
];
$address = new Address($values);
dump($address);
/**
* As the Value Object doesn't extend Commerceguys/Address library anymore, these features are not longer avaialable.
*
* To get them, use commerceguys/addressing and commerceguys/intl.
*/
/*
echo '<h1>Format the address: US</h1>';
echo '<h2>Default options</h2>';
echo $address->toString();
echo '<h2>Without HTML</h2>';
echo $address->toString(['html' => false]);
echo '<h2>In another locale: DE</h2>';
echo $address->toString(['locale' => 'DE']);
echo '<h2>Using the "pre" tag</h2>';
echo $address->toString(['html_tag' => 'pre']);
echo '<h1>Example usage of PHPValueObjects Address with chineese addresses.</h1>';
// ucfirst is applied automatically to find the right setter
$values = [
'countryCode' => 'CN',
'AdministrativeArea' => 'Taiwan',
'Locality' => 'Taichung City',
'dependentLocality' => 'Xitun District',
'PostalCode' => '407',
'SortingCode' => '',
'AddressLine1' => 'Jingcheng Road, 27',
'AddressLine2' => 'Lane 50',
'Organization' => 'Aerendir Company',
// Recipient's name and surname
'Recipient' => 'Adamo Crespi',
'locale' => 'it'
];
$address = new Address($values);
dump($address);
echo '<h2>In another locale: IT</h2>';
echo $address->toString(['locale' => 'IT']);
echo '<h1>Some other useful features of the CommerceGuys/Addressing library</h1>';
$addressFormatRepository = new AddressFormatRepository();
$subdivisionRepository = new SubdivisionRepository();
// Get the address format for Brazil.
$addressFormat = $addressFormatRepository->get('IT');
// Get the subdivisions for Brazil.
$states = $subdivisionRepository->getAll('IT');
foreach ($states as $state) {
$municipalities = $state->getChildren();
}
// Get the subdivisions for Canada, in French.
$states = $subdivisionRepository->getAll('IT', 0, 'fr');
foreach ($states as $state) {
echo $state->getName();
}
*/