1. Go to this page and download the library: Download k2gl/enum library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
k2gl / enum example snippets
use K2gl\Enum\src\ExtendedBackedEnumInterface;use K2gl\Enum\Types\ExtendedBackedEnum\ExtendedBackedEnum;
enum CardSuit: string implements ExtendedBackedEnumInterface
{
use ExtendedBackedEnum;
case HEARTS = 'hearts';
case DIAMONDS = 'diamonds';
case CLUBS = 'clubs';
case SPADES = 'spades';
}
enum ResponseCode: int implements ExtendedBackedEnumInterface
{
use ExtendedBackedEnum;
case HTTP_OK = 200;
case HTTP_I_AM_A_TEAPOT = 418;
}
$suit = CardSuit::any(); // random CardSuit
$suit = CardSuit::anyoneExcept(CardSuit::CLUBS); // random CardSuit except 'clubs'
$suit = CardSuit::anyoneExcept([CardSuit::HEARTS, CardSuit::DIAMONDS]); // random CardSuit except 'hearts' and 'diamonds'
$suit = CardSuit::SPADES;
$suit->is(CardSuit::SPADES); // true
$suit->is('spades'); // true
$suit->is(CardSuit::HEARTS); // false
$suit = ResponseCode::HTTP_I_AM_A_TEAPOT;
$suit->isNot(200); // true
$suit->isNot(ResponseCode::HTTP_OK); // true
$suit->isNot(418); // false
$suit->isNot(ResponseCode::HTTP_I_AM_A_TEAPOT); // false
CardSuit::names(); // ['HEARTS', 'DIAMONDS', 'CLUBS', 'SPADES']
CardSuit::values(); // ['hearts', 'diamonds', 'clubs', 'spades']
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.