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

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

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

wirus15/enum

Composer 安装命令:

composer require wirus15/enum

包简介

A simple PHP library for creating enum objects.

README 文档

README

A simple PHP library for creating Enum objects.

Examples

Defining a new Enum class

use Enum\Enum;

// defining our Enum class
final class Example extends Enum
{
    const FOO = 1;
    const BAR = 2;
    const YOLO = 3;
}

Basic usage

$foo = Example::get(Example::FOO);
$bar = Example::get('bar');
$yolo = Example::YOLO();

function test(Example $enum) 
{
    if ($enum->is(Example::FOO)) {
        echo 'foo';
    } else if ($enum->is(Example::BAR)) {
        echo 'bar';
    } else {
        echo $enum;
    }
}

test($foo);   // foo
test($bar);   // bar
test($yolo);  // Yolo

Getting Enum instances, listing keys and values

Example::get(Example::FOO);               // instance of Example
Example::FOO();                           // shortcut
Example::all();                           // array of Example instances

// keys and values
Example::keys();                          // array of keys ['FOO', 'BAR', 'YOLO']
Example::values();                        // array of values [1, 2, 3]

// checking if value exists
Example::has(3);                          // true
Example::has(4);                          // false

Getting single Enum properties

$foo = Example::FOO();
$foo->key();                              // 'FOO'
$foo->value();                            // 1

Comparing Enums

$foo = Example::FOO();
$foo->is(1);                              // true
$foo->is(Example::FOO);                   // true
$foo->is($foo);                           // true

// comparing with strict option (type comparison)
$foo->is($foo, true);                     // true
$foo->is(1, true);                        // false

// searching in array
$foo->in([1,2,3]);                        // true
$foo->in([2,3]);                          // false

You can also make static calls and specify Enum class

Enum::get(Example::FOO, Example::class);
Enum::all(Example::class);    
Enum::keys(Example::class);      
Enum::values(Example::class); 
Enum::has(1, Example::class);

Development and tests

To develop this lib we are using docker and docker-compose. After installation of those you should run:

bash
docker-compose run enum bash

Then on docker console run:

composer install
composer test

License

This library is released under MIT license.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固