PHP code example of aaronbullard / firehose

1. Go to this page and download the library: Download aaronbullard/firehose 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/ */

    

aaronbullard / firehose example snippets


class Foo
{
    private $bar;
    protected $baz;
    private $qux;

    public function __construct($bar, $baz = null, $qux = null)
    {
        $this->bar = $bar;
        $this->baz = $baz;
        $this->qux = $qux;
    }

    public function bar(){ return $this->bar; }
    public function baz(){ return $this->baz; }
}

use Firehose\Hydrator;

$foo = Hydrator::newInstance(Foo::class, [
    'bar' => 'bar',
    'baz' => 'baz'
]);

$this->assertInstanceOf(Foo::class, $foo);
$this->assertEquals('bar', $foo->bar());
$this->assertEquals('baz', $foo->baz());

$foo = new Foo('bar', 'baz');

Hydrator::mutate($foo, [
    'bar' => 'newBar'
]);

$this->assertEquals('newBar', $foo->bar());

$foo = new Foo('bar', 'baz', 'qux');

$data = Hydrator::extract($foo, ['bar', 'baz', 'qux']);

$this->assertEquals('bar', $data['bar']);
$this->assertEquals('baz', $data['baz']);
$this->assertEquals('qux', $data['qux']);