extalion/php-enum

Gives the ability to emulate and create enumeration objects in PHP.

0.1.1 2020-04-24 21:00 UTC

This package is auto-updated.

Last update: 2024-04-13 01:49:24 UTC


README

Gives the ability to emulate and create enumeration objects in PHP.

Install

composer install extalion/php-enum

How to use

Enum definition:

/**
 * @method static RequestMethod get()
 * @method static RequestMethod post()
 */
final class RequestMethod extends \Enum
{
    const VALUES = [
        'get' => 1,
        'post' => 2
    ];
}

Usage:

function request(string $url, RequestMethod $method, array $data = [])
{
    // ...

    if ($method === RequestMethod::post()) {
        \curl_setopt($ch, \CURLOPT_POST, 1);
        \curl_setopt($ch, \CURLOPT_POSTFIELDS, $data);
    }

    // ...
}

Tests

php -d zend.assertions=1 test.php