承接 componenta/phone 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

componenta/phone

Composer 安装命令:

composer require componenta/phone

包简介

Phone number value object backed by libphonenumber

README 文档

README

Phone number value object backed by giggsey/libphonenumber-for-php.

Use it when phone numbers should be validated, normalized to E.164, formatted for UI, and serialized as a stable string.

Installation

composer require componenta/phone

Related Packages

This package is standalone but relies on giggsey/libphonenumber-for-php.

Package Why it may be used nearby
componenta/validation Validates raw phone input before creating Phone.
componenta/auth Can use phone numbers for OTP or passwordless flows.
componenta/cqrs Registration/profile commands can type phone fields with this value object.

Usage

use Componenta\Stdlib\Phone;

$phone = Phone::create('916 123-45-67', region: 'RU');

(string) $phone;          // "+79161234567"
$phone->toInternational();
$phone->toNational();
$phone->toRfc3966();
$phone->countryCode();    // 7
$phone->detectedRegion(); // "RU"

Constructors

  • Phone::create($phone, $region = 'RU') parses and validates raw input
  • Phone::fromE164($e164) creates from a pre-normalized E.164 string and still validates it
  • Phone::tryCreate($phone, $region = 'RU') returns null instead of throwing

The region is only a parsing hint for local formats. Numbers starting with + are parsed region-agnostically. The stored value is always E.164.

Validation And Errors

Invalid input throws InvalidArgumentException. Static isValid() can be used for boolean checks when no value object is needed.

Serialization

__toString() and jsonSerialize() return the E.164 value. masked() preserves the country code and the last four digits for logs and UI.

Performance

The parsed PhoneNumber instance is created lazily and cached on the value object after the first formatting/classification call.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固