extalion / php-enum
Gives the ability to emulate and create enumeration objects in PHP.
Installs: 625
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/extalion/php-enum
Requires
- php: ^7.2
This package is auto-updated.
Last update: 2025-10-13 05:11:03 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