ismailocal / whenable
Php when, then, else pattern and whenable trait
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/ismailocal/whenable
This package is auto-updated.
Last update: 2025-12-15 09:31:19 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!') });