$ show commerceguys/addressing
This is a PHP 8.0+ library for postal address manipulation, formatting, validation, and localization (i18n). It provides immutable address value objects (Address, AddressInterface), formatters for display and postal labels, validators (Symfony constraints), and repositories for countries, address formats, and subdivisions. The library bundles extensive static JSON data derived from CLDR (country names in 150+ locales) and Google's Address Data Service (address formats for 200+ countries, subdivisions for 62 countries). Key architectural patterns include the repository pattern for data loading, lazy-loaded subdivision collections, type-safe enumerations via AbstractEnum, and PSR-7-style immutable mutators. It is designed as a standalone Composer package with optional Symfony Validator integration, and is used in Drupal and Symfony applications. The code is well-structured, uses modern PHP features, and has solid test coverage.
The LLM identified 2 files worth highlighting for reuse:
Provides a base class for creating type-safe enumerations in PHP. Implements methods like getAll(), exists(), and assertExists() for consistent enum handling. The class is self-contained, uses no internal dependencies, and can be extracted into any PHP project needing reliable enum support without external packages.
A utility class with static methods for matching postal codes against pattern strings and checking validity. It handles pattern parsing and matching logic in isolation, with no dependencies on other library components. This pattern is reusable for any postal code validation or normalization task across projects.