Check if rule exists / valid
@param string $rule
@return boolean
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);
	}
220644
protected function validate( $attribute, $rule )
	{
		list( $rule, $parameters ) = $this->parseRule( $rule );

		if ( $rule == '' )
		{
			return;
		}

		// First we will get the correct keys for the given attribute in case the field is nested in
		// an array. Then we determine if the given rule accepts other field names as parameters.
		// If so, we will replace any asterisks found in the parameters with the correct keys.
		if ( ( $keys = $this->getExplicitKeys( $attribute ) ) && $this->dependsOnOtherFields( $rule ) )
		{
			$parameters = $this->replaceAsterisksInParameters( $parameters, $keys );
		}

		// We will get the value for the given attribute from the array of data and then
		// verify that the attribute is indeed validatable. Unless the rule implies
		// that the attribute is required, rules are not run for missing values.
		$value = $this->getValue( $attribute );

		$validatable = $this->isValidatable( $rule, $attribute, $value );

		$method = "validate{$rule}";

		if ( $validatable && !$this->$method( $attribute, $value, $parameters, $this ) )
		{
			$this->addFailure( $attribute, $rule, $parameters );
		}
	}
1074601
public function is($value, $rules)
    {
        $valTO = $this->apply($value, $rules);
        if ($valTO->fails()) {
            return false;
        }

        return $valTO->getValue();
    }
411919
public function rule($rule)
    {
        $this->rule = is_string($this->rule) ? explode('|', $this->rule) : $this->rule;
        $rule = is_string($rule) ? explode('|', $rule) : $rule;
        $this->rule = array_unique(array_merge($this->rule, $rule));
        if (in_array('required', $this->rule) && ! isset($this->no_star)) {
            $this->required = true;
        }

        return $this;
    }
1120122
protected function validateAttribute($attribute, $rule)
    {
        $this->currentRule = $rule;

        [$rule, $parameters] = ValidationRuleParser::parse($rule);

        if ($rule == '') {
            return;
        }

        // First we will get the correct keys for the given attribute in case the field is nested in
        // an array. Then we determine if the given rule accepts other field names as parameters.
        // If so, we will replace any asterisks found in the parameters with the correct keys.
        if (($keys = $this->getExplicitKeys($attribute)) &&
            $this->dependsOnOtherFields($rule)) {
            $parameters = $this->replaceAsterisksInParameters($parameters, $keys);
        }

        $value = $this->getValue($attribute);

        // If the attribute is a file, we will verify that the file upload was actually successful
        // and if it wasn't we will add a failure for the attribute. Files may not successfully
        // upload if they are too large based on PHP's settings so we will bail in this case.
        if ($value instanceof UploadedFile && ! $value->isValid() &&
            $this->hasRule($attribute, array_merge($this->fileRules, $this->implicitRules))
        ) {
            return $this->addFailure($attribute, 'uploaded', []);
        }

        // If we have made it this far we will make sure the attribute is validatable and if it is
        // we will call the validation method with the attribute. If a method returns false the
        // attribute is invalid and we will add a failure message for this failing attribute.
        $validatable = $this->isValidatable($rule, $attribute, $value);

        if ($rule instanceof RuleContract) {
            return $validatable
                    ? $this->validateUsingCustomRule($attribute, $value, $rule)
                    : null;
        }

        $method = "validate{$rule}";

        if ($validatable && ! $this->$method($attribute, $value, $parameters, $this)) {
            $this->addFailure($attribute, $rule, $parameters);
        }
    }
914308
function check($rule = null, &$error = null)
    {
        $this->get($rule, $error);
        return !isset($error);
    }
768047
public function validateRule(Rule $rule, array $restrictions = array())
    {
        /** @var \Claroline\CoreBundle\Rule\Constraints\AbstractConstraint[] $usedConstraints */
        $usedConstraints = array();
        $existedConstraints = $this->getConstraints();

        foreach ($existedConstraints as $existedConstraint) {
            if ($existedConstraint->isApplicableTo($rule)) {
                $usedConstraints[] = $existedConstraint->setRule($rule);
            }
        }

        $validatedConstraints = 0;
        $nbConstraints = count($usedConstraints);

        $associatedLogs = $this->getAssociatedLogs($usedConstraints, $restrictions);

        foreach ($usedConstraints as $usedConstraint) {
            $usedConstraint->setAssociatedLogs($associatedLogs);

            if ($usedConstraint->validate()) {
                ++$validatedConstraints;
            }
        }

        return ($validatedConstraints === $nbConstraints) ? $associatedLogs : false;
    }
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;
    }
