fatihirday/enummethods

v1.0.0 2023-02-05 18:19 UTC

This package is auto-updated.

Last update: 2024-05-05 21:06:23 UTC


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