hyperized/value-objects 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

hyperized/value-objects

Composer 安装命令:

composer require hyperized/value-objects

包简介

A basic value objects collection

README 文档

README

FOSSA Status

A typed, immutable value objects collection for PHP 8.4+.

All value objects validate on construction, are immutable (readonly classes), and follow the same pattern: extend an abstract, get validation for free.

Install

composer require hyperized/value-objects

Quick start

Use the provided concrete classes directly:

use Hyperized\ValueObjects\Concretes\Strings\Email;
use Hyperized\ValueObjects\Concretes\Integers\Port;

$email = Email::fromString('user@example.com');
$email->getLocalPart(); // 'user'
$email->getDomain();    // 'example.com'

$port = Port::fromInteger(8080);
$port->getValue(); // 8080

Or extend an abstract to create your own domain-specific value object:

use Hyperized\ValueObjects\Abstracts\Integers\AbstractPositiveInteger;

readonly class UserId extends AbstractPositiveInteger {}

$id = UserId::fromInteger(42);
$id->getValue(); // 42

Available value objects

Integers

Class Description
Integer Any integer value
PositiveInteger Must be > 0
NegativeInteger Must be < 0
NonNegativeInteger Must be >= 0
RangedInteger Within a min/max range (defaults to PHP_INT_MIN/PHP_INT_MAX)
Octal Valid octal number with decimal conversion
Hexadecimal Hex string parsing with asHexString()
Port Network port (1-65535)

Real numbers

Class Description
RealNumber Any float value
Percentage Float between 0-100, with asFraction()

Spatial

Class Description
Coordinate Latitude (-90/90) and longitude (-180/180) pair
BoundingBox Southwest/northeast coordinate pair with contains()
Distance Non-negative distance with unit conversions (m/km/mi/ft/nm)
Bearing Compass heading (0-360) with getCardinal()
Altitude Height above/below sea level with unit conversions (m/ft)
GeoHash Base-32 encoded location string with getPrecision()
Polygon Ordered list of coordinates (minimum 3 points)
LineString Ordered list of coordinates (minimum 2 points)

Strings

Class Description
ByteArray Any string value
EmptyByteArray Must be empty
NonEmptyByteArray Must be non-empty
Email Validated email with getLocalPart() / getDomain()
Url Validated URL with getScheme() / getHost() / getPath()
Uri URI with scheme requirement, getQuery() / getFragment()
Uuid RFC 4122 UUID, normalizes to lowercase, getVersion()
IpAddress IPv4/IPv6 with isIPv4() / isIPv6()
Hostname RFC-compliant, max 253 chars, normalized to lowercase
MacAddress Colon or dash format, normalized to lowercase colon-separated
Json Validated JSON string with decode()
Regex Validated regex pattern with matches()
SemVer Semantic version with getMajor() / getMinor() / getPatch()
DateString ISO 8601 / Y-m-d date with toDateTimeImmutable()

Lists

Class Description
Inventory From comma-separated string, with contains()
ConstrainedList List with a set of allowed values

Extending

Every concrete class extends an abstract that you can extend for your own domain types. Override validate() to add custom rules:

use Hyperized\ValueObjects\Abstracts\Strings\AbstractEmail;

readonly class CompanyEmail extends AbstractEmail
{
    #[\Override]
    protected static function validate(string $value): void
    {
        parent::validate($value);

        if (!str_ends_with($value, '@company.com')) {
            throw new \InvalidArgumentException('Must be a company email');
        }
    }
}

See the examples/ directory for more usage patterns.

Quality

composer test        # PHPStan (level 9) + PHPUnit
composer infection   # Mutation testing

Licence

MIT

FOSSA Status

Author

Gerben Geijteman gerben@hyperized.net

hyperized/value-objects 适用场景与选型建议

hyperized/value-objects 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.46k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2020 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 hyperized/value-objects 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hyperized/value-objects 我们能提供哪些服务?
定制开发 / 二次开发

基于 hyperized/value-objects 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 12
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-11