Skip to content

Commit 6117efe

Browse files
authored
Minor README text changes
1 parent d4cde55 commit 6117efe

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# PHP Enumeration classes
22
Implementation of [Enumeration Classes](https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/enumeration-classes-over-enum-types) in PHP.
33

4-
In contrast to [existing solutions](#existing-solutions) this implementation avoid usage of [Magic methods](https://www.php.net/manual/en/language.oop5.magic.php) and
4+
In contrast to [existing solutions](#existing-solutions), this implementation avoids usage of [Magic methods](https://www.php.net/manual/en/language.oop5.magic.php) and
55
[Reflection](https://www.php.net/manual/en/book.reflection.php) to provide better performance and code autocompletion.
6-
Also, we use static properties that can utilize the power of [Typed Properties](https://wiki.php.net/rfc/typed_properties_v2).
6+
Enumeration class holds reference to single Enum element represented as a object (singleton) to provide possiblity
7+
to use strict (`===`) comparision between the values.
8+
Also, it uses static properties that can utilize the power of [Typed Properties](https://wiki.php.net/rfc/typed_properties_v2).
79
The Enumeration Classes is much closer to other language implementations like [Java Enums](https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html)
810
and [Python Enums](https://docs.python.org/3/library/enum.html).
911

1012

1113
## Declaration
1214

13-
Basic way to declare named Enumeration class:
15+
A basic way to declare named Enumeration class:
1416
```php
1517
<?php
1618
use Dbalabka\Enumeration;
@@ -24,7 +26,7 @@ final class Action extends Enumeration
2426
Action::initialize();
2527
```
2628

27-
with Typed Properties support:
29+
Declaration with Typed Properties support:
2830
```php
2931
<?php
3032
final class Day extends Enumeration
@@ -114,15 +116,16 @@ By default enumeration class does not require the value to be provided. You can
114116
```
115117

116118
Declaration rules that developer should follow:
117-
1. You should always declare the Enum resulting enum class as `final`.
119+
1. The resulting Enumeration class should be marked as `final`. Abstract classes should be used to share functional between
120+
multiple Enumeration classes.
118121
> ...Allowing subclassing of enums that define members would lead to a violation of some important invariants of types and instances.
119122
> On the other hand, it makes sense to allow sharing some common behavior between a group of enumerations...
120123
> (from [Python Enum documentation](https://docs.python.org/3/library/enum.html#restricted-enum-subclassing))
121124
2. Constructor should always be declared as non-public (`private` or `protected`) to avoid unwanted class instantiation.
122125
3. Implementation is based on assumption that all class static properties are elements of Enum. If there is a need to declare
123-
any static property that isn't Enum element than you should override that `\Dbalabka\Enumeration::getStaticVars`.
124-
4. You must call `Dbalabka\Enumeration::initialize()` after each Enumeration class declaration or use
125-
[vladimmi/construct-static](https://github.com/vladimmi/construct-static) custom loader
126+
any static property that isn't Enum element than you should override `\Dbalabka\Enumeration::getStaticVars()` method.
127+
4. Method `Dbalabka\Enumeration::initialize()` should be called after each Enumeration class declaration. Please use
128+
[vladimmi/construct-static](https://github.com/vladimmi/construct-static) custom loader to avoid boilerplate code.
126129

127130
## Usage
128131
```php
@@ -156,7 +159,7 @@ Action::$view = null;
156159

157160
### Class static initialization
158161
Implementation rely on class static initialization which was proposed in [Static Class Constructor](https://wiki.php.net/rfc/static_class_constructor).
159-
RFC describes the possible workarounds. Simplest is to call initialization method right after class declaration,
162+
RFC describes the possible workarounds. The simplest way is to call initialization method right after class declaration,
160163
but it requires keep this in mind. Thanks to [Typed Properties](https://wiki.php.net/rfc/typed_properties_v2)
161164
we can control not initialized properties - PHP will throw and error in case of access to not initialized property.
162165
It might be automated with custom autoloader implemented in [vladimmi/construct-static](https://github.com/vladimmi/construct-static) library.

0 commit comments

Comments
 (0)