Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Libphonenumber For Php Lite Laravel Package

giggsey/libphonenumber-for-php-lite

A lightweight PHP library for parsing, formatting, storing, and validating international phone numbers, based on Google's libphonenumber. This lite version includes core phone number utilities and requires PHP 8.1+ with mbstring.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit

  • Stateless, side-effect-free utility library: no DB, no I/O, no queues, no service provider. It slots underneath the domain layer as a pure function of (input string, region) → normalized E.164 + validity. That makes it safe to call from form requests, jobs, console commands, and webhooks without circular-dependency or bootstrapping concerns.
  • Entry point is a singleton (PhoneNumberUtil::getInstance()) with static-ish semantics; the natural Laravel shape is a thin PhoneNumber value object plus a PhoneNumberService bound in the container, so application code never touches libphonenumber\* directly.
  • Fit is high for the common Laravel use cases: registration/profile phone fields, E.164 normalization before persistence, SMS/voice dispatch target formatting, de-duplicating contacts across national and international notations.

Integration feasibility

  • Single Composer require; no config publishing, no migrations, no assets. Hard requirements are PHP ≥ 8.1 and ext-mbstring, both already present in any Laravel 10/11/12 baseline. Realistic effort: 1–2 days for abstraction + validation rule + tests, not a sprint.
  • isNumberMatch (confidence levels) and getNumberType (fixed-line/mobile/toll-free/VoIP) are the highest-leverage features beyond basic validation — they enable SMS-only routing rules and fraud heuristics at near-zero cost.

Technical risk

  • Non-semver versioning. The project deliberately mirrors Google libphonenumber version numbers; the jump to 9.0.0 replaced constant classes with backed enums and moved metadata from arrays into PHP classes. Code that persisted integer type codes or serialized PhoneNumber objects is the exposure point. Constrain to ^9.0 and treat any major bump as a change requiring review, not an automatic merge.
  • Metadata churn. Releases land roughly every two weeks (9.0.5 → 9.0.22 across eight months). Validation outcomes for individual numbers can flip between releases, which makes fixtures built from live customer numbers inherently flaky.
  • Lite scope. No geocoding, no carrier lookup, no short-number info. If any roadmap item needs "which carrier is this" or "is this a premium-rate number," this package is the wrong artifact and the full giggsey/libphonenumber-for-php is required — same namespace, larger data footprint.
  • Adoption signal. 99 stars and 0 dependents on this fork, versus a very widely used parent package by the same maintainer. The risk is not the author; it is that the lite variant has a smaller bug-report surface, so edge-case defects may sit longer than in the parent.
  • Package size and cold-start memory. Full-region metadata ships in the package. Unmeasured here, but it affects container image size and opcache footprint — worth a 30-minute spike before committing.
  • Bus factor. Effectively one primary maintainer. Mitigation is architectural (abstraction layer), not contractual.

Key questions

  1. Do we need carrier, geolocation, or short-number data anywhere in the next 12 months? If yes, start with the full package and skip the migration.
  2. Do we ever persist serialized PhoneNumber objects (cache, queue payloads, DB columns)? If so, the 9.x serialization change is a migration, not a routine bump.
  3. What is our update policy for a dependency that ships every two weeks and does not follow semver — pinned-and-manual, or automated with a test gate?
  4. Where is the single validation choke point? If numbers are validated in three places today, the abstraction must be introduced before the library.
  5. Do we accept all ~240 regions, or restrict the dropdown to a supported set? Restriction removes a large class of support tickets.
  6. What is the container image size and PHP memory ceiling budget for the added metadata?

Integration Approach

Stack fit

  • Composer-only dependency with PSR-4 autoloading; no Laravel coupling either direction, so it survives framework upgrades and is portable if part of the app is extracted to a service.
  • Recommended layering: App\Support\PhoneNumber value object (raw input, E.164, national, region, type) → PhoneNumberService wrapping PhoneNumberUtil → a ValidPhoneNumber validation rule and a custom Eloquent cast. Everything above the service is then library-agnostic.
  • Bind the service as a singleton in a service provider so getInstance() is called once and the metadata cache is shared per process.

Migration path

  • Brownfield inventory first: grep for regex phone validation, str_replace punctuation stripping, and manual + prefixing. Each site is a candidate for replacement and a potential source of duplicate or inconsistent stored formats.
  • Introduce the service and rule, apply to new writes only, and keep the legacy path behind a feature flag. Persist raw input alongside E.164 so nothing is lost if normalization is later judged wrong.
  • Backfill in a queued, chunked job with a dry-run mode that writes proposed changes to an audit table. Do not overwrite in place without a reviewable diff — normalization changes are hard to reverse once merged with other profile edits.
  • Do not migrate persisted PhoneNumber serializations in the same release as the backfill; separate the concerns.

