fatihirday / enummethods
PHP enum methods
v1.0.0
2023-02-05 18:19 UTC
Requires
- php: ^8.1
README
Installation
composer require fatihirday/enummethods
Examples
Create Enum
<?php use Fatihirday\EnumMethods\EnumMethods; enum HttpMethods: string { use EnumMethods; case GET = 'get'; case POST = 'post'; }
Get Enum All Names
<?php HttpMethods::names(); // Array // ( // [0] => GET // [1] => POST // ) HttpMethods::names(operator: ', '); // GET, POST
Get Enum All Values
<?php HttpMethods::values(); // Array // ( // [0] => get // [1] => post // ) HttpMethods::values(operator: ', '); // get, post
Enum to Array
<?php HttpMethods::toArray(); // Array // ( // [GET] => get // [POST] => post // ) HttpMethods::toArray(reverse: true); // Array // ( // [get] => GET // [post] => POST // )
Enum to Object
<?php HttpMethods::toObject(); // Object // ( // get => GET // post => POST // ) HttpMethods::toObject(reverse: true); // Object // ( // get => GET // post => POST // )
Enum summoner
<?php HttpMethods::getValueByName('GET'); // get HttpMethods::getNameByValue('get'); // GET
Enum name check
<?php HttpMethods::tryFromName('GET'); // True