convoflo/ordered-enum 问题修复 & 功能扩展

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

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

convoflo/ordered-enum

最新稳定版本:1.0.0

Composer 安装命令:

composer require convoflo/ordered-enum

包简介

Give your enums an order. Provides utilities such as greaterThan, lessThan, min, max and more.

README 文档

README

This package gives your enums an order. It provides helper utilities such as ->greaterThan(), ->lessThan(), ::min(), ::max() and more.

Installation

You can install the package via composer:

composer require convoflo/ordered-enum

Usage

This is how an ordered enum can be defined.

use \Convoflo\OrderedEnum\OrderedBackedEnum;
use \Convoflo\OrderedEnum\OrderedTrait;

enum UserRole: string implements OrderedBackedEnum
{
    use OrderedTrait;

    case Admin = 'admin';
    case Regular = 'user';
    case Basic = 'basic';

    public static function order(): array
    {
        return [self::Basic, self::Regular, self::Admin];
    }
}

Here's how ordered enums are used with their helpers:

$showAdminConsole = $userRole->greaterThan(UserRole::Regular);
$showMinimalInterface = $userRole->lessThan(UserRole::Regular);

$isNotBasic = $userRole->greaterThanOrEqualsTo(UserRole::Regular);
$isNotAdmin = $userRole->lessThanOrEqualsTo(UserRole::Regular);

UserRole::min(UserRole::Basic, UserRole::Admin); // UserRole::Basic
UserRole::max(UserRole::Basic, UserRole::Admin); // UserRole::Admin

$highestRole = UserRole::max(); // UserRole::Admin
$lowestRole = UserRole::min(); // UserRole::Basic

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 28
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-12-03