承接 macrominds/enum 相关项目开发

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

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

macrominds/enum

Composer 安装命令:

composer require macrominds/enum

包简介

A simple enum implementation for php that allows for typehinting.

README 文档

README

Build Status

Usage

Example

In order to create a blazingly simple Salutation enum, just create it as follows:

use macrominds\enum\Enumerations;


class Salutation
{
	use Enumerations;
    protected static $enums = [
            'MRS' => 1,
            'MR' => 2,
            'MS' => 3
        ];
}

If you require complex epressions for your enum values, just take the alternative static method approach and you're fine.

//alternative approach

use macrominds\enum\Enumerations;

class AnyValueEnum
{
	use Enumerations;

    protected static function enums(){
    	return [
    		'String' => 'string',
            'Integer' => 2,
            'Object' => Salutation::MR()
        ];
    }
}

That's it. You are now able to typehint your functions and you're sure that you get instances of your custom enum. See tests/EnumTest.php if you're in doubt. It shows which expectations you can make.

// example for type hinted function
public function save(Salutation $salutation) {
	saveToDB($salutation->value());
}

// example for fetching the enum from value
public function load($value) {
    // throws \Exception if $value is invalid
    return Salutation::fromValue($value);
}

// example for fetching the enum from key
public function loadKey($key) {
    // throws \Exception if $key is invalid
    return Salutation::fromKey($key);
}

IDE Support

In order to support code completion, you may want to give hints about the resulting methods:

use macrominds\enum\Enumerations;

/**
 * @method static \macrominds\enum\Salutation MRS()
 * @method static \macrominds\enum\Salutation MR()
 * @method static \macrominds\enum\Salutation MS()
 */
class Salutation
{
    use Enumerations;
    protected static $enums = [
            'MRS' => 1,
            'MR' => 2,
            'MS' => 3
        ];
}

Installation

composer require macrominds/enum.

TODO

  • More source documentation.
  • Make sure that configured names and values are unique: This is currently the developer's responsibility when creating a custom Enum.
  • Make php5.6 compatible

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固