Last active
December 31, 2015 12:49
-
-
Save dinamic/7988656 to your computer and use it in GitHub Desktop.
Generic bitwise tester
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 | |
class BitwiseTester | |
{ | |
/** | |
* | |
* @var int | |
*/ | |
protected $flags = 0; | |
/** | |
* | |
* @param int $flag | |
* @return $this | |
*/ | |
public function setFlag($flag) | |
{ | |
$this->flags |= $flag; | |
return $this; | |
} | |
/** | |
* | |
* @param array $flags | |
* @return $this | |
*/ | |
public function setFlags(array $flags) | |
{ | |
foreach ($flags as $flag) { | |
$this->setFlag($flag); | |
} | |
return $this; | |
} | |
/** | |
* | |
* @return $this | |
*/ | |
public function clearFlags() | |
{ | |
$this->flags = 0; | |
return $this; | |
} | |
/** | |
* | |
* @param int $flag | |
* @return boolean | |
*/ | |
public function hasFlag($flag) | |
{ | |
return (($this->flags & $flag) === $flag); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment