Gives the ability to emulate and create enumeration objects in PHP.
composer install extalion/php-enum
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);
}
// ...
}
php -d zend.assertions=1 test.php