Must return true if rule is valid.

@param mixed $rule
@return bool
171733
private function validateRule($rule): bool
    {
        if ($rule instanceof \Closure || $rule instanceof RuleInterface) {
            return true;
        }

        if (is_array($rule)) {
            return is_callable($rule, true);
        }

        if (is_string($rule) && class_exists($rule)) {
            try {
                $reflection = new \ReflectionClass($rule);
            } catch (\ReflectionException $e) {
                return false;
            }

            return $reflection->isSubclassOf(RuleInterface::class);
        }

        return false;
    }
281636
protected function parseRule( $rule )
	{
		$parameters = [];

		// example: {rule}:{parameters}
		if( strpos( $rule, ':' ) !== false ) {
			list( $rule, $parameter ) = explode( ':', $rule, 2 );

			// example: {parameter1,parameter2,...}
			$parameters = $this->parseParameters( $rule, $parameter );
		}

		$rule = ucwords( str_replace( ['-', '_'], ' ', trim( $rule )));
		$rule = str_replace( ' ', '', $rule );

		return [ $rule, $parameters ];
	}
488942
private static function isRule($rule) {

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

		$class = static :: getRuleClass($rule);

		return true === class_exists($class);
	}
1000552
protected function hasRule($attribute, $rules)
	{
		$rules = (array) $rules;

		// To determine if the attribute has a rule in the ruleset, we will spin
		// through each of the rules assigned to the attribute and parse them
		// all, then check to see if the parsed rules exists in the arrays.
		foreach ($this->rules[$attribute] as $rule)
		{
			list($rule, $parameters) = $this->parseRule($rule);

			if (in_array($rule, $rules)) return true;
		}

		return false;
	}
1013046
public function isRequired(): bool
    {
        foreach ($this->rules as $rule) {
            if ($rule instanceof RequiredRule) {
                return true;
            }
        }
        return false;
    }
76672
public function getRule($rule, $domain = null)
    {
        return isset($this->rule[$domain][$rule]) ? $this->rule[$domain][$rule] : [];
    }
788141
protected function checkRule($rule)
    {
        $this->assertTrue(is_array($rule) || is_string($rule));

        $parts = is_array($rule) ? $rule : explode('|', $rule);

        $this->assertTrue(isset($parts[0]));

        if ($this->enforceRequiredOrNullable()) {
            $this->assertTrue($parts[0] === 'required' || $parts[0] === 'nullable');
        }

        foreach ($parts as $part) {
            $this->assertInternalType('string', $part);
        }
    }
1042620
public function parseGroupRule($rule)
    {
        $origin = $this->router->getGroup();
        $this->router->setGroup($this);

        if ($rule instanceof \Closure) {
            Container::getInstance()->invokeFunction($rule);
        } elseif (is_array($rule)) {
            $this->addRules($rule);
        } elseif (is_string($rule) && $rule) {
            $this->router->bind($rule, $this->domain);
        }

        $this->router->setGroup($origin);
    }
144876
public function validationRules(array $rules = array())
    {
        if (empty($rules)) {
            return $this->validationRules;
        }

        $this->validationRules = $rules;

        return $this;
    }
1344268
private function checkTokenForOnlyRule(RuleInterface $rule, $token): bool
    {
        $fitRuleRequirements = false;
        foreach ($rule->getRequirements() as $req) {
            if (false !== strpos($token, $req)) {
                $fitRuleRequirements = true;
            }
        }

        return $fitRuleRequirements;
    }
955415
public function isRequired(): bool
    {
        foreach ($this->validationRules as $rule) {
            if ($rule instanceof Required) {
                return true;
            }
        }

        return false;
    }
1231513
public function parse($value, $rule) {
        $rs = $value;

        if (!is_bool($value)) {
            if (is_numeric($value)) {
                $rs = $value > 0 ? TRUE : FALSE;
            } else if (is_string($value)) {
                $rs = in_array(strtolower($value), array('ok', 'true', 'success', 'on', 'yes')) 
                    ? TRUE : FALSE;
            } else {
                $rs = $value ? TRUE : FALSE;
            }
        }

        return $rs;
    }
938225
public function regex($rule) {
        $this->check_role = 'regex';
        $this->rule = $rule;
        $result = $this->checkRegex($this->value, $rule);
        $this->checkResult($result);
        return $this;
    }
204433
private function isValidPattern(string $pattern): bool
    {
        set_error_handler(function (int $severity, string $message, string $file, int $line): bool {
            throw new \ErrorException($message, 0, $severity, $file, $line);
        }, \E_ALL);

        try {
            $result = preg_match("/$pattern/", '');
        } catch (\ErrorException $exception) {
            $errorMessage = sprintf("Invalid regular expression '%s': %s", $pattern, $exception->getMessage());
            throw new \InvalidArgumentException($errorMessage, 0, $exception);
        } finally {
            restore_error_handler();
        }

        return $result !== false;
    }
360642
public function get_message($rule)
	{
		if ( ! array_key_exists($rule, $this->error_messages))
		{
			return false;
		}

		return $this->error_messages[$rule];
	}
1178649
public function removeRule($field, $rule)
    {
        if (isset($this->rules[$field][$rule])) {
            unset($this->rules[$field][$rule]);
            return true;
        }
        return false;
    }
16531
private function parseRule($rule)
    {
        $parameters = [];

        if (strpos($rule, ':') !== false) {
            list($rule, $parameter) = explode(':', $rule, 2);
            $parameters = $this->parseParameters($rule, $parameter);
        }

        if (!Variable::ruleExists($rule)) {
            throw new \InvalidArgumentException("validation: rule '$rule' not supported.");
        }

        return [$rule, $parameters];
    }