承接 pkly/enum-attribute-utils 相关项目开发

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

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

pkly/enum-attribute-utils

Composer 安装命令:

composer require pkly/enum-attribute-utils

包简介

Helper for easy attribute load/cache/fetch etc. in PHP Enums

README 文档

README

Helper for easy attribute load/cache/fetch etc. in PHP Enums

Packagist Downloads

Installation

Simply run

composer require pkly/enum-attribute-utils

Usage

Example use on an enum.

use Pkly\EnumAttributeUtils\AttributeControlTrait;

enum ExampleEnum
{
    use AttributeControlTrait;

    #[NotAllowed]
    case Foo;

    #[CustomStuff(true)]
    case Bar;

    /**
     * @return list<self>
     */
    public static function getNotAllowed(): array
    {
        return self::findCases(NotAllowed::class);
    }

    public function isNotAllowed(): bool
    {
        return self::attributeExists(NotAllowed::class, $this);
    }

    public function getCustom(): CustomStuff|null
    {
        return self::findAttribute(CustomStuff::class, $this);
    }
    
    public function getCustomWithTrue(): CustomStuff|null
    {
        return self::findAttribute(CustomStuff::class, $this, static fn (CustomStuff $s) => $s->thing);    
    }
}

See the trait for more methods. You can use the $filter parameter to better revise results, so that you don't have to create multiple classes to gain the same functionality.

Attributes are preloaded once per enum and stored in AttributeCache.

It's not suggested to touch said class, it's required as enums cannot contain properties.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固