required-with:another-field

@param \MadeSimple\Validator\Validator $validator
@param array $data
@param string $pattern
@param string $rule
@param array  $parameters
969121
public static function requiredWith(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        $field   = $parameters[0];
        $isWild  = strpos($field, $validator::WILD) !== false;
        $overlap = Str::overlapLeft($field, $pattern);

        // Check that the pattern and field can be compared
        if ($isWild && $overlap === false) {
            throw new \InvalidArgumentException('Cannot match pattern ('.$pattern.') to field ('.$field.')');
        }

        // If the required with field exists and the pattern field does not
        if (ArrDots::has($data, $field, $validator::WILD) && !ArrDots::has($data, $pattern, $validator::WILD)) {
            $validator->addError($pattern, $rule, [':field' => $field]);
        }

        // Check value is not null
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            $fieldAttribute = $isWild ? Str::overlapLeftMerge($overlap, $attribute, $field) : $field;
            $fieldValue     = ArrDots::get($data, $fieldAttribute);

            if ($fieldValue === null) {
                continue;
            }
            if ($fieldValue !== null && $value !== null) {
                continue;
            }

            $validator->addError($attribute, $rule, [':field' => $fieldAttribute]);
        }
    }
430754
public static function validate(array $data, array $rules = [], array $messages = []): array
    {
        $errors = [];

        foreach ($rules as $name => $field_rules) {
            if (isset($data[$name])) {
                $field_value = $data[$name];

                $found_err = self::validateFiled($data, $field_value, self::normalizeRules($field_rules), $messages[$name] ?? []);

                if(\is_array($found_err)){
                    $errors[$name] = $found_err;
                }
            }
        }

        return $errors;
    }
804319
protected function validateParams(array &$params, $rules = null, $clean = false)
	{

		if( ! is_null($rules) )
		{
			// init laravel validator
			$validator = $this->newValidator($params, $rules, $clean);
			$this->setValidator($validator);
		}
		$validator = $this->getValidator();

		$rules = $validator->getRules();
		

		if ($validator->fails())
		{
			// params did not pass validation rules
			
			// add errors to exception
			$this->getException()->addErrors($validator->errors()->toArray());

			return false;
		}
		else
		{
			// params passed validation rules
			return true;
		}
	}
373569
public function validateValidatorList($attribute, $value, $parameters)
    {
        $validators = Input::get('validators');
        if (!is_null($validators)) {
            foreach ($validators as $index => $id) {
                if (isset($value[$id]) && $value[$id] == '') {
                    $this->setCustomMessages(["validator_custom[{$id}]" => trans('antares/customfields::validator.create.validators-empty-fields')]);
                    $this->addFailure("validator_custom[{$id}]", "validator_custom[{$id}]", []);
                    break;
                }
            }
        }

        return true;
    }
1284347
private function createEachRule($rule, $validator = null)
    {
        unset($rule['attributes']);
        if (isset($rule['validator'])) {
            array_unshift($rule, "'{$rule['validator']}'");
            unset($rule['validator']);
        } elseif ($validator !== null) {
            array_unshift($rule, "'$validator'");
        }
        $result = [
            'validator' => 'each',
            'rule' => $rule,
            'attributes' => [],
        ];
        foreach (['on', 'except'] as $param) {
            if (isset($rule[$param])) {
                $result[$param] = $result['rule'][$param];
                unset($result['rule'][$param]);
            }
        }
        return $result;
    }
1347947
protected function replaceRequiredWith($message, $attribute, $rule, $parameters)
    {
        return str_replace(':values', implode(' / ', $this->getAttributeList($parameters)), $message);
    }
934210
public function validate( $data, array $rules = [] )
	{
		$this->normalizeData( $data );
		$this->setRules( $rules );

		foreach( $this->rules as $attribute => $rules ) {
			foreach( $rules as $rule ) {
				$this->validateAttribute( $rule, $attribute );

				if( $this->shouldStopValidating( $attribute ))break;
			}
		}

		return $this->errors;
	}
1080476
public static function greaterThan(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        $lowerBound = Validator::getValue($data, $parameters[0]);
        if (null === $lowerBound) {
            return;
        }
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            if (null === $value || empty($value)) {
                continue;
            }
            if ($value > $lowerBound) {
                continue;
            }
            $validator->addError($attribute, $rule, [':value' => $value]);
        }
    }
