maisner / enum
Enum PHP implementation
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/maisner/enum
Requires
- php: >= 7.1
Requires (Dev)
- phpstan/phpstan: ^0.10.5
- phpstan/phpstan-strict-rules: ^0.10.1
- phpunit/phpunit: ^7.4
- slevomat/coding-standard: ^4.8
This package is auto-updated.
Last update: 2025-09-29 02:32:53 UTC
README
Enum PHP implementation
Usage
- implementation Enum class
<?php declare(strict_types = 1); use Maisner\Enum\AbstractEnum; class TypeEnum extends AbstractEnum { public const TEMPERATURE = 'temperature'; public const HUMIDITY = 'humidity'; /** * @return array|string[] */ protected static function allowedValues(): array { return [ self::TEMPERATURE, self::HUMIDITY ]; } /** * @return TypeEnum */ public static function TEMPERATURE(): self { return new self(self::TEMPERATURE); } /** * @return TypeEnum */ public static function HUMIDITY(): self { return new self(self::HUMIDITY); } }
- and usage
$type = TypeEnum::TEMPERATURE(); $type->getValue(); //temperature (string)$type; //temperature