Created
June 21, 2016 11:51
-
-
Save marcojetson/c415b5a7e4c2162e9eb06ab31216da55 to your computer and use it in GitHub Desktop.
Flag trait
This file contains 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 FlagTrait | |
{ | |
/** @var int */ | |
private $flags = 0; | |
/** | |
* @param int $flag | |
* @return bool | |
*/ | |
public function flagged($flag) | |
{ | |
return (bool)($this->flags & pow($flag, 2)); | |
} | |
/** | |
* @param int $flag | |
*/ | |
public function flag($flag) | |
{ | |
$this->flags |= pow($flag, 2); | |
} | |
/** | |
* @param int $flag | |
*/ | |
public function unflag($flag) | |
{ | |
$this->flags &= ~pow($flag, 2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment