Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 70f74aa

Browse files
committed
feat: added NotBlank normalizer option
1 parent 23d3a2a commit 70f74aa

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/Rule/NotBlank.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ public function __construct(array $options = [])
1313
{
1414
$resolver = new OptionsResolver();
1515

16-
$resolver->setDefaults(['message' => 'The "{{ name }}" value should not be blank, "{{ value }}" given.']);
16+
$resolver->setDefaults([
17+
'message' => 'The "{{ name }}" value should not be blank, "{{ value }}" given.',
18+
'normalizer' => null
19+
]);
1720

1821
$resolver->setAllowedTypes('message', 'string');
22+
$resolver->setAllowedTypes('normalizer', ['null', 'string', 'callable']);
1923

2024
$this->options = $resolver->resolve($options);
2125
}
@@ -25,8 +29,16 @@ public function __construct(array $options = [])
2529
*/
2630
public function assert(mixed $value, string $name): void
2731
{
32+
// Keep original value for parameter
33+
$input = $value;
34+
35+
// Call normalizer if provided
36+
if ($this->options['normalizer'] !== null) {
37+
$input = ($this->options['normalizer'])($input);
38+
}
39+
2840
// Do not allow null, false, [] and ''
29-
if ($value === false || (empty($value) && $value != '0')) {
41+
if ($input === false || (empty($input) && $input != '0')) {
3042
throw new NotBlankException(
3143
message: $this->options['message'],
3244
parameters: [

0 commit comments

Comments
 (0)