https://github.com/extalionlab/php-enum
Gives the ability to emulate and create enumeration objects in PHP.
https://github.com/extalionlab/php-enum
enum php type
Last synced: 15 days ago
JSON representation
Gives the ability to emulate and create enumeration objects in PHP.
- Host: GitHub
- URL: https://github.com/extalionlab/php-enum
- Owner: eXtalionLab
- License: mit
- Created: 2019-05-26T12:12:16.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-04-24T21:05:22.000Z (about 6 years ago)
- Last Synced: 2025-01-05T01:41:46.025Z (over 1 year ago)
- Topics: enum, php, type
- Language: PHP
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# php-enum
Gives the ability to emulate and create enumeration objects in PHP.
## Install
```bash
composer install extalion/php-enum
```
## How to use
Enum definition:
```php
/**
* @method static RequestMethod get()
* @method static RequestMethod post()
*/
final class RequestMethod extends \Enum
{
const VALUES = [
'get' => 1,
'post' => 2
];
}
```
Usage:
```php
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
php -d zend.assertions=1 test.php
```