Skip to content

A simple package to create PHP enum from a json file

License

Notifications You must be signed in to change notification settings

Ronildo-Sousa/enumer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enumer

Latest Version on Packagist Total Downloads

A simple package to create PHP enum from a Json.

Installation

You can install the package via composer:

composer require ronildo-sousa/enumer

Usage

$json = '{"Hearts": "H", "Diamonds": "D", "Clubs": "C", "Spades": "S"}';

$enumer = new RonildoSousa\Enumer();
$enumer->convertJson(json: $json, file_path: '/Enums/Test.php');

It will create a class like this:

enum Test: string
{
    
   case Hearts = "H";

   case Diamonds = "D";

   case Clubs = "C";

   case Spades = "S";

}

You can change the return type of the enum:

$json = '{"Guest": 1, "Editor": 2, "Admin": 3, "Owner": 4}';

$enumer = new RonildoSousa\Enumer();
$enumer->convertJson(json: $json, file_path: '/Enums/Test.php', returnType: 'int');

It will create a class like this:

enum Test: int
{
    
   case Guest = 1;

   case Editor = 2;

   case Admin = 3;

   case Owner = 4;

}

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

About

A simple package to create PHP enum from a json file

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages