Skip to content

steveleetn91/php-user-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

63dd754 · Dec 14, 2021

History

47 Commits
Dec 13, 2021
Jun 28, 2020
Dec 13, 2021
Jun 26, 2020
Jun 28, 2020
Dec 13, 2021
Jun 27, 2020
Dec 13, 2021
Dec 13, 2021
Dec 14, 2021
Dec 13, 2021
Jun 27, 2020
Jun 26, 2020
Jun 26, 2020
Jun 27, 2020
Jun 27, 2020
Dec 14, 2021
Jun 27, 2020

Repository files navigation

Description

This module will support create user with : name, age, location, level, todo. This module is Builder Pattern of PHP

        -------- first build -------

        Array ( [name] => Steve Lee [age] => 11 [location] => HCM, Viet Nam [level] => Technical Leader [todo] => Array ( [post] => Array ( [update] => 1 [delete] => 1 [create] => 1 [view_all] => 1 ) [page] => Array ( [update] => 1 [delete] => 1 [create] => 1 [view_all] => 1 ) [setting] => Array ( [update] => 1 [create] => 1 ) ) )

        -------- next build -------

        Array ( [name] => Steve Job [age] => 11 [location] => Silicon valley, US [level] => Technical Leader [todo] => Array ( [post] => Array ( [update] => 1 [delete] => [create] => 1 [view_all] => ) [page] => Array ( [update] => 1 [delete] => [create] => 1 [view_all] => ) [setting] => Array ( [update] => [create] => ) ) )

        -------- next build -------

        Array ( [name] => Bill gates [age] => 11 [location] => Silicon valley, US [level] => Technical Leader [todo] => Array ( [post] => Array ( [update] => 1 [delete] => [create] => 1 [view_all] => ) [page] => Array ( [update] => 1 [delete] => [create] => 1 [view_all] => ) [setting] => Array ( [update] => [create] => ) ) )

install composer

php composer.phar install

Unit Test

./vendor/bin/phpunit test/UserTest.php

How to use ?

    try {
        require_once dirname(__FILE__) . '/UserBuilder.php';
        $admin = new UserBuilder;
        $admin->setName('Steve Lee')
            ->setAge(11)
            ->setLocation('HCM, Viet Nam')
            ->setLevel('Technical Leader')
            ->setTodo('admin');
        print_r('<br/>-------- first build ------- <br/>');
        print_r($admin->build());
        print_r('<br/>-------- next build ------- <br/>');
        $admin->setName('Steve Jobs')
            ->setLocation('Silicon valley, US')
            ->setTodo('member');
        print_r($admin->build());
        print_r('<br/>-------- next build ------- <br/>');
        $admin->setName('Bill Gates')
            ->setTodo('member');
        print_r($admin->build());
    } catch (\Exception $e) {
        echo "Debug<br/>";
        print_r($e);
    }