Skip to content

Latest commit

 

History

History
49 lines (37 loc) · 708 Bytes

File metadata and controls

49 lines (37 loc) · 708 Bytes

php-enum

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