224662
protected function buildUpRules(AbstractData $data, Validator $validator)
    {
        $fields = $this->definition->getEditableFieldNames();
        $rules  = [];
        foreach ($fields as $field) {
            $fieldRules = $this->fieldTypeToRules($field, $data, $validator);
            $fieldRules = array_merge($fieldRules, $this->fieldConstraintsToRules($field, $data));
            if (!empty($fieldRules)) {
                $rules[$field] = $fieldRules;
            }
        }
        return $rules;
    }
140698
public static function requiredWithAll(Validator $validator, $data, $pattern, $rule, $parameters)
    {
        // Find the overlaps and if the fields are wild
        $overlaps = [];
        $longest  = 0;
        foreach ($parameters as $k => $field) {
            $isWild       = strpos($field, $validator::WILD) !== false;
            $overlaps[$k] = $isWild ? Str::overlapLeft($field, $pattern) : null;
            if ($isWild && $overlaps[$k] === false) {
                throw new \InvalidArgumentException('Cannot match pattern ('.$pattern.') to field ('.$field.')');
            }
            // Store the longest overlap
            $longest = $isWild && strlen($overlaps[$k]) > strlen($overlaps[$longest]) ? $k : $longest;
        }

        // If the pattern field does not exist
        if (!ArrDots::has($data, $pattern, $validator::WILD)) {
            // Check that all "required with" fields are present and not null
            $required = false;
            foreach (Validator::getValues($data, $parameters[$longest]) as $attribute => $value) {
                $required = true;
                foreach ($parameters as $k => $field) {
                    $fieldAttribute = $overlaps[$k] ? Str::overlapLeftMerge($overlaps[$k], $attribute, $field) : $field;
                    $fieldValue     = ArrDots::get($data, $fieldAttribute);
                    $required       = $required && $fieldValue !== null;
                    if (!$required) {
                        break;
                    }
                }
                if ($required) {
                    break;
                }
            }

            if ($required) {
                $validator->addError($pattern, $rule);
            }
            return;
        }



        // Check value is required and not null
        foreach (Validator::getValues($data, $pattern) as $attribute => $value) {
            // Check that all "required with" fields are present and not null
            $required = true;
            foreach ($parameters as $k => $field) {
                $fieldAttribute = $overlaps[$k] ? Str::overlapLeftMerge($overlaps[$k], $attribute, $field) : $field;
                $fieldValue     = ArrDots::get($data, $fieldAttribute);
                $required       = $required && $fieldValue !== null;
                if (!$required) {
                    break;
                }
            }

            // If required and value is null
            if ($required && $value === null) {
                $validator->addError($pattern, $rule);
            }
        }
    }
1280318
public function addRuleToAll(ValidatorRule $rule, $position = self::APPEND) {
    if ($position == self::APPEND) {
      foreach ($this->rules as $key => $NULL) {
        array_push($this->rules[$key],$rule);
      }
    }
    
    if ($position == self::PREPEND) {
      foreach ($this->rules as $key => $NULL) {
        array_unshift($this->rules[$key], $rule);
      }
    }
    
    if (is_numeric($position)) {
      foreach ($this->rules as $key => $NULL) {
        A::insert($this->rules[$key], $rule, (int) $position);
      }
    }
    
    throw new \Psc\Exception('unbekanter Parameter für position: '.Code::getInfo($position));
  }
840382
protected function runRegex($regex, $key, $datas, $rule)
    {
        if (!preg_match($regex, $datas[$key])) {
            $this->fails[] = $messageKey = "regex.$key";

            $this->addMessage($key, $rule, $messageKey);
        }
    }
956123
protected function requireIf($value, $rule, $data)
    {
        list($field, $val)=explode(',', $rule);
        if ($this->getDataValue($data, $field) == $val) {
            return !empty($value);
        } else {
            return true;
        }
    }
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;
    }
1091187
public function validate(array $data, $rules = null, $custom = false)
    {
        if (!$custom) {
            $rules = $this->rules($rules);
        }

        return $this->validator->make($data, $rules);
    }
97328
public function requireCallback($value, $rule, $data) {
        $result = call_user_func_array([$this, $rule], [$value, $data]);

        if ($result) {
            return !empty($value) || '0' == $value;
        }

        return true;
    }
476810
public function validate(array $data, array $rules, array $messages = [], array $customAttributes = [])
    {
        return $this->make($data, $rules, $messages, $customAttributes)->validate();
    }