Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/steveleetn91/php-user-pattern

User Pattern Of PHP
https://github.com/steveleetn91/php-user-pattern

design-patterns hoanglee oops oops-in-php php php7 phpcore phpcore-framework stevelee vietnam

Last synced: about 1 month ago
JSON representation

User Pattern Of PHP

Awesome Lists containing this project

README

        



# 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('
-------- first build -------
');
print_r($admin->build());
print_r('
-------- next build -------
');
$admin->setName('Steve Jobs')
->setLocation('Silicon valley, US')
->setTodo('member');
print_r($admin->build());
print_r('
-------- next build -------
');
$admin->setName('Bill Gates')
->setTodo('member');
print_r($admin->build());
} catch (\Exception $e) {
echo "Debug
";
print_r($e);
}