brosua/enums
Composer 安装命令:
composer require brosua/enums
包简介
Helpers for PHP enums, especially for TYPO3 projects.
README 文档
README
Enums
Installation
Install this extension via composer req brosua/enums.
Concept
This package provides helpers for PHP enums. It is designed with a special focus on TYPO3 projects.
| URL | |
|---|---|
| Repository: | https://github.com/brosua/enums/ |
Usage
Simply apply the needed trait on your enum.
Base
Base includes all available traits.
use Brosua\Enums\Base; enum MyEnum: int { use Base; case One = 1; case Two = 1; protected static function getLanguageFilePath(): string { return 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:myEnum.'; } }
Now you can use all functions described for the following traits.
Translation
use Brosua\Enums\Translation; enum MyEnum: int { use Translation; case One = 1; case Two = 1; protected static function getLanguageFilePath(): string { return 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:myEnum.'; } }
Now you can use the following functions:
MyEnum::One->getLabel() // => 'translation1' MyEnum::One->getTranslationString() // => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:myEnum.One'
Options
use Brosua\Enums\Options; enum MyEnum: int { use Options; case One = 1; case Two = 1; }
Now you can use the following functions:
MyEnum::getOptions() // => [1 => 'translation1', 2 => 'translation2']
TcaOptions
use Brosua\Enums\TcaOptions; enum MyEnum: int { use TcaOptions; case One = 1; case Two = 1; protected static function getLanguageFilePath(): string { return 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:myEnum.'; } }
Now you can use the following functions:
MyEnum::getTcaOptions() // => [['label' => 'translation1', 'value' => 1], ['label' => 'translation2', 'value' => 2]]
From
use Brosua\Enums\From; enum MyEnum: int { use From; case One = 1; case Two = 1; }
Now you can use the following functions:
MyEnum::fromName('One') // => Enum instance One
统计信息
- 总下载量: 6.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2025-03-20