Triggered via role_unassigned event.

@param \core\event\role_unassigned $event
@return bool true on success
969352
public static function role_unassigned(\core\event\role_unassigned $event) {
        if (!enrol_is_enabled('meta')) {
            // All roles are removed via cron automatically.
            return true;
        }

        // Prevent circular dependencies - we can not sync meta roles recursively.
        if ($event->other['component'] === 'enrol_meta') {
            return true;
        }

        // Only course level roles are interesting.
        if (!$parentcontext = context::instance_by_id($event->contextid, IGNORE_MISSING)) {
            return true;
        }
        if ($parentcontext->contextlevel != CONTEXT_COURSE) {
            return true;
        }

        self::sync_course_instances($parentcontext->instanceid, $event->relateduserid);

        return true;
    }
773311
public static function off($event)
    {
        if (self::hasEvent($event)) {
            unset(self::$events[$event], self::$eventHandlers[$event]);

            return true;
        }

        return false;
    }
123458
public function hasRole($role)
    {
        $roles = array_column($this->roles->toArray(), 'name');
        return array_search($role, $roles) > -1;
    }
963406
public function unregister($event, $callback = null)
	{
		if (isset($this->_events[$event]))
		{
			if ($callback === null)
			{
				unset($this->_events[$event]);
				return true;
			}

			foreach ($this->_events[$event] as $i => $arguments)
			{
				if($callback === $arguments[1])
				{
					unset($this->_events[$event][$i]);
					return true;
				}
			}
		}

		return false;
	}
1251629
private function onEvent($event)
    {
        if (isset($this->_options[$event])) {
            $onEvent = strtoupper($this->_options[$event]);

            if (! in_array($onEvent, ['NO ACTION', 'RESTRICT'])) {
                return $onEvent;
            }
        }

        return false;
    }
935320
public static function process($event)
    {
        // Link Lead with User
        if ($event->account_linking->status === 'linked') {
            $authorization_code = $event->account_linking->authorization_code;
            $user_id = str_replace('user_id:', '', $authorization_code);
            
            return self::linkWithExistingUser($event->sender->id, $user_id);
        } // Unlink, Logout user
        
        return self::unlinkWithExistingUser($event->sender->id);
    }
552678
public function addRole(Role $role): bool
    {
        return (new actions\AddRole($this->user, $role))->execute();
    }
245882
private function isGranted($role, $object = null): bool
    {
        if (null === $this->securityChecker) {
            return false;
        }

        try {
            return $this->securityChecker->isGranted($role, $object);
        } catch (AuthenticationCredentialsNotFoundException $e) {
            return false;
        }
    }
586192
public function determineEventBinding(Event $event)
    {
        switch ($event->getCode()) {
            case Event::RESOURCE_DELETED:
                return 'delete';
                break;
            case Event::RESOURCE_CREATED:
                return 'create';
                break;
            case Event::RESOURCE_MODIFIED:
                return 'modify';
            break;
        }
    }
1287186
public function hasRole(string $role): bool
    {
        return (null !== $this->roles) ? \in_array($role, $this->roles) : false;
    }
642464
public function hasRole($role)
    {
        if (!$this->roles->where('token', $role)->isEmpty()) {
            return true;
        }

        foreach ($this->groups as $group) {
            if (!$group->roles->where('token', $role)->isEmpty()) {
                return true;
            }
        }

        return false;
    }
70465
public function match(Event $event) : bool
    {
        $filter = $this->filter;
        if (!$filter) {
            return true;
        }
        if (is_string($filter)){
            return $this->matchEventName($filter, $event);
        }
        if (is_callable($filter)){
            return ($filter)($event);
        }
        return false;
    }
14607
public function assign($role, UserInterface $user)
    {
        $roles = is_array($role) ? $role : [ $role ];

        $count = 0;

        foreach ($roles as $singleRole) {
            $count += $this->assignSingleRole($singleRole, $user) ? 1 : 0;
        }

        if ($count !== count($roles)) {
            return false;
        }

        $this->fireUserPermissionChangeEvent($user);
        return true;
    }
229756
public function hasRole($role)
    {
        $role = strtoupper($role);

        if ($role == 'ROLE_USER') {
            return true;
        }

        if (in_array($role, $this->roles)) {
            return true;
        }

        return false;
    }
960731
public static function hasRoleId($role)
    {
        return (self::isFeUser()
            && self::isAuthenticated()
            && in_array($role, $GLOBALS['TSFE']->fe_user->groupData['uid'])
        );
    }
131137
public function off(string $event): bool
    {
        if ($this->hasEvent($event)) {
            unset(self::$events[$event], self::$eventHandlers[$event]);

            return true;
        }

        return false;
    }
306609
protected function isActionableEvent($event)
    {
        if ($event->action !== 'labeled') {
            return false;
        }

        $pattern = Config::getInstance()['dms.github.label-manager']['actionable.regexp'];
        if (preg_match($pattern, $event->label->name) == false) {
            return false;
        }

        return true;
    }