Validate input against rules contains placeholder.

@param $key
@param $rule
@param $isValid
@return mixed
493678
private function validateRulesHasPlaceHolder($key, $rule, $isValid)
    {
        $string = string_split($rule, ':');

        if (!string_has($string[1], ',')) {
            return $this->doValidateData($string[0], $string[1], $isValid, $key);
        }

        return $this->doValidateData($string[0], $key, $isValid, $string[1]);
    }
759219
public function validate($key, $value)
    {
        $this->v_key = $key;

        $expected = static::$expected[$key];

        if (!is_array($expected)) {
            $expected = array($expected);
        }

        // if it has optional rule and theres no value
        if (in_array('optional', $expected) && ($value == '' || is_null($value))) {
            return $value;
        }

        foreach ($expected as $rule) {
            if (method_exists($this, "$rule")) {
                $value = call_user_func_array(array($this, "$rule"), array($value));

            } else {
                // Missing rule method exception
                throw new Exceptions\IncorrectValidationMethodException($rule);
            }
        }

        return $value;
    }
1178546
public static function validator(array $rules = [], ContainerInterface $container = null): self
    {
        $validator = new static($rules, $container);

        return $validator;
    }
462958
private function validateInput($input, $rules, $key)
    {
        if (isset($input[$key]) && isset($rules[$key])) {
            $ruleExp = explode('|', $rules[$key]);

            foreach ($ruleExp as $rule) {
                $this->parseRule($rule, $input, $key);
            }
        }
    }
280170
protected function validateByBaseValidator(Validation $validation, array $input, array $baseRules, AppliesToResource $resource=null, $locale=null)
    {
        $laravelRules = $this->toLaravelRules($baseRules);

        $illuminateValidator = $this->buildValidator($input, $laravelRules);

        if (!$illuminateValidator->fails()) {
            return;
        }

        foreach ($illuminateValidator->failed() as $key=>$fails) {
            foreach ($fails as $ruleName=>$parameters) {
                $validation->addFailure($key, Type::snake_case($ruleName), $parameters);
            }
        }
    }
129545
private static function applyValidatorRules($validator, array &$rules)
    {
        $validatorRule = ValidatorRule::getInstance();
        foreach ($rules as $rule) {
            list($functionName, $arguments) = $validatorRule->parseRule($validator, $rule);
            $validator = \call_user_func_array([$validator, $functionName], $arguments);
        }

        return $validator;
    }
1103918
protected function addRule($key, $rules)
    {
        if ($this->shouldSanitize($key)) {
            throw new InvalidArgumentException(sprintf(
                'Sanitation rules are already defined for field [%s]', $key
            ));
        }

        $this->rules[$key] = $this->buildRules($rules);
    }
34710
public function addRule(ValidatorRule $rule, $field, $flags = 0x00000) {
    $key = $this->getKey($field);
    $this->rules[$key][] = $rule;
    
    if ($rule instanceof FieldValidatorRule) {
      $rule->setField($field);
    }
    
    if ($flags & self::OPTIONAL) {
      $this->setOptional($field);
    }
  }
525923
public function validate($key, $label = '')
    {
        // set up field name for error message
        $this->fields[$key] = (empty($label)) ? 'Field with the name of "' . $key . '"' : $label;

        // apply filters to the data
        $this->_applyFilters($key);

        $val = $this->_getVal($key);

        // validate the piece of data
        $this->_validate($key, $val);

        // reset rules
        $this->rules = array();
        $this->filters = array();
        return $val;
    }
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;
    }
834930
public function setRulesFor($key, $rules)
    {
        if (is_array($rules) || is_string($rules))
            $this->_rules[$key] = $rules;

        return $this;
    }
1134411
protected function registerError($rule, $key, $message = null)
    {
        if (empty($message)) {
            $message = $this->messages[$rule];
        }

        $this->errors[$key] = sprintf($message, $this->fields[$key]);
    }
