PHP code example of hollisho / object-builder

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

    

hollisho / object-builder example snippets


$objectBuilder = ObjectBuilder::build(User::class, [
    'id' => 1,
    'username' => 'Hollis'
]);

//get username
var_dump($objectBuilder->username);

//or 
$user = HUser::build([
    'id' => 2,
    'username' => 'Hollis Ho'
]);

//get username
var_dump($user->username);

//setter

class HUser extends HObject
{
    public $id;

    public $username;

    //use setter
    public function setGrade($value)
    {
        $this->username = $value . ':' . $this->username;
    }
}

$user = HUser::build([
    'id' => 2,
    'username' => 'Hollis Ho'
]);

$user->grade = 'grade 1';
//or
$user->setGrade('grade 1');


$user = HUser::build()->id(2)->username('hollis');
echo $user->id; // 2
echo $user->username; // hollis
sh
$ ./vendor/phpunit/phpunit/phpunit --configuration phpunit.xml --test-suffix TemplateTest.php