承接 dive-be/php-enum-utils 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

dive-be/php-enum-utils

最新稳定版本:1.4.0

Composer 安装命令:

composer require dive-be/php-enum-utils

包简介

Those utilities you always need when dealing with native enumerations.

README 文档

README

Latest Version on Packagist

This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

Installation

You can install the package via composer:

composer require dive-be/php-enum-utils

Usage

Assume the following string backed enum:

enum Role: string
{
    use \Dive\Enum\Arrayable;
    use \Dive\Enum\Assertable;
    use \Dive\Enum\Comparable;
    use \Dive\Enum\NameListable;
    use \Dive\Enum\ValueListable;

    case Administrator = 'admin';
    case Auditor = 'audit';
    case Moderator = 'mod';
}

Arrayable (backed enums only)

Allows you to retrieve a key-value pair of names and values:

Role::toArray(); // ['Administrator' => 'admin', 'Auditor' => 'audit', 'Moderator' => 'mod']

Assertable

This relies on the enum names being in PascalCase, which follows Larry Garfield's RFC.

Allows you to make assertions on enum instances using predicate functions:

$role = Role::Moderator;

$role->isAuditor(); // false
$role->isModerator(); // true

Comparable

Allows you to compare enums. Mostly useful when providing backed values:

$role = Role::Administrator;

$role->equals('admin'); // true
$role->equals(Role::Administrator); // true
$role->equals('mod'); // false
$role->equals(Role::Moderator); // false

$role->equalsAny(['admin', 'mod', 'audit']); // true
$role->equalsAny([Role::Administrator, Role::Auditor]); // true
$role->equalsAny([Role::Moderator, 'audit']); // false

NameListable

Allows you to retrieve a list of the enum names:

Role::toNames(); // ['Administrator', 'Auditor', 'Moderator']

ValueListable (backed enums only)

Allows you to retrieve a list of the enum values:

Role::toValues(); // ['admin', 'audit', 'mod']

WithUtilities (backed enums only)

Aggregator trait for all of the aforementioned utilities.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email oss@dive.be instead of using the issue tracker.

Credits

License

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

统计信息

  • 总下载量: 278.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 30
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固