Skip to content

Commit d7a43c8

Browse files
committed
feat: add matchesValueOf + fix rule params
1 parent 9138d7d commit d7a43c8

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/Form.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ public function __construct()
130130
$this->rules['in'] = function ($value, $param) {
131131
return in_array($value, $param);
132132
};
133+
134+
$this->rules['matchesvalueof'] = function ($value, $param) {
135+
$this->message('matchesvalueof', "{field} must match the value of $param");
136+
return \Leaf\Http\Request::get($param) === $value;
137+
};
133138
}
134139

135140
protected function test($rule, $valueToTest, $fieldName = 'item'): bool
@@ -192,6 +197,10 @@ protected function test($rule, $valueToTest, $fieldName = 'item'): bool
192197
$param = ['Item'];
193198
}
194199

200+
if (!is_array($param)) {
201+
$param = [$param];
202+
}
203+
195204
$this->addError($fieldName, sprintf(
196205
str_replace(
197206
['{field}', '{Field}', '{value}'],
@@ -313,10 +322,10 @@ public function addErrorMessage($field, ?string $message = null)
313322
}
314323

315324
/**
316-
* Add validation error message
317-
* @param string|array $field The field to add the message to
318-
* @param string|null $message The error message if $field is a string
319-
*/
325+
* Add validation error message
326+
* @param string|array $field The field to add the message to
327+
* @param string|null $message The error message if $field is a string
328+
*/
320329
public function addMessage($field, ?string $message = null)
321330
{
322331
if (is_array($field)) {

0 commit comments

Comments
 (0)