Skip to content

ismailocal/whenable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Whenable

User Class With WhenableTrait

class User{
    use \Ismailocal\Whenable\WhenableTrait;

    protected $id;
    protected $name;
    protected $active = true;

    public function __construct($id, $name)
    {
        $this->id = $id;
        $this->name = $name;
    }
    
    public function setPassive(){
      // Logic
    }
}

Example Usage

$user = new User(1, 'ismailocal');

$user->when(function (){
    return $this->active;
})->then(function(){
    $this->setPassive();
})->else(function(){
    log($this->name +' not active user!')
});

Example Usage Without Trait

$user = new User(1, 'ismailocal');

\Ismailocal\Whenable\Whenable::when(function () use($user){
    return $user->active;
})->then(function () use($user){
    $user->setPassive();
})->else(function () use($user){
    log($user->name +' not active user!')
});

About

Php when then else, whenable trait

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages