Download the PHP package sinemacula/data-normalizer-php without Composer
On this page you can find all versions of the php package sinemacula/data-normalizer-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sinemacula/data-normalizer-php
More information about sinemacula/data-normalizer-php
Files in sinemacula/data-normalizer-php
Package data-normalizer-php
Short Description PHP library for consistent data normalization and formatting across names, emails, phone numbers, addresses, and other common data types.
License Apache-2.0
Informations about the package data-normalizer-php
Data Normalizer for PHP
Consistent, deterministic normalization for the common data types every system handles slightly differently — names,
emails, phone numbers, postal addresses, dates, currencies, and more. Each data type is encapsulated in a small,
single-purpose normalizer behind one static facade, so Normalizer::phone($value) returns the same canonical output
everywhere it is called.
The library is framework-agnostic — it has no dependency on Laravel or any other framework — and extensible: any consuming application can register its own normalizers without forking the package.
How It Works
Every normalizer implements a single contract, NormalizerInterface, and is reached through the Normalizer facade.
Calls are routed by name: Normalizer::email($value) resolves to the Email normalizer, dispatches to its
normalize() method, and returns the result. Resolution is memoised, so the lookup cost is paid once per name per
process.
A few rules hold across the surface:
- Null means "could not normalize." Every normalizer returns
nullfor input it cannot produce a meaningful value from (non-strings, empty values, unparseable input) rather than throwing. - Canonical, idempotent output. Each normalizer maps varied input to a single canonical form; re-normalizing an already-normalized value returns it unchanged.
Supported Normalizers
| Normalizer | Call | Result |
|---|---|---|
clean |
Normalizer::clean($value) |
Collapses internal whitespace and trims the ends; the building block for the other normalizers |
name |
Normalizer::name($value) |
Title-cases personal names; preserves Mc / Mac / O' prefixes, lowercases particles (van, de, von), and flips Doe, John to John Doe |
email |
Normalizer::email($value) |
Lowercases and strips spaces |
phone |
Normalizer::phone($value, ?$country) |
Formats to E.164 via libphonenumber; defaults to the US region, returns null for invalid numbers |
date |
Normalizer::date($value) |
Parses a set of known formats to Y-m-d; returns null for invalid calendar dates |
timezone |
Normalizer::timezone($value) |
Resolves to a canonical IANA timezone identifier (case-insensitive) |
addressLine |
Normalizer::addressLine($value) |
Title-cases the line and strips trailing commas |
postalCode |
Normalizer::postalCode($value, ?$country) |
Validates and formats to the country's canonical form (UK/Canada spacing, US ZIP+4 hyphen); without a country, uppercases and trims |
country |
Normalizer::country($value) |
Resolves a country name or code to its ISO 3166-1 alpha-2 code, with fuzzy matching for near-misses |
administrativeArea |
Normalizer::administrativeArea($value, ?$country) |
Resolves a state / province / region name or code to its subdivision code (defaults to the US country) |
companyName |
Normalizer::companyName($value) |
Normalizes legal suffixes (Inc, LLC, Ltd, GmbH, SARL) |
jobTitle |
Normalizer::jobTitle($value) |
Title-cases titles while preserving acronyms (CEO, IT, R&D) and lowercasing stop words |
currency |
Normalizer::currency($value) |
Validates and uppercases to an ISO 4217 currency code |
ssn |
Normalizer::ssn($value) |
Strips to digits; preserves already-redacted values such as ***123 |
Installation
Usage
Extending
Register your own normalizers at application bootstrap. A custom normalizer is any class implementing
SineMacula\Foundation\Normalizers\Contracts\NormalizerInterface:
Registration is validated eagerly — register() throws an InvalidNormalizerException (an InvalidArgumentException
subclass) immediately if the class does not implement NormalizerInterface, so misconfiguration surfaces at bootstrap
rather than at call time. Registering the same name twice overwrites the earlier registration (last write wins).
[!WARNING] Registered normalizers take precedence over the built-ins. Registering a name such as
phoneorcleanintentionally replaces the built-in behaviour for every caller in the process — a deliberate feature, but one that can cause hard-to-trace differences in normalized output if used accidentally.
Register at bootstrap only. In long-running runtimes (Octane, Swoole, RoadRunner, queue workers) the registry is
shared process state — treat it as write-once during boot and read-only thereafter. Normalizer::flush() clears all
registrations and is intended for test isolation only.
For IDE completion of your custom normalizers, subclass the facade (it is intentionally non-final) purely to carry
@method docblocks:
Requirements
- PHP ^8.3
Testing
Changelog
See CHANGELOG.md for a list of notable changes.
Contributing
Contributions are welcome. Please read CONTRIBUTING.md for guidelines on branching, commits, code quality, and pull requests.
Security
If you discover a security vulnerability, please report it responsibly. See SECURITY.md for the disclosure policy and contact details.
License
Licensed under the Apache License, Version 2.0.
All versions of data-normalizer-php with dependencies
brick/postcode Version ^0.6
commerceguys/addressing Version ^2.2
giggsey/libphonenumber-for-php Version ^9.0
symfony/intl Version ^7.4|^8.0