maximaster/atoa 问题修复 & 功能扩展

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

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

maximaster/atoa

最新稳定版本:v1.0.0

Composer 安装命令:

composer require maximaster/atoa

包简介

Convert a value to another value using your own callables.

README 文档

README

Convert a value to another value using your own callables.

composer require maximaster/atoa

Example

namespace Maximaster\Atoa;

use Maximaster\Atoa\Contract\Atoa;
use Maximaster\Atoa\Converter;

class A { public function __construct(public string $value) {} }
class B { public function __construct(public string $value) {} }

// Implement converters for all needed cases.
// Make sure that callable has both input and return types described.
$converter = new Converter([
    static fn (A $a): B => new B($a->value),
    static fn (B $b): A => new A($b->value),
    static fn (string $c): int => intval($c),
]);

// Use Atoa interface instead of implementation in your services.
(static function (Atoa $atoa): void {
    // Ask converter to get desired type and pass any other type.
    // If the converter does know how to convert this object to desired type, it
    // would do it.
    $a = $converter->convertTo(A::class, new B('hello')); // A('hello')
    $b = $converter->convertTo(B::class, new A('hello')); // B('hello')
    $c = $converter->convertTo('int', '42'); // 42
})($converter);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-03