Commit e4275632 authored by Jan Kuchař's avatar Jan Kuchař

Merge branch 'make-get-all-values-available' into 'master'

Enum::getAvailableValues(): support for getting all values of enum (will be...

See merge request !6
parents e51fef64 8f70f127
Pipeline #14345 passed with stages
in 45 seconds
......@@ -21,11 +21,20 @@ abstract class Enum
}
/**
* Provide values for given enum.
* @return array
* Provide values for given enum, never call this method directly.
* @return static[]
*/
abstract protected static function provideInstances(): array;
/**
* @return static[] Order and array keys are not guaranteed.
* For further value introspection use returned enum instances.
*/
final public static function getAvailableValues(): array
{
return self::getMeta()->getValues();
}
/**
* @return string[]|int[]
*/
......
<?php declare(strict_types=1);
require __DIR__ . '/../bootstrap.php';
/**
* @method static AvailableValuesEnum NEW()
* @method static AvailableValuesEnum ACTIVE()
*/
class AvailableValuesEnum extends \Grifart\Enum\Enum
{
use Grifart\Enum\AutoInstances;
protected const NEW = 'new';
protected const ACTIVE = 'active';
}
\Tester\Assert::same(
AvailableValuesEnum::getAvailableValues(),
[AvailableValuesEnum::NEW(), AvailableValuesEnum::ACTIVE()]
);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment