tyam/fadoc

表数组到域对象转换器/验证器

0.1.3 2018-06-11 05:32 UTC

This package is not auto-updated.

Last update: 2024-09-26 08:16:09 UTC


README

fadoc 会根据方法类型声明自动将表数组与域对象相互转换。

功能

  • 根据域对象的声明自动执行转换。无需表类。
  • 您可以在域对象上定义验证逻辑。
  • 支持工厂、抽象类/接口。

基本用法

class Point {
    private $x, y;
    public function __construct(int $x, int $y) {...}
}
class Circle {
    private $c, $r;
    public function __construct(Point $c, int $r) {...}
    public function intersects(Circle $another): bool {...}
}

$form = ['another' => [
           'c' => ['x' => '0', 'y' => '20'],
           'r' => '10'
        ]];
$c = new tyam\fadoc\Converter();
$condition = $c->objectize(['my\domain\Circle', 'intersects'], $form);
if ($condition->isFine()) {
    list($another) = $condition->get();
    $result = $myCircle->intersects($another);
} else {
    // validation error...
}

安装

$ composer require tyam/fadoc

fadoc 依赖于 tyam/condition,这也是我的库。

文档

许可证

MIT