Download the PHP package lemonade/component_postcode without Composer
On this page you can find all versions of the php package lemonade/component_postcode. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package component_postcode
Lemonade Postcode
A lightweight PHP library for validating and formatting international postal codes (ZIP/PSC).
Provides country-specific formatters, unified exception handling, and clear error codes for integration in forms, APIs, and e-commerce applications.
✨ Features
- ✅ Validation and normalization of postal codes for multiple countries
- ✅ Country-specific formatters (
CZ,SK,DE,GB,FR,IT,…) - ✅ Unified API via
PostcodeFormatter - ✅ Strict typing (PHP 8.1+)
- ✅ Consistent error handling with
PostcodeExceptionandPostcodeErrorCodeenum - ✅ Ready for localization (
messageKey()for translation keys) - ✅ PSR-4 autoloading
- ✅ PHPUnit test coverage
- ✅ PHPStan Level 10 + Strict Rules
- ✅ Verified with 100% PHPUnit coverage
-
✅ Includes support for all 249 ISO 3166-1 alpha-2 country codes
🚀 Installation
🔧 Usage
➕ Custom Formatters
You can easily extend the library with your own country-specific formatters.
Simply implement CountryPostcodeFormatter and register it via FormatterRegistry.
Example with an anonymous class:
📦 Country Formatters
Each country has its own Formatter class under Lemonade\Postcode\Formatter.
Examples:
- CZ_Formatter –
12000→120 00 - SK_Formatter –
81101→811 01 - PL_Formatter –
01001→01-001 - GB_Formatter –
SW1A1AA→SW1A 1AA - LT_Formatter – supports both
12345andLT12345
⚠️ Exceptions
All errors are reported using dedicated exception classes.
This makes it easy to distinguish between invalid input and unsupported countries.
-
InvalidPostcodeException
Thrown when the postcode does not match the expected format
or contains an unsupported value.
Example:"ABCDE"forCZ. -
UnknownCountryException
Thrown when trying to format a postcode for an unsupported
or unrecognized ISO 3166-1 alpha-2 country code.
Example:"XX". -
UnsupportedCountryException
Thrown when the country code is valid, but no formatter is registered for it.Example:
"AQ"(valid ISO code, but not implemented inFormatterMapper)..
All exceptions implement the PostcodeException interface, which provides:
getValue()→ returns the original input (postcodeorcountry)getCode()→ stable numeric error code (PostcodeErrorCode)getMessage()→ translation key for localization
📖 Changelog
All notable changes are documented in the CHANGELOG.md.
🧪 Development & Testing
This package is fully covered by PHPUnit tests and verified with PHPStan Level 10.
Run PHPUnit tests:
Run static analysis (PHPStan Level 10 + Strict Rules):