定制 phpbuildingblocks/types 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

phpbuildingblocks/types

最新稳定版本:1.0.0

Composer 安装命令:

composer require phpbuildingblocks/types

包简介

description

README 文档

README

Description

This package is designed to provide a comprehensive collection of Value Objects, crafted for reusability and adaptability in various projects. Primarily, these types focus on implementing robust validation rules. However, they also offer the flexibility to override these validation rules as needed, ensuring a versatile and efficient utilization in a wide range of applications.

Getting Started

Dependencies

Zero Dependencies

Installing

composer require phpbuildingblocks/types

How to Rewrite validation rules

Let's say you want to IntId to accept only positive numbers greater than 0. You can do this by extending the IntId class and overriding the validate method.

<?php
use PHPBuildingBlocks\Types\Id\Exceptions\InvalidIdException;
use PHPBuildingBlocks\Types\Id\IntId;

class PositiveIntId extends IntId
{
    protected function validate(int $value): void
    {
        if (!is_int($value) || $value <= 0) {
            throw new InvalidIdException('Value must be positive');
        }
    }
}

You can now use this class as you would the original IntId class.

<?php
use PHPBuildingBlocks\Types\Id\IntId;

class someRepository
{
    public function getById(IntId $id)
    {
        // do something
    }
}

$someRepository = new someRepository();
$result = $someRepository->getById(new PositiveIntId(1));

Supported Types

IntId - A simple integer ID
UUidId - A UUID ID
Email - An email address

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2024-01-20