PHP code example of tkaratug / powered-enum
1. Go to this page and download the library: Download tkaratug/powered-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/ */
tkaratug / powered-enum example snippets
use Tkaratug\PoweredEnum\PoweredEnum;
enum MyEnum: int
{
use PoweredEnum;
case ONE = 1;
case TWO = 2;
case THREE = 3;
}
$myEnum = MyEnum::ONE;
$myEnum->is(MyEnum::ONE); // true
$myEnum->is(MyEnum::TWO); // false
$myEnum->isNot(MyEnum::ONE); // false
$myEnum->isNot(MyEnum::TWO); // true
enum MyEnum: int {
use PoweredEnum;
case ONE = 1;
case TWO = 2;
}
MyEnum::hasName('ONE'); // true
MyEnum::hasName('THREE'); // false
enum MyEnum: int {
use PoweredEnum;
case ONE = 1;
case TWO = 2;
}
MyEnum::hasValue(1); // true
MyEnum::hasValue(3); // false
enum MyEnum: int {
use PoweredEnum;
case ONE = 1;
case TWO = 2;
}
MyEnum::getNames(); // ['ONE', 'TWO']
enum MyEnum: int {
use PoweredEnum;
case ONE = 1;
case TWO = 2;
}
MyEnum::getValues(); // [1, 2]
enum MyEnum: int {
use PoweredEnum;
case ONE = 1;
case TWO = 2;
}
MyEnum::toArray(); // [1 => 'ONE', 2 => 'TWO']
enum MyEnum: int {
use PoweredEnum;
case ONE = 1;
case TWO = 2;
case THREE = 3;
}
MyEnum::getNamesExcept([MyEnum::ONE]); // ['TWO', 'THREE']
enum MyEnum: int {
use PoweredEnum;
case ONE = 1;
case TWO = 2;
case THREE = 3;
}
MyEnum::getValuesExcept([MyEnum::ONE]); // [2, 3]
enum MyEnum: int {
use PoweredEnum;
case ONE = 1;
case TWO = 2;
case THREE = 3;
}
MyEnum::toArrayExcept([MyEnum::ONE]); // [2 => 'TWO', 3 => 'THREE]
enum MyEnum: int {
use PoweredEnum;
case ONE = 1;
}
MyEnum::getRandomName(); // ['ONE']
enum MyEnum: int {
use PoweredEnum;
case ONE = 1;
}
MyEnum::getRandomValue(); // [1]
enum MyEnum: int {
use PoweredEnum;
case ONE = 1;
}
MyEnum::getRandomCase(); // MyEnum::ONE