library enum
Enum implementing the flyweight pattern.
pamil/enum
Enum implementing the flyweight pattern.
- Tuesday, December 19, 2017
- by pamil
- Repository
- 1 Watchers
- 2 Stars
- 3 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 2 Versions
- 0 % Grown
Enum
This library extends myclabs/php-enum with ability to
compare enums by their identity (if static methods are used to create them)., (*1)
Usage
-
Require this package:, (*2)
$ composer require pamil/enum
-
Create your enum:, (*3)
<?php
use Pamil\Enum\Enum;
/**
* @method static static active()
* @method static static inactive()
*/
final class SampleEnum extends Enum
{
protected const active = 1;
protected const inactive = 2;
}
-
Compare your enums by identity:, (*4)
var_dump(SampleEnum::active() === SampleEnum::active()); // true
Caveats
-
It does not work when creating enums by the constructor:, (*5)
var_dump(new SampleEnum(1) === SampleEnum::active()); // false
-
It does not work when you deserialise serialised enums:, (*6)
var_dump(unserialize(serialize(SampleEnum::active())) === SampleEnum::active());
dev-master
9999999-dev
Enum implementing the flyweight pattern.
Sources
Download
MIT
The Requires
The Development Requires
v1.0.0
1.0.0.0
Enum implementing the flyweight pattern.
Sources
Download
MIT
The Requires
The Development Requires