Check if rule passes
@return boolean
176826
public function isValid() {

		$params = $this -> getParameters();

		if(false === isset($params[0])) {
			return trigger_error(sprintf('Missing argument 1 for %s', __METHOD__), E_USER_ERROR);
		}

		if(false === is_string($params[0])) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($params[0])), E_USER_ERROR);
		}

		foreach($this -> getValues() as $fieldname => $value) {

			if($fieldname == $params[0]) {
				return $value == $this -> getValue();
			}
		}

		return true;
	}
1070016
public function isValid()
    {
        if (!isset($this->rules) || !is_array($this->rules) || empty($this->rules)) {
            return true;
        }

        $rules        = array();
        $replacements = array();

        foreach ($this->attributes as $k => $v) {
            $replacements['{{self_'.$k.'}}'] = $v;
        }

        foreach ($this->rules as $k => $v) {
            $rules[$k] = str_replace(array_keys($replacements), array_values($replacements), $v);
        }

        $v = Validator::make($this->attributes, $rules);

        if ($v->fails()) {
            $this->errorMessages = $v->messages();

            return false;
        }

        return true;
    }
680298
protected function uvRuleCheck() {
		$expire = strtotime(date('Y-m-d', time() + 60 * 60 * 24));
		$item = strtr(static::classname(), '\\', '_') . '_' . $this->id;

		$session = \Yii::$app->session->get($this->statisticsParam);
		if(!\Yii::$app->session->has($this->statisticsParam) || $session['expire'] != $expire) {
			$session = [
				'expire' => $expire,
				'items' => [],
			];
		}

		if(!isset($session['items'][$item])) {
			$session['items'][$item] = true;
			\Yii::$app->session->set($this->statisticsParam, $session);

			return true;
		}

		return false;
	}
1013046
public function isRequired(): bool
    {
        foreach ($this->rules as $rule) {
            if ($rule instanceof RequiredRule) {
                return true;
            }
        }
        return false;
    }
810436
public function can_manage_rule() {
        $courseid = $this->rulecourseid;
        $context = empty($courseid) ? \context_system::instance() : \context_course::instance($courseid);
        return has_capability('tool/monitor:managerules', $context);
    }
323456
private function unfold(): bool
    {
        while (0 < \count($this->todo)) {
            $rule = \array_pop($this->todo);

            if ($rule instanceof Escape) {
                $this->addTrace($rule);
            } else {
                $out = $this->reduce($this->grammar->fetch($rule->getRule()), $rule->getData());

                if ($out === false && $this->backtrack() === false) {
                    return false;
                }
            }
        }

        return true;
    }
346301
protected function checkRules($context = null)
    {
        $rules = $this->getRules();
        $result = false;

        foreach ($rules as $rule) {
            if ($rule->check($context)) {
                $result = true;
                break;
            }
        }

        return $result;
    }
211462
public static function matchDetectionRulesAgainstUA(){
		$userAgent=isset(self::$httpHeaders['HTTP_USER_AGENT'])?self::$httpHeaders['HTTP_USER_AGENT']:'';
		if(empty($userAgent))
			return false;

		//foreach(self::getRules() as $_regex){
		foreach(self::getMobileDetectionRules() as $_regex){
			if(empty($_regex)) continue;
			if(self::match($_regex,$userAgent))
				return true;
			}
		return false;
		}
308830
protected function buildRules()
    {
        if ($this->rules) {
            return $this->rules;
        }

        if ($resource = $this->resource()) {
            $this->rules = $this->filterDetectedRules($this->detectRules($resource), $resource);
        }

        return $this->rules;
    }
602452
public function isTrue(): bool
    {
        return (
            in_array($this->string, ['ok']) ||
            (true === filter_var($this->string, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE))
        );
    }
715137
public function getActionRule () {
		return array_merge(
			static::GetDefaultRule(),
			method_exists($this, Strings::ToLowerCamelCase($this->action.'_rule')) ? $this->{Strings::ToLowerCamelCase($this->action.'_rule')}() ?: [] : []
		);
	}
1125768
protected function check()
  {
    if ( $this->slugAble() ){
      if ( !$this->checkTitleUnique($this->row->get('id'), $this->row->get('title')) ){
        return false;
      }
      
      if ( !$this->checkSlugUnique($this->row->get('id'), $this->row->get('slug')) ){
        return false;
      }
    }
    
    if ( $this->orderingAble() ){
      if ( $this->shouldBeOrdered() ){
        $conditions = $this->getReorderConditions();
        $this->row->set('ordering', $this->getNextOrder($conditions));
      }
    }
    
    if ( $this->statesAble() ){
      $userId   = $this->db->getUid();
      $nullDate = $this->db->getNullDate();
      $nowDate  = Date::getInstance()->format($this->db->getDateFormat());
      
      if ( !$this->row->get($this->tbl_key) ){
        $this->row->set('created', $nowDate);
        $this->row->set('created_by', $userId); 
      }
      else {
        $this->row->set('modified', $nowDate);
        $this->row->set('modified_by', $userId); 
      }
    }
    
    if ( $this->versionAble() ){
      $version = (int)$this->row->get('version');
      $this->row->set('version', ++$version);
    }
    
    foreach($this->getFields() as $fieldName => $fieldInfos){
      $v = $this->row->get($fieldName);
      
      if ( 'YES' === $fieldInfos->Null ){
        switch($fieldInfos->Type){
          case 'bigint':
          case 'mediumint':
          case 'smallint':
          case 'tinyint':
            if ( 0 === $this->row->get($fieldName) ){
              $this->row->set($fieldName, null);
            }
            break;
          
          case 'datetime':
          case 'timestamp':
            if ( $this->db->getNullDate(true) === $this->row->get($fieldName) ){
              $this->row->set($fieldName, null);
            }
            break;
          
          case 'date':
            if ( $this->db->getNullDate(false) === $this->row->get($fieldName) ){
              $this->row->set($fieldName, null);
            }
            break;
          
          case 'time':
            if ( '00:00:00' === $this->row->get($fieldName) ){
              $this->row->set($fieldName, null);
            }
            break;
        }
      }
    }
    
    return true;
  }
272358
public function getErrorNextRule () {
		return isset($this->rule->next['error'][1]) ? $this->rule->next['error'][1] : (($this->getErrorNextUrl() === null) ? static::NEXT_RENDERING : static::NEXT_FORWARD);
	}
565565
private function validateRule($rule)
    {
        if (strpos($rule, '/')) {
            list($rule, $mask) = explode('/', $rule);
        }

        if (filter_var($rule, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
            if (isset($mask) && ($mask < 1 || $mask > 30)) {
                return false;
            }

            return true;
        } elseif (filter_var($rule, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
            if (isset($mask) && ($mask < 1 || $mask > 128)) {
                return false;
            }

            return true;
        }

        return false;
    }
440634
public function removeRule($ruleName)
    {
        if (isset($this->rules[$ruleName])) {
            unset($this->rules[$ruleName]);
            return true;
        }
        return false;
    }
532966
public function filtersPass()
    {
        $invoker = new Invoker();

        foreach ($this->filters as $callback) {
            if (!$invoker->call($callback)) {
                return false;
            }
        }

        foreach ($this->rejects as $callback) {
            if ($invoker->call($callback)) {
                return false;
            }
        }

        return true;
    }
922271
public function getReduceRule(): ?Rule
    {
        foreach ($this->items as $item) {
            if (!$item->hasFurther()) {
                return $item->getAsRule();
            }
        }
        return null;
    }