hectororm/data-types

Hector Data Types

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

This package is auto-updated.

Last update: 2024-11-02 14:59:26 UTC


README

Latest Version Software license Build Status Quality Grade Total Downloads

Hector Data Types is the module to manage types of Hector ORM. Can be used independently of ORM.

Installation

Composer

You can install Hector Data Types with Composer, it's the recommended installation.

$ composer require hectororm/data-types

Dependencies

  • PHP ^8.0
  • Extensions dependencies:
    • ext-pdo

Usage

Each type converter implement interface:

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;
}

Attempted excepted type is a representation of PHP type of property.