mfonte/bitmask 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固