PHP code example of battis / hydratable

1. Go to this page and download the library: Download battis/hydratable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

battis / hydratable example snippets


use Battis\Hydratable\Hydratable;

class MyObject
{
    use Hydratable;

    private static $DEFAULTS = [
      'foo' => 'bar',
      'argle' => 'bargle'
    ]

    private $options;

    public function __construct(array $params = [])
    {
        $this->options = $this->hydrate($params, self::$DEFAULTS);
    }
}

$o = new MyObject(['baz' => 123, 'argle' = 'BaRgLe']);

/*
$o->options = [
    'foo' => 'bar',
    'baz' => 123,
    'argle' => 'BaRgLe'
]
*/

$hydrate = new Battis\Hydratable\Hydrate();
$options = $hydrate($params, $defaults);