Skip to content

Commit 8e9c2da

Browse files
committed
Merge pull request #48 from ADmad/patch-2
Enable syntax highlighting for code blocks
2 parents 1afe8f6 + 1eae3cf commit 8e9c2da

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ It's an abstract class that needs to be extended to use it.
2828

2929
## Basics
3030

31+
```php
3132
use MabeEnum\Enum;
3233

3334
// define an own enumeration class
@@ -66,10 +67,11 @@ It's an abstract class that needs to be extended to use it.
6667
UserStatus::ACTIVE()->is(UserStatus::ACTIVE()); // true
6768
UserStatus::ACTIVE()->is(UserStatus::DELETED); // false
6869
UserStatus::ACTIVE()->is(UserStatus::DELETED()); // false
69-
70+
```
7071

7172
## Type-Hint
72-
73+
74+
```php
7375
use MabeEnum\Enum;
7476

7577
class User
@@ -90,23 +92,27 @@ It's an abstract class that needs to be extended to use it.
9092
return $this->status;
9193
}
9294
}
95+
```
9396

9497
### Type-Hint issue
9598

9699
Because in normal OOP the above example allows `UserStatus` and types inherited from it.
97100

98101
Please think about the following example:
99102

103+
```php
100104
class ExtendedUserStatus
101105
{
102106
const EXTENDED = 'extended';
103107
}
104108

105109
$user->setStatus(ExtendedUserStatus::EXTENDED());
110+
```
106111

107112
Now the setter receives a status it doesn't know about but allows it.
108113
If your `User` class doesn't allow it the following is the recommanded way:
109114

115+
```php
110116
class User
111117
{
112118
// ...
@@ -116,6 +122,7 @@ If your `User` class doesn't allow it the following is the recommanded way:
116122
}
117123
// ...
118124
}
125+
```
119126

120127
Now you are 100% sure to work with an exact instace of `UserStatus`.
121128

@@ -128,6 +135,7 @@ An ```EnumMap``` maps enumerators of the same type to data assigned to.
128135

129136
Internally the ```EnumMap``` is based of ```SplObjectStorage```.
130137

138+
```php
131139
use MabeEnum\EnumMap;
132140

133141
// create a new EnumMap
@@ -148,7 +156,7 @@ Internally the ```EnumMap``` is based of ```SplObjectStorage```.
148156
// define key and value used for iteration
149157
$enumSet->setFlags(EnumMap::KEY_AS_NAME | EnumMap::CURRENT_AS_DATA);
150158
var_dump(iterator_to_array($enumSet)); // array('ACTIVE' => 'aktiv');
151-
159+
```
152160

153161
## EnumSet
154162

@@ -160,6 +168,7 @@ The maximun number of enumerators are limited by the size of an integer.
160168

161169
Enumerators will be ordered by the ordinal number.
162170

171+
```php
163172
use MabeEnum\EnumSet;
164173

165174
// create a new EnumSet
@@ -176,7 +185,7 @@ Enumerators will be ordered by the ordinal number.
176185

177186
// iterate
178187
var_dump(iterator_to_array($enumSet)); // array(0 => UserStatus{$value=1});
179-
188+
```
180189

181190
# Why not ```SplEnum```
182191

0 commit comments

Comments
 (0)