承接 componenta/caster 相关项目开发

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

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

componenta/caster

Composer 安装命令:

composer require componenta/caster

包简介

Value casting attributes and resolvers for Componenta

README 文档

README

Named value casters and casting pipelines.

Installation

composer require componenta/caster

The package declares Componenta\Caster\ConfigProvider in extra.componenta.config-providers. When componenta/composer-plugin is installed, the provider is added to the generated provider list automatically.

Requirements

  • PHP 8.4+

Related Packages

Package Why it matters here
componenta/di Uses casters in #[Cast], #[QueryParam(cast: ...)], and similar attributes.
componenta/validation Can validate DTOs after values are normalized by casters.
componenta/config Registers CasterProviderInterface through ConfigProvider.

What It Provides

  • CasterInterface: public contract for named value casters.
  • CasterProviderInterface: registry contract for resolving casters by name.
  • CasterProvider: default registry with scalar, string, array, date, enum, hash, and pipeline casters.
  • Typed exceptions when a value cannot be cast.

Basic Usage

use Componenta\Caster\CasterProvider;

$provider = new CasterProvider();

$int = $provider->provide('int');
$int->cast('42'); // 42

Unknown casters return null:

$provider->provide('missing'); // null

Parameterized Casters

$provider->provide('clamp:10,20')->cast(25); // 20.0
$provider->provide('csv_int')->cast('1,2,3'); // [1, 2, 3]

Pipelines

Use | to chain casters:

$provider->provide('trim|lower')->cast('  HELLO  '); // hello

Use ? to pass null through the whole downstream chain:

$provider->provide('?int|bool')->cast(null); // null
$provider->provide('?int|bool')->cast('1');  // true

DI Registration

ConfigProvider registers CasterProviderInterface as a factory returning CasterProvider.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固