1342937
private function parseRule($rule) {
		$parsed = [false];
		if (preg_match('#^([a-z][a-z\d_]+)\s*\((.+)\)\s*$#i', $rule, $ms)) {
			$method = trim($ms[1]);
			$ops    = trim($ms[2]);
		} else {
			$method = trim($rule);
			$ops    = '';
		}
		$parsed[0] = $method;
		$parsed[1] = $ops;

		return $parsed;
	}
838274
public function error($rule=null) {
		if($rule === null)
			return $this->self;
		elseif(isset($this->rules[$rule]))
			return $this->rules[$rule];
		elseif($attribute = $this->attribute($rule))
			return $attribute->error();
	}
699514
private function parseRule($rule)
	{
		if (!is_array($rule) || (count($rule) < 2)) {
			throw new ValidatorException('Invalid declaration of validation rule');
		}

		is_array($rule[0]) || $rule[0] = [$rule[0]];

		if (!is_string($rule[1])) {
			throw new ValidatorException('Validator name: Expected string');
		}

		if (isset($rule[2])) {
			if(!is_array($rule[2])) {
				throw new ValidatorException('Validator options: Expected array');
			}
		} else {
			$rule[2] = [];
		}
		$rule[2] = new ArrayWrapper($rule[2]);

		return $rule;
	}
209672
static protected function parseRule($rule)
    {
        switch (gettype($rule)) {
            case 'string':
                $type = $rule;
                $target = null;
                $types = [];
                break;
            case 'array':
                $type = isset($rule['type']) ? $rule['type'] : [];
                $target = isset($rule['target']) ? $rule['target'] : [];
                $types = isset($rule['types']) ? $rule['types'] : [];
                break;
            case 'object':
                $type = isset($rule->type) ? $rule->type : null;
                $target = isset($rule->target) ? $rule->target : null;
                $types = isset($rule->types) ? $rule->types : [];
                break;
            default:
                $type = null;
                $target = null;
                $types = [];
        }
        return compact('type', 'target', 'types');
    }
847898
private function hasFixCallback(string $rule, string $tag)
    {
        return method_exists($this, $method = sprintf('fix%s%s', ucfirst($rule), ucfirst($tag)))
            ? $method
            : false;
    }
745738
protected function checkRegex($value, $rule) {

        if (0 !== strpos($rule, '/') && !preg_match('/\/[imsU]{0,4}$/', $rule)) {
            // 不是正则表达式则两端补上/
            $rule = '/^' . $rule . '$/';
        }
        return is_scalar($value) && 1 === preg_match($rule, (string)$value);
    }
235815
public function configureRule(Rule $rule)
    {
        if ($config = $this->getRuleConfig($rule)) {
            
            if (isset($config['type'])) {
                $rule->setType($config['type']);
            }
            
            if (isset($config['format'])) {
                $rule->setFormat($config['format']);
            }
            
            if (isset($config['attribute'])) {
                $rule->setAttribute($config['attribute']);
            }
            
        }
        
        return $rule;
    }
1232215
protected function validate($attribute, $rule)
    {
        list($rule, $parameters) = $this->parseRule($rule);

        $value = $this->getValue($attribute);
        $method = 'validate' . self::studly($rule);

        if ($rule != 'required' && $value === null) {
            return true;
        }
        if (!$this->$method($attribute, $value, $parameters)) {
            if (in_array($rule, ['max', 'min', 'size', 'between'])) {
                $message = $this->ruleMessages[$rule][$this->getType($value)];
            } else {
                $message = $this->ruleMessages[$rule];
            }

            if (isset($this->customMessages[$attribute])) {
                $customMessage = $this->customMessages[$attribute];
                if (is_array($customMessage) && isset($customMessage[$rule])) {
                    $message = $customMessage[$rule];
                } else if (is_string($customMessage)){
                    $message = $customMessage;
                }
            }

            if ($rule == 'size') {
                $message = str_replace(':size', $parameters[0], $message);
            } else if ($rule == 'max') {
                $message = str_replace(':max', $parameters[0], $message);
            } else if ($rule == 'min') {
                $message = str_replace(':min', $parameters[0], $message);
            } else if ($rule == 'between') {
                $message = strtr($message, [':min' => $parameters[0], ':max' => $parameters[1]]);
            } else if ($rule == 'in') {
                $message = str_replace(':values', implode(',', $parameters), $message);
            } else if ($rule == 'contain') {
                $message = str_replace(':phrase', $parameters[0], $message);
            } else if ($rule == 'date_format') {
                $message = str_replace(':date_format', $parameters[0], $message);
            }

            if (isset($this->attributes[$attribute])) {
                $attribute = $this->attributes[$attribute];
            }
            $message = str_replace(':attribute', $attribute, $message);
            $this->message = $message;

            return false;
        }

        return true;
    }
133043
public static function getRule($ruleName) {

		if (isset(self::$rules[$ruleName])) {
			return self::$rules[$ruleName];
		}

		return false;

	}