Compatibility

  • PHP 8.1+ aligns cleanly with Laravel 10+. Any remaining PHP 8.0 runtime is a blocker and should be surfaced early.
  • Verify ext-mbstring in every image variant, including CI, queue workers, and any Lambda/serverless runtime — a missing extension is a fatal at first use, not at install.
  • v9 backed enums require PHP 8.1; they coexist fine with Laravel coding standards but will trip static analysis rules that expect class constants.

Sequencing

  1. Spike (1–2 days): run a sample of 200–500 real production numbers through parse/validate/format; measure per-call cost, peak memory, and the invalid-rate by region. This also tells you whether the lite scope is actually sufficient.
  2. Decide lite vs. full against the roadmap, not against the current ticket.
  3. Build the abstraction — value object, service, validation rule, cast — with a fixture suite spanning 15–20 regions including leading-zero cases (IT), trunk-prefix variation (GB, CH), and extensions.
  4. Pin and gate — exact version in composer.lock, dependency bot configured to open PRs but require the fixture suite plus a manual reviewer.
  5. Roll out to new writes, monitor, then backfill.
  6. Add lightweight telemetry — counters for NumberParseException and invalid-number rate by region, so a metadata regression shows up as a metric rather than as a support ticket.

Operational Impact

Maintenance

  • Code maintenance is near zero; dependency maintenance is the real cost. Expect ~24 metadata-only releases per year. Most require nothing, but each is a potential validation-behavior change.
  • Recommend a monthly update cadence with a standing 30-minute review, plus an out-of-band path for region-specific fixes. Budget roughly 0.5 engineer-day per month.
  • The build script (composer run build) clones Google's repo; it is not something we run in CI. Consume published releases only.

Support

  • No vendor support channel. Escalation ladder to document in the runbook: reproduce against Google's online demo → if Google agrees it is wrong, file upstream with Google → if this library diverges from the parent PHP package, file with this repo. That ordering prevents wasted cycles.
  • Apache-2.0 is commercially permissive; retain the NOTICE/attribution in any distributed artifact.

Scaling

  • Stateless and CPU-cheap; throughput is bounded by metadata loading, which amortizes per PHP-FPM worker or per Octane process. No network calls, so no latency tail and no cascading-failure surface — this is one of the safer dependencies to put on a hot path.
  • Under Octane, confirm the singleton is not holding stale metadata across a deploy; a worker recycle on release is the simplest guarantee.
  • Validate performance at the batch-job level: a backfill over millions of rows re-parses per row, so cache the region metadata lookup and consider a memoization map keyed by normalized input.

Failure modes

  • False negatives from metadata lag. New prefixes and number-plan changes take weeks to propagate. Mitigation: never block a user from saving a number solely on isValidNumber; store raw input, normalize best-effort, and flag for review rather than reject.
  • Missing region context. National-format input cannot be parsed without a region. Every call site must supply one (explicit field, account locale, or IP-derived) — this is the most common integration bug.
  • Unhandled NumberParseException. It is thrown, not returned. An unguarded call inside a chunked job aborts the batch; wrap at the service boundary and convert to a domain result object.
  • Serialization breakage. Cached or queued PhoneNumber objects can fail to unserialize across a major version. Store scalars (E.164 strings) in durable storage; treat the object as in-memory only.
  • Environment drift. One container missing ext-mbstring produces a runtime fatal under load. Add an extension assertion to the health check.
  • Silent behavior change after a metadata bump. Guarded by the fixture suite; without it, this fails quietly in production.

Ramp-up

  • Roughly one day for a mid-level Laravel developer to be productive: the README examples cover parsing, validation, and the three format modes, which is 80% of real usage. Add half a day for the backfill tooling.
  • The actual learning curve is the phone-number domain, not the API — E.164 versus national versus RFC 3966, trunk prefixes, Italian leading zeros, extensions, and the fact that "valid" and "in service" are different questions. A short internal note on those concepts will save more time than any library documentation.
  • Enforce the abstraction layer in review. The single most valuable long-term decision is that application code depends on our PhoneNumber value object, not on libphonenumber\PhoneNumberUtil — that keeps the lite-to-full upgrade, or a future swap, a one-file change.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo