From 7d44158c3205b1532ff70ed8b4b362857c65ad8d Mon Sep 17 00:00:00 2001 From: Marco Date: Sat, 10 Mar 2018 01:58:54 +0100 Subject: [PATCH] Implement methods 'getMap', 'getNames' and 'getValues' in class 'Role' --- src/Role.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/Role.php b/src/Role.php index cc8a813..7f0eae3 100644 --- a/src/Role.php +++ b/src/Role.php @@ -41,6 +41,39 @@ final class Role { // const XXX = 268435456; // const XXX = 536870912; + /** + * Returns an array mapping the numerical role values to their descriptive names + * + * @return array + */ + public static function getMap() { + $reflectionClass = new \ReflectionClass(static::class); + + return \array_flip($reflectionClass->getConstants()); + } + + /** + * Returns the descriptive role names + * + * @return string[] + */ + public static function getNames() { + $reflectionClass = new \ReflectionClass(static::class); + + return \array_keys($reflectionClass->getConstants()); + } + + /** + * Returns the numerical role values + * + * @return int[] + */ + public static function getValues() { + $reflectionClass = new \ReflectionClass(static::class); + + return \array_values($reflectionClass->getConstants()); + } + private function __construct() {} }