ismailocal / whenable
Php when, then, else pattern and whenable trait
dev-master
2019-08-14 18:00 UTC
This package is auto-updated.
Last update: 2025-05-15 08:10:55 UTC
README
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!') });