Created
October 30, 2023 15:32
-
-
Save bubba-h57/22586c2fc2173b81027e4fb54d2452f9 to your computer and use it in GitHub Desktop.
When/Unless Trait for PHP Objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
trait Conditionable | |
{ | |
public function when($condition, $callable) | |
{ | |
if ($condition) { | |
$callable($this, $condition); | |
} | |
return $this; | |
} | |
public function unless($condition, $callable) | |
{ | |
return $this->when(!$condition, $callable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment