承接 ap-lib/caster-scheme 相关项目开发

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

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

ap-lib/caster-scheme

Composer 安装命令:

composer require ap-lib/caster-scheme

包简介

AP\Caster\Scheme is a plugins for caster for casting objects based on scheme

README 文档

README

MIT License

AP\Caster\Scheme is a plugins for caster for casting objects based on scheme

Installation

composer require ap-lib/caster-scheme

Features

  • Caster uses the ToObject::toObject(mixed $data) method to construct objects.

Requirements

  • PHP 8.3 or higher

Getting started

Here's a quick example demonstrating how to use AP\Caster.

Initialize the PrimaryCaster with SchemeCaster

$toObject = new ToObject(
    new \AP\ToObject\ObjectParser\ByConstructor(),
    new PrimaryCaster([
        new SchemeCaster,
    ])
);

class Guid implements \AP\Scheme\ToObject
{
    public function __construct(public string $bites) {
    
    }

    public static function toObject(array|string|int|float|bool|null $data): static
    {
        if (is_string($data)) {
            return new static(pack("h*", str_replace('-', '', $data)));
        }
        throw ThrowableErrors::one('value is not valid uuid bytes');
    }
}

class Request {
    public function __constructor(
        public User $user,
        public Guid $guid, 
    ){}
}

$obj = $toObject->makeObject(
    [
        "user" => [
            "name" => "John", 
            "age" => 12
        ], 
        "guid" => "6B29FC40-CA47-1067-B31D-00DD010662DA"
    ],
    Request::class
);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-14