2017 © Pedro Peláez
 

library hydrator

PHP PSR-7 compatible cacheable hydrator for modern application.

image

grzesie2k/hydrator

PHP PSR-7 compatible cacheable hydrator for modern application.

  • Monday, March 12, 2018
  • by Grzesie2k
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Hydrator

Build Status Coverage Status Maintainability, (*1)

PHP7 PSR-5 compatible cacheable hydrator for modern application., (*2)

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

The Versions

12/03 2018

dev-master

9999999-dev

PHP PSR-7 compatible cacheable hydrator for modern application.

  Sources   Download

MIT

The Requires

 

The Development Requires

10/03 2018

0.0.1

0.0.1.0

PHP PSR-7 compatible cacheable hydrator for modern application.

  Sources   Download

MIT

The Requires

 

The Development Requires