Skip to content
This repository has been archived by the owner on Oct 29, 2020. It is now read-only.
/ Hydrator Public archive

PHP7 PSR-5 compatible cacheable hydrator for modern application.

License

Notifications You must be signed in to change notification settings

Grzesie2k/Hydrator

Repository files navigation

Hydrator

Build Status Coverage Status Maintainability

PHP7 PSR-5 compatible cacheable hydrator for modern application.

Installation

composer install grzesie2k/hydrator

Examples

  • Validate primitive type
<?php

$hydrator = $hydratorFactory->createHydrator('int[]'); // any valid type

$intList = $hydrator->hydrator([1, 2, 3]); // ✓ OK
$intList = $hydrator->hydrator([1, 'a', 2]); // ☹ exception
  • Hydrate Your class by constructor
<?php

class Example
{
    /**
     * @param int $id
     * @param string $name we can read types from PHPDoc
     */
    public function __construct(int $id, $name) // or from type hints
    {
        // ... some operation
    }
}

$hydrator = $hydratorFactory->createHydrator(Example::class);

$hydrator->hydrate(\json_decode('{"id":2,"name":"Adam"}')); // ✓ OK
$hydrator->hydrate(\json_decode('{"id":"Nope","name":"Janek"}')); // ☹ exception

To do

  • create hydrator strategy to handle compound type (eq. int|string)
  • create alternative object hydration strategy (without constructor)
  • create hydrator strategies for some built-in types (eg. DateTime)
  • handle hydration exceptions with internal class and better messages
  • create symfony/laravel bundle
  • add examples and better docs

About

PHP7 PSR-5 compatible cacheable hydrator for modern application.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages