alphazygma/usps-zonechart-php

Provide zone identification between Source and Target Destination.

1.0 2016-11-03 23:43 UTC

This package is not auto-updated.

Last update: 2024-04-27 18:14:47 UTC


README

Latest Stable Version Build Status Coverage Status Total Downloads Latest Unstable Version License

USPS ZoneChart (for PHP)

Provide zone identification between Source and Target Destination

Requirements

PHP 5.5+ is required. (The [] short array syntax was introduced on 5.4, and GuzzleHttp 6 is not compatible with PHP 5.4)

Disclaimer

The ConfigGenerator and the helper tool to run the generator does not have unittests, however, since these are not intended for library use, but more for updating the JSON configuration files if USPS updates their charts because new ZipCodes are added to the US.

As such, these files are not included for test coverage purposes.

Changelog

  • 1.0 Retrieve a Zone for a given source/destination ZipCodes

Usage

This usage considers that you have an autoloader running. (see Install for more reference)

<?php
$sourceZip1 = '94040'; // Mountain View, CA
$sourceZip2 = '40342'; // Lawrenceburg, KY
$destinationZip = '94118'; // San Francisco, CA

// Same or close zone example (CA -> CA)
$zoneChart = new \Shipping\ZoneChart\ZoneChart($sourceZip1);
$zoneA     = $zoneChart->getZoneFor($destinationZip);
// $zoneA would have 1 or 2 for example

// different zone example (KY -> CA)
$zoneChart = new \Shipping\ZoneChart\ZoneChart($sourceZip2);
$zoneB     = $zoneChart->getZoneFor($destinationZip);
// $zoneB would have 4 or 5 for example

Install

The easiest way to install is through composer.

Just create a composer.json file for your project:

{
    "require": {
        "alphazygma/usps-zonechart-php": "~1.0"
    }
}

Then you can run these two commands to install it:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install

or simply run composer install if you have have already installed the composer globally.

Then you can include the autoloader, and you will have access to the library classes:

<?php
require 'vendor/autoload.php';