hectororm/data-types

Hector 数据类型

v1.0.0-beta5 2024-07-02 14:13 UTC

This package is auto-updated.

Last update: 2024-09-02 14:40:51 UTC


README

Latest Version Software license Build Status Quality Grade Total Downloads

Hector 数据类型是用于管理 Hector ORM 类型的一个模块。可以独立于 ORM 使用。

安装

Composer

您可以使用 Composer 安装 Hector 数据类型,这是推荐的安装方式。

$ composer require hectororm/data-types

依赖

  • PHP ^8.0
  • 扩展依赖
    • ext-pdo

用法

每个类型转换器实现接口

use Hector\DataTypes\ExpectedType;

interface TypeInterface
{
    /**
     * From schema function.
     *
     * @return string|null
     */
    public function fromSchemaFunction(): ?string;

    /**
     * From schema to entity.
     *
     * @param mixed $value
     * @param ExpectedType|null $expected
     *
     * @return mixed
     */
    public function fromSchema(mixed $value, ?ExpectedType $expected = null): mixed;

    /**
     * To schema function.
     *
     * @return string|null
     */
    public function toSchemaFunction(): ?string;

    /**
     * From entity to schema.
     *
     * @param mixed $value
     * @param ExpectedType|null $expected
     *
     * @return mixed
     */
    public function toSchema(mixed $value, ?ExpectedType $expected = null): mixed;

    /**
     * Get binding type.
     * Must return a PDO::PARAM_* value.
     *
     * @return int|null
     */
    public function getBindingType(): ?int;
}

尝试的预期类型是属性的 PHP 类型表示。