PHP Classes

File: examples/example.php

Recommend this page to a friend!
  Packages of Johnny Mast   Redbox Hydrate   examples/example.php   Download  
File: examples/example.php
Role: Example script
Content type: text/plain
Description: Demo
Class: Redbox Hydrate
Popular object variables from array data
Author: By
Last change: Update of examples/example.php
Date: 4 years ago
Size: 968 bytes
 

 

Contents

Class file image Download
<?php
require 'autoload.php';

use Redbox\Hydrate\Hydrator;
use function Redbox\Hydrate\Helpers\Hydrate;

class User {
    protected $username = '';
    private $password = '';

    /**
     * @return string
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * @return string
     */
    public function getPassword()
    {
        return $this->password;
    }
}

/**
 * Method 1
 */
$result1 = Hydrator::hydrate(new User())->with(
    [
        'username' => 'abc',
        'password' => 'pass'
    ]
);

/**
 * Method 2
 */
$result2 = Hydrate(new User())->with(
    [
        'username' => 'abc',
        'password' => 'pass'
    ]
);

/**
 * Method 3
 */
$hydrator = new Hydrator(new User());
$result3 = $hydrator->with(
    [
        'username' => 'abcs',
        'password' => 'pass'
    ]
);

unset($hydrator);

/**
 * Dump whatever you want
 */
//var_dump($result1);
//var_dump($result2);
//var_dump($result3);