定制 outerweb/enum-helpers 二次开发

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

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

outerweb/enum-helpers

最新稳定版本:v2.0.0

Composer 安装命令:

composer require outerweb/enum-helpers

包简介

Traits to make working with Enums a breeze in Laravel.

README 文档

README

Enum helpers

Enum helpers

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides a set of traits you can use to extend the functionality of your enums in Laravel.

Table of Contents

Installation

You can install the package via composer:

composer require outerweb/enum-helpers

Usage

Collection support

Add the following trait to your backed enum to get collection support:

use Outerweb\EnumHelpers\HasCollectionSupport;

enum MyEnum: string
{
    use HasCollectionSupport;

    case Foo = 'foo';
    case Bar = 'bar';

    public function getLabel(): string
    {
        return match ($this) {
            self::Foo => 'Foo label',
            self::Bar => 'Bar label',
        };
    }
}

This allows you to collect enum cases easily into a Laravel collection:

$collection = MyEnum::collect(); // Collection{'foo' => MyEnum::Foo, 'bar' => MyEnum::Bar}

Getting a collection of values

You can get a collection of enum values using the collect('value') method:

$values = MyEnum::collect('value'); // Collection{'foo' => 'foo', 'bar' => 'bar'}

Getting a collection of return values of a function

You can get a collection of return values of a function by passing the function name to the collect() method:

$mapped = MyEnum::collect('getLabel'); // Collection{'foo' => 'Foo label', 'bar' => 'Bar label'}

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-25