hectororm/data-types

Hector Data Types

v1.0.0-beta4 2024-03-20 09:09 UTC

This package is auto-updated.

Last update: 2024-03-20 09:10:25 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.