kongulov/interact-with-enum 问题修复 & 功能扩展

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

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

kongulov/interact-with-enum

最新稳定版本:1.1.0

Composer 安装命令:

composer require kongulov/interact-with-enum

包简介

Trait for convenient use of ENUM in PHP

关键字:

README 文档

README

Latest Version on Packagist Licence Total Downloads

This package contains the InteractWithEnum.php trait, which you can use to conveniently work with ENUMs.

Requirements

  • php: >=8.1

Installation

Install the package via Composer:

# Install interact-with-enum
composer require kongulov/interact-with-enum

Usage

Imagine you have ENUM StatusEnum.php where we already use the InteractWithEnum trait:

<?php

namespace App\Enums;

use Kongulov\Traits\InteractWithEnum;

enum StatusEnum: string {
    use InteractWithEnum;

    case Pending = 'pending';
    case Active = 'active';
    case Inactive = 'inactive';
}

After using the trait, you can call methods:

  • names()
StatusEnum::names()

Return:

array:3 [
  0 => "Pending"
  1 => "Active"
  2 => "Inactive"
]
  • values()
StatusEnum::values()

Return:

array:3 [
  0 => "pending"
  1 => "active"
  2 => "inactive"
]
  • array()
StatusEnum::array()

Return:

array:3 [
  "pending" => "Pending"
  "active" => "Active"
  "inactive" => "Inactive"
]
  • find($needle)
StatusEnum::find('Active') // Find by name
StatusEnum::find('active') // Find by value

Return:

App\Enums\StatusEnum {
  name: "Active"
  value: "active"
}
  • count()
StatusEnum::count()

Return:

3
  • exists($value)
StatusEnum::exists('active')

Return:

true
  • getByIndex($index)
StatusEnum::getByIndex(1)

Return:

App\Enums\StatusEnum {
  name: "Active"
  value: "active"
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-28