genkiroid / enum-generator
Generate sub class of enum from definition file.
0.2.1
2018-05-04 00:22 UTC
Requires
- php: ^7.1
- nikic/php-parser: ^4.0
- symfony/yaml: ^4.0
Requires (Dev)
- phpunit/phpunit: ^7.1
README
Generate PHP class definition that extends Enum class from file(yaml, json).
Installation
composer require genkiroid/enum-generator
Usage
Generate to STDOUT.
enum-generator --in enums.yaml
Generate to files. (Specify output dir.)
enum-generator --in enums.yaml --out /tmp/enums/
Generate to files. (Overwrite.)
enum-generator --in enums.yaml --out /tmp/enums/ --force
Input file format
YAML
--- - User: state: active: 0 inactive: 1 - Shop: state: active: 0 inactive: 1
JSON
[ { "User": { "state": { "active": 0, "inactive": 1 } } }, { "Shop": { "state": { "active": 0, "inactive": 1 } } } ]
Output
STDOUT.
<?php class UserState extends Enum { const ACTIVE = 0; const INACTIVE = 1; } <?php class ShopState extends Enum { const ACTIVE = 0; const INACTIVE = 1; }
Files.
UserState.php ShopState.php
Tips
You can use genkiroid/enum_exporter to create input file from existing Ruby on Rails application.