Initial Commit
This commit is contained in:
43
dependencies/rakit/validation/src/Rules/RequiredWithout.php
vendored
Normal file
43
dependencies/rakit/validation/src/Rules/RequiredWithout.php
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Ultimo\Dependencies\Rakit\Validation\Rules;
|
||||
|
||||
use WP_Ultimo\Dependencies\Rakit\Validation\Rule;
|
||||
class RequiredWithout extends Required
|
||||
{
|
||||
/** @var bool */
|
||||
protected $implicit = \true;
|
||||
/** @var string */
|
||||
protected $message = "The :attribute is required";
|
||||
/**
|
||||
* Given $params and assign $this->params
|
||||
*
|
||||
* @param array $params
|
||||
* @return self
|
||||
*/
|
||||
public function fillParameters(array $params) : Rule
|
||||
{
|
||||
$this->params['fields'] = $params;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Check the $value is valid
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function check($value) : bool
|
||||
{
|
||||
$this->requireParameters(['fields']);
|
||||
$fields = $this->parameter('fields');
|
||||
$validator = $this->validation->getValidator();
|
||||
$requiredValidator = $validator('required');
|
||||
foreach ($fields as $field) {
|
||||
if (!$this->validation->hasValue($field)) {
|
||||
$this->setAttributeAsRequired();
|
||||
return $requiredValidator->check($value, []);
|
||||
}
|
||||
}
|
||||
return \true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user