ali-eltaweel/bitmask
最新稳定版本:1.0.0
Composer 安装命令:
composer require ali-eltaweel/bitmask
包简介
A simple bitmask library for PHP
README 文档
README
A simple bitmask library for PHP
Installation
Install bitmask via Composer:
composer require ali-eltaweel/bitmask
Usage
Declaring Bitmask
use Bitmask\{ Annotations\Bit, Bitmask }; class JsonOptions extends Bitmask { #[Bit] const PRETTY_PRINT = JSON_PRETTY_PRINT; #[Bit] const UNESCAPED_SLASHES = JSON_UNESCAPED_SLASHES; #[Bit] const OBJECT_AS_ARRAY = JSON_OBJECT_AS_ARRAY; }
Using the #[Bit] annotation with no arguments will result in the name of the constant being used as the bit's name. You can also pass a string to the annotation to specify a custom name for the bit:
use Bitmask\{ Annotations\Bit, Bitmask }; class JsonOptions extends Bitmask { #[Bit('pretty')] const PRETTY_PRINT = JSON_PRETTY_PRINT; #[Bit('forceArray')] const OBJECT_AS_ARRAY = JSON_OBJECT_AS_ARRAY; }
Working with Bitmasks
$jsonOptions = new JsonOptions(JsonOptions::PRETTY_PRINT); $jsonOptions->has(JsonOptions::PRETTY_PRINT); // true $jsonOptions->has(JsonOptions::UNESCAPED_SLASHES); // false $jsonOptions = $jsonOptions->add(JsonOptions::UNESCAPED_SLASHES); $jsonOptions->has(JsonOptions::UNESCAPED_SLASHES); // true $jsonOptions = $jsonOptions->remove(JsonOptions::PRETTY_PRINT); $jsonOptions->has('pretty'); // false $jsonOptions = $jsonOptions->add('pretty|forceArray'); $jsonOptions->has('pretty'); // true $jsonOptions->has(JsonOptions::OBJECT_AS_ARRAY); // true $jsonOptions->toArray(); // [ 128 => 'pretty', 64 => 'UNESCAPED_SLASHES', 1 => 'forceArray' ] $jsonOptions->toInt(); // 193
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-06-20