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

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

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

simondeeley/enum

Composer 安装命令:

composer require simondeeley/enum

包简介

A simple ENUM object for PHP

README 文档

README

License Latest Stable Version Latest Unstable Version Build Status Scrutinizer Code Quality Code Coverage

A simple library for adding ENUM type objects into any existing or new PHP project.

Requirements

  • PHP >= 7.1

Installation

composer require simondeeley/enum

Usage

Create a new Enum class using your own chosen enum types

use simondeeley\enum;

class MyAwesomeEnum extends Enum
{
    const FOO = 'FOO';
    const BAR = 'BAR';
}

Now you can use your newly designed enum object in your code. Just simply instantiate a new MyAwesomeEnum every time you want to use an enum. The constants you defined in the class definition determine what the allowed values of the enum object can take. You can add as many constants as you wish, depending on your design needs.

Every time a new instance of your enum object is created, it requires that you pass a value to it's constructor. If the value passed to the constructor is not one of the pre-determined values then an InvalidArgumentException will be thrown.

use Acme\MyAwesomeEnum;

$good = new MyAwesomeEnum('FOO');
$bad = new MyAwesomeEnum('BAZ'); // throws an exception

Examples

This package provides two enums for out-of-the-box use, Boolean and Weekday. The first, Boolean leverages an enum that is either true or false whilst the second is a list of the days of the week.

use simondeeley\Enums\Boolean;
use simondeeley\Enums\Weekday;

$true = new Boolean('TRUE');
$true->getValue(); // returns (bool) true

$tuesday = new Weekday('TUESDAY');
$tuesday->getValue(); // returns (string) "Tuesday"

Although not mandatory when building enum objects, both Boolean and Weekday each provide short-cut static methods to quickly create a new object, for example:

$true = Boolean::true();

$saturday = Weekday::Saturday();

This functionality is built-in to any enums extending the base Enum type object. The only caveats are that when performing static method calls that it is best to keep in-line with PHP good coding practice and to ensure all constants are typed in uppercase.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2017-11-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固