PHPackages                             black/address - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. black/address

ActiveLibrary

black/address
=============

PHP 5.4+ library to make working with Address safer, easier, and fun

v1.0.1(11y ago)541MITPHPPHP &gt;=5.4.0

Since Oct 22Pushed 11y ago1 watchersCompare

[ Source](https://github.com/pocky/Address)[ Packagist](https://packagist.org/packages/black/address)[ Docs](http://www.lablackroom.com)[ RSS](/packages/black-address/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Address
=======

[](#address)

PHP 5.4+ library to make working with Addresses safer, easier, and fun!

[![SensioLabsInsight](https://camo.githubusercontent.com/14e5af493ce1dc78be25665d13baa49dc9373b437ccf07afb8c64dfa8903ff36/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f39633431376130622d363637622d343832342d393538382d3731646263323333373239612f6269672e706e67)](https://insight.sensiolabs.com/projects/9c417a0b-667b-4824-9588-71dbc233729a)[![Build Status](https://camo.githubusercontent.com/4956c5983e20f8b934ea5947abe59fac71841ee0004579c794dfe463cba9df92/68747470733a2f2f7472617669732d63692e6f72672f626c61636b2d70726f6a6563742f416464726573732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/black-project/Address)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/61b4ac148eb92a95d3cc5ddb3377ac2d7d52b731a5ef5355fc7d0d042012d9f8/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f626c61636b2d70726f6a6563742f416464726573732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/black-project/Address/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/319f1613f4dd06f999c63837181649ba2ff41eaa00fa6fca2153eba1a83e90d9/68747470733a2f2f706f7365722e707567782e6f72672f626c61636b2f616464726573732f762f737461626c652e706e67)](https://packagist.org/packages/black/address)[![Total Downloads](https://camo.githubusercontent.com/8078f7daca7dca26ceb9913fc26189bfc9fef119fc8e2a4d603908963c8709f2/68747470733a2f2f706f7365722e707567782e6f72672f626c61636b2f616464726573732f646f776e6c6f6164732e706e67)](https://packagist.org/packages/black/address)

Installation
------------

[](#installation)

The recommended way to install Address is through [Composer](https://getcomposer.org/):

```
{
    "require": {
        "black/address": "@stable"
    }
}
```

**Protip:** You should browse the [`black/address`](https://packagist.org/packages/black/address) page to choose a stable version to use, avoid the `@stable` meta constraint.

Usage
-----

[](#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

[](#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**

```
$country = new Address\Country("France", "FR");
echo $country->getName(); // return (string) France
```

It is possible to create a Country object with two static functions.

```
$country = Address\Country::buildFromISOCode("FR");
```

```
$country = Address\Country::buildFromName("France");
```

**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

[](#street)

A street is composed by a number and a name.

**Exemple**

```
$street = new Address\Street(1600, "Amphitheatre Pkwy");
$street->getValue(','); // return (string) 1600, Amphitheatre Pkwy
```

**Available functions**

- `->getNumber()`
- `->getName()`
- `->getValue($separator)`
- `->getValueAsArray()`
- `->isEqualTo($street)`

#### PostalAddress

[](#postaladdress)

PostalAddress is the main Value Object. He needs all the informations but an empty string is allowed.

```
$street  = new Address\Street(1600, "Amphitheatre Pkwy");
$country = new Address\Country("United States", "US");

$postalAddress = new Address\PostalAddress(
    $street,
    94043,
    "Mountain View",
    "CA",
    23,
    $country
);
```

**Available functions**

- `->getStreet()`
- `->getStreetName()`
- `->getStreetNumber()`
- `->getPostalCode()`
- `->getLocality()`
- `->getRegion()`
- `->getPostOfficeBoxNumber()`
- `->getCountry()`
- `->getCountryCode()`
- `->getCountryName()`
- `->getValue()` Return an array

#### Formatters

[](#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:

```
$street  = new Address\Street(1600, "Amphitheatre Pkwy");
$country = new Address\Country("United States", "US");

$postalAddress = new Address\PostalAddress(
    $street,
    94043,
    "Mountain View",
    "CA",
    23,
    $country
);

$formatter = new Address\PostalAddressFormatter($postalAddress);
echo $formatter->format("%u %n %P %a"); // return 1600 Amphitheatre Pkwy 94043 United States
```

License
-------

[](#license)

Address is released under the MIT License. See the bundled LICENSE file for details.

Contributing
------------

[](#contributing)

See CONTRIBUTING file.

Credits
-------

[](#credits)

This README is heavily inspired by [Geocoder](https://github.com/geocoder-php/Geocoder) library by the great [@willdurand](https://github.com/willdurand). This guy needs your \[PR\]\[3\] for the sake of the REST in PHP.

Alexandre "pocky" Balmes [alexandre@lablackroom.com](mailto:alexandre+github@lablackroom.com). Send me [Flattrs](https://flattr.com/profile/alexandre.balmes)if you love my work, [buy me gift](http://www.amazon.fr/registry/wishlist/3OR3EENRA5TSK) or hire me!

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~16 days

Total

2

Last Release

4208d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/86a3a03b53a62ac6bea9885beb48980a4a57dda70e36dc8828d0ececec05a738?d=identicon)[pocky](/maintainers/pocky)

---

Top Contributors

[![pocky](https://avatars.githubusercontent.com/u/204451?v=4)](https://github.com/pocky "pocky (15 commits)")

---

Tags

addressValue Objectblack-projectlibary

### Embed Badge

![Health badge](/badges/black-address/health.svg)

```
[![Health](https://phpackages.com/badges/black-address/health.svg)](https://phpackages.com/packages/black-address)
```

###  Alternatives

[moneyphp/money

PHP implementation of Fowler's Money pattern

4.8k82.5M422](/packages/moneyphp-money)[commerceguys/addressing

Addressing library powered by CLDR and Google's address data.

95430.2M43](/packages/commerceguys-addressing)[mlocati/ip-lib

Handle IPv4, IPv6 addresses and ranges

3126.4M44](/packages/mlocati-ip-lib)[darsyn/ip

An immutable IP Address value object that provides several different notations, including helper functions.

2572.0M20](/packages/darsyn-ip)[shippo/shippo-php

A PHP library for connecting with multiple carriers (FedEx, UPS, USPS) using Shippo.

1711.8M2](/packages/shippo-shippo-php)[markrogoyski/ipv4-subnet-calculator

Network calculator for subnet mask and other classless (CIDR) network information.

177813.7k6](/packages/markrogoyski-ipv4-subnet-calculator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
