File: D:/HostingSpaces/ASmits/kemi.nl/app/KommaApp/Users/Roles.php
<?php
namespace App\KommaApp\Users;
/**
* Class Role
*
* Represents user roles.
* Will be replaced by the Role model since this is a interim solution
*/
abstract class Roles
{
const SuperAdmin = 1;
const Admin = 2;
const Editor = 3;
/**
* @return int[] All roles as an array of integers
*/
static function getAsArray() {
return self::getAllRoles();
}
/**
* Check if the passed role is really a role that is defined as a constant in this class.
*
* @param int $role
* @param bool $strict If true it will only consider a role as valid if it is an int. If it for example is a numeric string it won't consider it valid
* @return bool Returns true if the role is a valid one, false otherwise
*/
static function isValidRole(int $role, $strict = false) {
return in_array($role, self::getAllRoles(), $strict);
}
/**
* Returns an array containing integers representing the defined roles.
*
* @return int[]
*/
private static function getAllRoles()
{
$thisClassAsReflectionClass = new \ReflectionClass(__CLASS__);
return $thisClassAsReflectionClass->getConstants();
}
}