tebru/enum 问题修复 & 功能扩展

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

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

tebru/enum

Composer 安装命令:

composer require tebru/enum

包简介

Simple enum library for PHP

README 文档

README

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight

Enum

A simple PHP library to add support for enums. This requires slightly more work than myclabs/php-enum, but does not require reflection. It also forces enums to be singletons.

Installation

composer require tebru/enum

Usage

To use, extend AbstractEnum and implement the getConstants() method.

class DirectionEnum extends AbstractEnum
{
    const NORTH = 'north';
    const EAST = 'east';
    const SOUTH = 'south';
    const WEST = 'west';

    /**
     * Return an array of enum class constants
     *
     * @return array
     */
    public static function getConstants()
    {
        return [
            self::NORTH,
            self::EAST,
            self::SOUTH,
            self::WEST,
        ];
    }
}

Now you can create a new instance using the static method.

DirectionEnum::create('north');

You can also create an instance using the __callStatic magic method.

DirectionEnum::NORTH();

Add a hint to the enum doc block

/**
 * @method static $this NORTH()
 */

Reference

There are multiple methods available on each enum

  • create() [static] Returns an instance of the enum
  • values() [static] A 0-indexed array of all of the enum values
  • exists($value) [static] Returns true if the value exists
  • toArray() [static] Returns a hash with keys and values as the enum values
  • equals($enum) Performs a strict comparison of two enum values
  • getValue() Returns the current value of the enum
  • __toString() Same as getValue()

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固