Skip to content

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

License

Notifications You must be signed in to change notification settings

eXtalionLab/php-enum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages