Skip to content

Commit 6e08fb1

Browse files
authored
Update README.md
1 parent f713988 commit 6e08fb1

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ use MabeEnum\Enum;
3838
// define an own enumeration class
3939
class UserStatus extends Enum
4040
{
41-
const INACTIVE = 0;
42-
const ACTIVE = 1;
43-
const DELETED = 2;
41+
const INACTIVE = 'i';
42+
const ACTIVE = 'a';
43+
const DELETED = 'd';
4444

4545
// all scalar datatypes are supported
4646
const NIL = null;
@@ -72,17 +72,24 @@ class UserStatus extends Enum
7272
// const CLASS = 'class';
7373
}
7474

75-
// different ways to instantiate an enumerator
76-
$status = UserStatus::get(UserStatus::ACTIVE);
77-
$status = UserStatus::ACTIVE();
78-
$status = UserStatus::byName('ACTIVE');
79-
$status = UserStatus::byOrdinal(1);
75+
// ways to instantiate an enumerator
76+
$status = UserStatus::get(UserStatus::ACTIVE); // by value or instance
77+
$status = UserStatus::ACTIVE(); // by name as callable
78+
$status = UserStatus::byValue('a'); // by value
79+
$status = UserStatus::byName('ACTIVE'); // by name
80+
$status = UserStatus::byOrdinal(1); // by ordinal number
8081

81-
// available methods to get the selected entry
82+
// basic methods of an instantiated enumerator
8283
$status->getValue(); // returns the selected constant value
8384
$status->getName(); // returns the selected constant name
8485
$status->getOrdinal(); // returns the ordinal number of the selected constant
85-
(string) $status; // returns the selected constant name
86+
87+
// basic methods to list defined enumerators
88+
UserStatus::getEnumerators() // returns a list of enumerator instances
89+
UserStatus::getValues() // returns a list of enumerator values
90+
UserStatus::getNames() // returns a list of enumerator names
91+
UserStatus::getOrdinals() // returns a list of ordinal numbers
92+
UserStatus::getConstants() // returns an associative array of enumerator names to enumerator values
8693

8794
// same enumerators (of the same enumeration class) holds the same instance
8895
UserStatus::get(UserStatus::ACTIVE) === UserStatus::ACTIVE()
@@ -113,8 +120,8 @@ class User
113120
public function getStatus()
114121
{
115122
if (!$this->status) {
116-
// initialize the default enumerator
117-
$this->status = UserStatus::get(UserStatus::INACTIVE);
123+
// initialize default
124+
$this->status = UserStatus::INACTIVE();
118125
}
119126
return $this->status;
120127
}

0 commit comments

Comments
 (0)