承接 kongulov/interact-with-enum 相关项目开发

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

邮箱: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"
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固