Skip to content

Instantly share code, notes, and snippets.

@dinamic
Last active December 31, 2015 12:49
Show Gist options
  • Save dinamic/7988656 to your computer and use it in GitHub Desktop.
Save dinamic/7988656 to your computer and use it in GitHub Desktop.
Generic bitwise tester
<?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