937451
private function validateByRule( $field, $value, $rule, $message = null )
    {
        $ruleClassName = $this->ruleToClassName($this->getRuleName($rule));

        if (!class_exists($ruleClassName)) {
            return false;
        }

        $ruleObject = new $ruleClassName();
        if ($this->isLengthRule($rule)) {
            $ruleObject->setLength($this->extractLength($rule));;
        } else {
            if ($this->isSameRule($rule)) {
                $ruleObject->prepareRule($this->fields, $this->extractSame($rule));
            }
        }
        $result = $ruleObject->run($this->keyToLabel($field), $value, $message);

        if (!$result) {
            static::$errors[ $field ] = $ruleObject->message();
        }

        return $result;
    }
413191
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if(!$exists) {
            return true;
        }
        
        if(!\is_callable($value)) {
            return 'formvalidator_make_callable';
        }
        
        if(empty($options)) {
            throw new \LogicException('Invalid options value given for callback rule');
        }
        
        /** @var \ReflectionMethod|\ReflectionFunction  $prototype */
        
        if(\is_array($value)) {
            $prototype = new \ReflectionMethod($value[0], $value[1]);
        } else {
            $prototype = new \ReflectionFunction($value);
        }
        
        $options = \explode('=', $options, 2);
        
        if(!empty($options[0])) {
            $params = \explode(',', $options[0]);
            
            /** @var \ReflectionParameter  $param */
            foreach($prototype->getParameters() as $pos => $param) {
                $type = $param->getType();
                
                if(!isset($params[$pos])) {
                    return array('formvalidator_make_callback_param_superfluos', array('{0}' => $pos));
                } elseif($params[$pos] === '') {
                    continue; // "mixed" type - wildcard
                } elseif(($type === null && $params[$pos] !== '') || \trim($params[$pos], '?') !== $type->getName()) {
                    return array('formvalidator_make_callback_param', array('{0}' => $pos, '{1}' => \trim($params[$pos], '?')));
                } elseif($params[$pos][0] === '?' && !$type->allowsNull()) {
                    return array('formvalidator_make_callback_param_nullable', array('{0}' => $pos));
                } elseif(\substr($params[$pos], -1) === '?' && !$param->isOptional()) {
                    return array('formvalidator_make_callback_param_optional', array('{0}' => $pos));
                }
            }
        }
        
        if(!empty($options[1])) {
            $return = $prototype->getReturnType();
            
            if($return === null) {
                return array('formvalidator_make_callback_return', array('{0}' => $options[1]));
            } elseif(($return->allowsNull() ? '?' : '').$return->getName() !== $options[1]) {
                return array('formvalidator_make_callback_return_type', array('{0}' => $options[1], '{1}' => $return->getName()));
            }
        }
        
        return true;
    }
876945
protected function extractCustomValidationRules(array $rules)
    {
        $customRules = array_filter($rules, function ($rule) {
            return $this->isCustomRule($rule);
        });

        return $customRules;
    }
61645
protected function makeValidationRuleDataFromSpecialArraySyntax(array $rules, $key)
    {
        $data = new ValidationRuleData(
            array_get($rules, 'rules', []),
            array_get($rules, 'key', is_numeric($key) ? null : $key)
        );

        if (array_has($rules, 'translated')) {
            $data->setIsTranslated((bool) $rules['translated']);
        }

        if (array_has($rules, 'locale_index')) {

            // @codeCoverageIgnoreStart
            if ((int) $rules['locale_index'] < 1) {
                throw new UnexpectedValueException(
                    "Locale index for configured validation data cannot be less than 1 (key/index: {$key})"
                );
            }
            // @codeCoverageIgnoreEnd

            $data->setLocaleIndex((int) $rules['locale_index']);
        }

        return $data;
    }
271970
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if((!$exists || \is_null($value) || (\is_string($value) === true && \trim($value) === '')) && (!isset($_FILES[$key]) || $_FILES[$key]['error'] != 0)) {
            return 'formvalidator_make_required';
        }
        
        return true;
    }