Download the PHP package jstewmc/usps-address without Composer
On this page you can find all versions of the php package jstewmc/usps-address. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package usps-address
USPS Address
A library for normalizing and comparing United States Postal Service (USPS) addresses in PHP.
Comparing addresses is tricky. There are many different ways to represent the same physical address. For example, "123 First St" is the same address as "123 1st St". However, to a computer, those are two different things.
This library attempts to normalize addresses so that different forms of the same physical address can be compared. For example, "17 First Street" and "17 1st st" will be considered equal.
There are a few caveats:
- A normalized address should not be displayed to users. It's formatted to help a computer compare addresses for equality, and it's not "pretty".
- A normalized address should not be saved over the original address. The normalized version of an address may change as this library's algorithm improves, but once you overwrite the original address, it's gone forever.
- A normalized address should not be considered authentic. This library will normalize and compare whatever address you give it, regardless of whether or not it actually exists. If you don't mind using a web service, there are APIs available that can normalize, validate, and authenticate addresses for you.
Installation
This library requires PHP 7.4+.
It is multi-platform, and we strive to make it run equally well on Windows, Linux, and OSX.
It should be installed via Composer. To do so, add the following line to the require
section of your composer.json
file, and run composer update
:
Usage
This library defines an interface for USPS addresses, AddressInterface
, which supports a two-line street address, a city, a state, and a zip code, for example:
All components are optional to support partial data.
This library provides an implementation of the interface, Address
, as well as a trait
, Addressable
, which you can use in your own classes to implement the interface.
Using your implementation
When using your implementation of AddressInterface
(let's call it MyAddress
), you can use this library's Compare
service to compare addresses:
If you'd like to access a lower-level normalized address, you can use the Normalize
service to do so. Keep in mind, this service will accept any implementation of the AddressInterface
, and it will return an instance of our own implementation, Address
:
If you're using both services, you can inject your instance of the Normalize
service into your instance of the Compare
service. Otherwise, the Compare
service will instantiate its own copy of the Normalize
service:
Using our implementation
Our implementation of AddressInterface
, Address
, provides two methods - equals()
and normalize()
- for convenience. These methods are reasonable shortcuts to managing the services if you aren't processing a large number of addresses. With large enough datasets, the methods' instantiating and discarding single-use objects may affect memory and performance.
Our implementation also allows you to instantiate an address using the constructor alone:
Migrating from 0.1
This library changed substantially from 0.1
to 0.2
:
- We moved previously
public static
properties to private constants to better encapsulate them. - We moved previously
public static
methods to a service for a service-friendly, easier-to-test solution. - We programmed to an interface, not an implementation, and provided a trait to make the library easier to use with your own code.
- We removed the
Usps
prefix from class names, because it didn't add information not already obvious from the library's name.
As a result, migrating from 0.1
to 0.2
involves a number of breaking changes. Although painful, we believe it will make the library easier to use and maintain in the future.
Contributing
Contributions are welcome!
License
This library is released under the MIT License.