genkiroid/enum-generator

Generate sub class of enum from definition file.

0.2.1 2018-05-04 00:22 UTC

This package is auto-updated.

Last update: 2024-11-28 10:40:48 UTC


README

build

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.

License

MIT

Author

genkiroid