y-tsuzaki/php-enum-spy
最新稳定版本:v0.1.2
Composer 安装命令:
composer require y-tsuzaki/php-enum-spy
包简介
A CLI tool to extract a list of Enum definitions from PHP files.
README 文档
README
A PHP CLI tool for extracting Enum definitions. Outputs Enum definitions to CSV and JSON files for easy access and analysis.
Example
This tool can output JSON files like the following.
{
"enums": {
"YTsuzaki\\PhpEnumSpyExample\\ExampleEnum": {
"className": "ExampleEnum",
"namespace": "YTsuzaki\\PhpEnumSpyExample",
"fully_qualified_class_name": "YTsuzaki\\PhpEnumSpyExample\\ExampleEnum",
"filePath": "/Users/y-tsuzaki/work/php-enum-spy-example/src/ExampleEnum.php",
"cases": {
"IN_PROGRESS": {
"name": "IN_PROGRESS",
"value": "in_progress",
"displayName": "進行中"
},
"PUNIRU": {
"name": "PUNIRU",
"value": "puniru_is_cute_slime",
"displayName": "ぷにるはかわいいスライム"
}
}
}
}
}
CSV files are output in the following format.
class_name,file_path,case,value,displayName
"YTsuzaki\PhpEnumSpyExample\ExampleEnum",/Users/y-tsuzaki/work/php-enum-spy-example/src/ExampleEnum.php,IN_PROGRESS,in_progress,進行中
"YTsuzaki\PhpEnumSpyExample\ExampleEnum",/Users/y-tsuzaki/work/php-enum-spy-example/src/ExampleEnum.php,PUNIRU,puniru_is_cute_slime,ぷにるはかわいいスライム
The Enum class used in the sample is as follows.
<?php declare(strict_types=1); namespace YTsuzaki\PhpEnumSpyExample; enum ExampleEnum: string { case TODO = 'todo'; case IN_PROGRESS = 'in_progress'; case DONE = 'done'; case PUNIRU = "puniru_is_cute_slime"; public function toDisplay(): string { return match ($this) { self::TODO => '未完了', self::IN_PROGRESS => '進行中', self::DONE => '完了', self::PUNIRU => 'ぷにるはかわいいスライム', }; } }
Please refer to the following Example repository for details. https://github.com/y-tsuzaki/php-enum-spy-example
Configuration
Create a configuration file php-enum-spy.config.php in the root directory of your project.
<?php $config = [ "dirs" => [ // Add the directory where the Enum class file is located "src", ], "convert_functions" => [], ]; return $config;
Custom conversion function
If you want to read the method in Enum and convert the value, add a custom conversion function as follows.
<?php $config = [ "dirs" => [ // Add the directory where the Enum class file is located "src", ], "convert_functions" => [ // Add your custom convert function if needed "your_custom_function" => function (UnitEnum $enum) { if (method_exists($enum, 'toJapanese')) { return $enum->toJapanese(); } return null; }, ], ]; return $config;
Installation
composer require --dev y-tsuzaki/php-enum-spy
Usage
Create a configuration file (php-enum-spy.config.php) based on the above description.
vi php-enum-spy.config.php
Run the following command.
vendor/bin/php-enum-spy
CSV files and JSON files are output to ./output.
output
├── enum_metadata.csv
└── enum_metadata.json
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-05