PHP Classes

File: examples/example.php

Recommend this page to a friend!
  Classes 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: Updated example.php
Updated README.md
Date: 11 months 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);

For more information send a message to info at phpclasses dot org.