pamil / enum
Enum implementing the flyweight pattern.
v1.0.0
2017-12-19 11:40 UTC
Requires
- myclabs/php-enum: ^1.5
Requires (Dev)
- phpstan/phpstan: ^0.9
- phpstan/phpstan-phpunit: ^0.9
- phpstan/phpstan-strict-rules: ^0.9
- phpunit/phpunit: ^6.5
- sylius-labs/coding-standard: ^1.0
This package is auto-updated.
Last update: 2024-10-29 02:12:31 UTC
README
Enum
This library extends myclabs/php-enum with ability to compare enums by their identity (if static methods are used to create them).
Usage
-
Require this package:
$ composer require pamil/enum
-
Create your enum:
<?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:
var_dump(SampleEnum::active() === SampleEnum::active()); // true
Caveats
-
It does not work when creating enums by the constructor:
var_dump(new SampleEnum(1) === SampleEnum::active()); // false
-
It does not work when you deserialise serialised enums:
var_dump(unserialize(serialize(SampleEnum::active())) === SampleEnum::active());