mfonte/bitmask
最新稳定版本:v1.0
Composer 安装命令:
composer require mfonte/bitmask
包简介
Bitmask class helps you to use all might of bit masks and don't care about what bitwise operations are. It represents a high-level abstraction that looks like simple and manageable object and behaves like collection.
README 文档
README
Bitmask class helps you to use all might of bit masks and don't care about what bitwise operations are. It represents a high-level abstraction that looks like simple and manageable object and behaves like collection.
Installation
Add the following dependency to your composer.json file.
{
"require": {
"mfonte/bitmask": "^1.0"
}
}
Example usage
For example we have User class that can have different roles.
use Mfonte\Bit\Mask; class User { const ROLE_ADMIN = Mask::FLAG_1; const ROLE_MANAGER = Mask::FLAG_2; const ROLE_CUSTOMER = Mask::FLAG_3; /** * @var Mask */ private $roles; public function __construct() { $this->roles = new Mask(); } public function becomeAdmin() { $this->roles->add(self::ROLE_ADMIN); } public function isAdmin() { return $this->roles->has(self::ROLE_ADMIN); } ... public function isCustomer() { return $this->roles->has(self::ROLE_CUSTOMER); } ... }
Now we are able to create a user.
$user = new User(); $user->becomeAdmin(); // User now has admin role $user->becomeAdmin(); // Throws MaskException because role has been already set // and mask is in strict mode $user->isAdmin(); // Returns true $user->isCustomer(); // Returns false
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-17