Download the PHP package black/address without Composer
On this page you can find all versions of the php package black/address. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download black/address
More information about black/address
Files in black/address
Package address
Short Description PHP 5.4+ library to make working with Address safer, easier, and fun
License MIT
Homepage http://www.lablackroom.com
Informations about the package address
Address
PHP 5.4+ library to make working with Addresses safer, easier, and fun!
Installation
The recommended way to install Address is through Composer:
Protip: You should browse the black/address
page to choose a stable version to use, avoid the @stable
meta
constraint.
Usage
Usage of this class is simple. A complete Postal address is based on a street (number and name), a postal code and a locality. But we also need region, post office box number and country so a complete Postal address should use all this fields.
We have 3 value objects for a complete Postal Address.
Country
A country is composed by a code and a name. This code is an ISO 3166-1 alpha-2 code and the name is in english.
Exemple
It is possible to create a Country object with two static functions.
Available functions
::buildFromISOCode($code)
::buildFromName($name)
->getName()
->getCode()
->getValue()
->getValueAsArray()
->isEqualTo($country)
Exception
An Address\InvalidCountryException()
will be thrown if code or name is not found in Resources\countries.php
Street
A street is composed by a number and a name.
Exemple
Available functions
->getNumber()
->getName()
->getValue($separator)
->getValueAsArray()
->isEqualTo($street)
PostalAddress
PostalAddress is the main Value Object. He needs all the informations but an empty string is allowed.
Available functions
->getStreet()
->getStreetName()
->getStreetNumber()
->getPostalCode()
->getLocality()
->getRegion()
->getPostOfficeBoxNumber()
->getCountry()
->getCountryCode()
->getCountryName()
->getValue()
Return an array
Formatters
Ok now, you have a complete Postal Address but somewhere in your brain, you say:
Oh fuck, sometimes I don't have any region or post-office box and addresses are not written in France or in US with the same order and...
Don't panic, there is a formatter for that!
Three formatters are available with the same ->format()
function:
- Address\Formatter\CountryFormatter
- Address\Formatter\StreetFormatter
- Address\Formatter\PostalAddressFormatter
Here is the mapping:
- Street: %S
- Street name: %n
- Street number: %u
- Postal code: %P
- Locality: %L
- Region: %R
- Post Office Box Number: %B
- Country: %C
- Country code: %C
- Country name: %a
And how to use it:
License
Address is released under the MIT License. See the bundled LICENSE file for details.
Contributing
See CONTRIBUTING file.
Credits
This README is heavily inspired by Geocoder library by the great @willdurand. This guy needs your [PR][3] for the sake of the REST in PHP.
Alexandre "pocky" Balmes Flattrs if you love my work, buy me gift or hire me!