HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/honger7.komma.pro/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;
    const Customer = 4;

    /**
     * @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();
    }
}