定制 desmart/php-enum 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

desmart/php-enum

Composer 安装命令:

composer require desmart/php-enum

包简介

Strongly-typed enum objects for PHP

README 文档

README

Latest version Tests Software License

Package provides a strongly typed enums for PHP.

Enumeration class name is used on purpose, to avoid potential issues. There will be native enums in PHP 8.1 🎉

There are other great packages implementing enums for PHP. Consider checking them out!

Installation

To install the package via Composer, simply run the following command:

composer require desmart/php-enum

Usage

Example enum definition:

/**
 * @method static Character good()
 * @method static Character evil()
 * @method static Character sometimesGoodSometimesEvil()
 */
class Character extends Enumeration
{
    const GOOD = 'good';
    const EVIL = 'evil';
    const SOMETIMES_GOOD_SOMETIMES_EVIL = 'sometimes_good_or_evil';
}

Create an enum object

$enum = Character::good(); // or Character::fromName('good')

In general, named constructor method name should be a constant name in camelCase.

Few exceptions to this rule are allowed. See test file.

Create an enum object based on available constants' values

$enum = Character::fromValue('sometimes_good_or_evil');

This approach is very convenient when enum objects are created from eg. database.

Comparing enums

Character::good()->equals(Character::fromName('good')); // true
Character::good()->equals(Character::evil());           // false
Character::good()->equals(OtherEnum::someValue());      // false

Changelog

Please see CHANGELOG for more information what has changed recently.

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固