Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit 8281d77

Browse files
author
Petr Knap
committed
Update README.md
2 parents a77fdfe + c763528 commit 8281d77

File tree

1 file changed

+68
-1
lines changed

1 file changed

+68
-1
lines changed

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,69 @@
11
# php-enum
2-
Enumerated type for PHP
2+
3+
Enumerated type for PHP by [Petr Knap].
4+
5+
6+
## What is enum?
7+
8+
> In computer programming, an **enumerated type** (also called **enumeration** or **enum**, or **factor** in the R programming language, and a categorical variable in statistics) is a data type consisting of a set of named values called **elements**, **members**, **enumeral**, or **enumerators** of the type. The enumerator names are usually identifiers that behave as constants in the language. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value. In other words, an *enumerated type has values that are different from each other*, and that can be compared and assigned, but which are not specified by the programmer as having any particular concrete representation in the computer's memory; compilers and interpreters can represent them arbitrarily.
9+
-- [Enumerated type - Wikipedia, The Free Encyclopedia]
10+
11+
### Usage of php-enum
12+
13+
#### Enum declaration
14+
```php
15+
/**
16+
* @method static DayOfWeekEnum SUNDAY()
17+
* @method static DayOfWeekEnum MONDAY()
18+
* @method static DayOfWeekEnum TUESDAY()
19+
* @method static DayOfWeekEnum WEDNESDAY()
20+
* @method static DayOfWeekEnum THURSDAY()
21+
* @method static DayOfWeekEnum FRIDAY()
22+
* @method static DayOfWeekEnum SATURDAY()
23+
*/
24+
class DayOfWeekEnum extends \PetrKnap\Php\Enum\AbstractEnum
25+
{
26+
protected function __construct($constantName)
27+
{
28+
self::setConstants([
29+
"SUNDAY" => 0,
30+
"MONDAY" => 1,
31+
"TUESDAY" => 2,
32+
"WEDNESDAY" => 3,
33+
"THURSDAY" => 4,
34+
"FRIDAY" => 5,
35+
"SATURDAY" => 6
36+
]);
37+
parent::__construct($constantName);
38+
}
39+
}
40+
```
41+
42+
#### Enum usage
43+
```php
44+
if (date('w') == DayOfWeekEnum::FRIDAY()->getValue()) {
45+
echo "Finally it is Friday!";
46+
}
47+
```
48+
49+
50+
## How to install
51+
52+
Run `composer require petrknap/php-enum` or merge this JSON code with your project `composer.json` file manually and run `composer install`. Instead of `dev-master` you can use [one of released versions].
53+
54+
```json
55+
{
56+
"require": {
57+
"petrknap/php-enum": "dev-master"
58+
}
59+
}
60+
```
61+
62+
Or manually clone this repository via `git clone https://github.com/petrknap/php-enum.git` or download [this repository as ZIP] and extract files into your project.
63+
64+
65+
66+
[Petr Knap]:http://petrknap.cz/
67+
[Enumerated type - Wikipedia, The Free Encyclopedia]:https://en.wikipedia.org/w/index.php?title=Enumerated_type&oldid=701057934
68+
[one of released versions]:https://github.com/petrknap/php-enum/releases
69+
[this repository as ZIP]:https://github.com/petrknap/php-enum/archive/master.zip

0 commit comments

Comments
 (0)