public static function check($action = '*', $subject = '*', $subject_id = 0) { if (!BACKEND_WITH_DATABASE) { return true; } static $cache = array(); if (is_object($subject)) { $subject = get_class($subject); } $key = serialize(array($action, $subject, $subject_id)); if (array_key_exists($key, $cache)) { //return $cache[$key]; } $roles = GateKeeper::permittedRoles($action, class_for_url($subject), $subject_id); $user = BackendUser::check(); $user = !$user && !empty($_SESSION['BackendUser']) ? $_SESSION['BackendUser'] : $user; if (!$user && !in_array('anonymous', $roles)) { if (Controller::$debug) { Backend::addNotice('Anonymous User'); } $cache[$key] = true; return true; } if ($subject != '*' && !Component::isActive(class_name($subject))) { if (Controller::$debug) { Backend::addNotice('Invalid Component: ' . class_name($subject)); } $cache[$key] = false; return false; } if (empty($user->roles)) { if (Controller::$debug) { Backend::addNotice('No User Roles'); } $cache[$key] = false; return false; } $intersect = is_array($roles) ? array_intersect($user->roles, $roles) : $user->roles; if (Controller::$debug >= 2) { Backend::addNotice('Valid roles found: ' . json_encode($intersect)); } $result = count($intersect) ? true : false; $cache[$key] = $result; return $result; }