PHPackages                             commerceguys/zone - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. commerceguys/zone

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

commerceguys/zone
=================

Zone management library.

v0.8(7y ago)781.1M—7.8%125MITPHPPHP &gt;=5.5.0

Since Feb 6Pushed 5y ago10 watchersCompare

[ Source](https://github.com/commerceguys/zone)[ Packagist](https://packagist.org/packages/commerceguys/zone)[ RSS](/packages/commerceguys-zone/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (8)Used By (5)

zone
====

[](#zone)

*Important:* A newer version of the zone functionality is now included directly in the [commerceguys/addressing](https://github.com/commerceguys/addressing) library. This library is deprecated.

[![Build Status](https://camo.githubusercontent.com/2d9ca972c192bb0d244738bc0e94180f9bb731426d31ca6e882955026016ee56/68747470733a2f2f7472617669732d63692e6f72672f636f6d6d65726365677579732f7a6f6e652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/commerceguys/zone)

A PHP 5.5+ zone management library. Requires [commerceguys/addressing](https://github.com/commerceguys/addressing).

Zones are territorial groupings mostly used for shipping or tax purposes. For example, a set of shipping rates associated with a zone where the rates become available only if the customer's address matches the zone.

A zone can match other zones, countries, subdivisions (states/provinces/municipalities), postal codes. Postal codes can also be expressed using ranges or regular expressions.

Examples of zones:

- California and Nevada
- Belgium, Netherlands, Luxemburg
- European Union
- Germany and a set of Austrian postal codes (6691, 6991, 6992, 6993)
- Austria without specific postal codes (6691, 6991, 6992, 6993)

Data model
==========

[](#data-model)

Each [zone](https://github.com/commerceguys/zone/blob/master/src/Model/ZoneInterface.php) has [zone members](https://github.com/commerceguys/zone/blob/master/src/Model/ZoneMemberInterface.php). A zone matches the provided address if one of its zone members matches the provided address.

The base interfaces don't impose setters, since they aren't needed by the service classes. Extended interfaces ([ZoneEntityInterface](https://github.com/commerceguys/zone/blob/master/src/Model/ZoneEntityInterface.php), [ZoneMemberEntityInterface](https://github.com/commerceguys/zone/blob/master/src/Model/ZoneMemberEntityInterface.php)) are provided for that purpose, as well as matching [Zone](https://github.com/commerceguys/zone/blob/master/src/Model/Zone.php) and [ZoneMember](https://github.com/commerceguys/zone/blob/master/src/Model/ZoneMember.php) classes that can be used as examples or mapped by Doctrine.

The library contains two types of zone members:

- [country](https://github.com/commerceguys/zone/blob/master/src/Model/ZoneMemberCountry.php) (matches a country, its subdivisions, included/excluded postal codes)
- [zone](https://github.com/commerceguys/zone/blob/master/src/Model/ZoneMemberZone.php) (matches a zone)

```
use CommerceGuys\Addressing\Address;
use CommerceGuys\Zone\Model\Zone;
use CommerceGuys\Zone\Model\ZoneMemberCountry;

$zone = new Zone();
$zone->setId('german_vat');
$zone->setName('German VAT');
$zone->setScope('tax');

// Create the German VAT zone (Germany and 4 Austrian postal codes).
$germanyZoneMember = new ZoneMemberCountry();
$germanyZoneMember->setCountryCode('DE');
$zone->addMember($germanyZoneMember);

$austriaZoneMember = new ZoneMemberCountry();
$austriaZoneMember->setCountryCode('AT');
$austriaZoneMember->setIncludedPostalCodes('6691, 6991:6993');
$zone->addMember($austriaZoneMember);

// Check if the provided austrian address matches the German VAT zone.
$austrianAddress = new Address();
$austrianAddress = $austrianAddress
    ->withCountryCode('AT')
    ->withPostalCode('6692');
echo $zone->match($austrianAddress); // true
```

Matcher
=======

[](#matcher)

A matcher class is provided for the use case where an address should be matched against all zones in the system, with the matched zones ordered by priority.

```
use CommerceGuys\Addressing\Address;
use CommerceGuys\Zone\Matcher\ZoneMatcher;
use CommerceGuys\Zone\Repository\ZoneRepository;

// Initialize the default repository which loads zones from json files stored in
// resources/zone. A different repository might load them from the database, etc.
$repository = new ZoneRepository('resources/zone');
$matcher = new ZoneMatcher($repository);

$austrianAddress = new Address();
$austrianAddress = $austrianAddress
    ->withCountryCode('AT')
    ->withPostalCode('6692');

// Get all matching zones.
$zones = $matcher->matchAll($austrianAddress);
// Get all matching zones for the 'tax' scope.
$zones = $matcher->matchAll($austrianAddress, 'tax');

// Get the best matching zone.
$zone = $matcher->match($austrianAddress);
// Get the best matching zone for the 'shipping' scope.
$zone = $matcher->match($austrianAddress, 'shipping');
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity52

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.1% 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 ~201 days

Recently: every ~273 days

Total

7

Last Release

2912d ago

PHP version history (2 changes)v0.5PHP &gt;=5.4.0

v0.8PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/621c34dbc1ad3ea00e09f6006aa9607d0046bf862182d59c66f1f18cb51c0f15?d=identicon)[bojanz](/maintainers/bojanz)

---

Top Contributors

[![bojanz](https://avatars.githubusercontent.com/u/330162?v=4)](https://github.com/bojanz "bojanz (49 commits)")[![dwkitchen](https://avatars.githubusercontent.com/u/1096557?v=4)](https://github.com/dwkitchen "dwkitchen (5 commits)")[![lsolesen](https://avatars.githubusercontent.com/u/148026?v=4)](https://github.com/lsolesen "lsolesen (3 commits)")[![JulienD](https://avatars.githubusercontent.com/u/408389?v=4)](https://github.com/JulienD "JulienD (1 commits)")[![pjcarly](https://avatars.githubusercontent.com/u/2808694?v=4)](https://github.com/pjcarly "pjcarly (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/commerceguys-zone/health.svg)

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

###  Alternatives

[commerceguys/tax

Tax library with a flexible data model, predefined tax rates, powerful resolving logic.

286763.3k](/packages/commerceguys-tax)[verbb/formie

The most user-friendly forms plugin for Craft.

101372.9k40](/packages/verbb-formie)[verbb/shippy

A framework agnostic, multi-carrier shipping library for PHP.

1610.1k1](/packages/verbb-shippy)

PHPackages © 2026

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