Skip to content

PHP Library to hydratate objects with class setters

License

Notifications You must be signed in to change notification settings

ferfabricio/hydrator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codecov

Hydrator

PHP Library to hydrate objects with class setters

Instalation

composer require ferfabricio/hydrator

How use

If you have a class like this:

class Example
{
    private $test;

    public function setTest($test)
    {
        $this->test = $test;
    }

    public function getTest()
    {
        return $this->test;
    }
}

And need to create a object from an array:

$myData = [
    'test' => 'this is a test'
];

You can use FerFabricio\Hydrator\Hydrate to do this work in a simple way:

use FerFabricio\Hydrator\Hydrate;

class Example
{
    private $test;

    public function setTest($test)
    {
        $this->test = $test;
    }

    public function getTest()
    {
        return $this->test;
    }
}

$myData = [
    'test' => 'this is a test'
];

$example = Hydratate::toObject(Example::class, $myData);
echo $example->getTest(); // This line will print: this is a test

Autoload

This library is only compatible with PSR-4, please be sure if your application is well configured to work with this.

About

PHP Library to hydratate objects with class setters

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages