sufir / hydrator
Создание и гидрация объектов
1.0.2
2015-12-26 08:58 UTC
Requires
- php: >=5.6
Requires (Dev)
- phpunit/phpunit: 5.1.*
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
This package is not auto-updated.
Last update: 2024-11-09 19:32:43 UTC
README
Install
Via Composer
$ composer require sufir/hydrator
Usage
Using Instantiator.
<?php use Sufir\Hydrator\Instantiator; $instantiator = new Instantiator(); $newObject = $instantiator->newInstance('\Some\ClassName');
Using Hydrators.
<?php use Sufir\Hydrator\PlainArrayHydrator as Hydrator; $className = '\Namespace\Domain\Entity'; $hydrateData = [ // simple properties 'firstName' => 'John', 'lastName' => 'Doe', // id property of sub class \Namespace\Domain\Entity\Identity '__identity:Identity_id' => 100500, // some properties in subclass from another namespace '__uncloneableClass:\vendor\Some\Super\Class_someProperty1' => 'value 1', '__uncloneableClass:\vendor\Some\Super\Class_someProperty2' => null, // unexpected properties of subclass will be ignored '__uncloneableClass:\vendor\Some\Super\Class_unknownProperty' => '!undefined', // internal classes cannot be created and injected (in current version) //'__stdClass:\stdClass_unknownProperty' => '!undefined', ]; /* @var $object PrivateConstructor */ $object = $this->hydrator->hydrate($data, $className); var_dump($object);
class \Namespace\Domain\Entity (5) {
protected $firstName => string(4) "John"
protected $lastName => string(3) "Doe"
protected $identity =>
class \Namespace\Domain\Entity\Identity {
protected $id => int(100500)
}
protected $uncloneableClass =>
class \vendor\Some\Super\Class (2) {
public $someProperty1 => string(7) "value 1"
public $someProperty2 => NULL
}
}
Testing
$ composer test
Credits
License
The MIT License (MIT).