33namespace ProgrammatorDev \YetAnotherPhpValidator \Rule ;
44
55use ProgrammatorDev \YetAnotherPhpValidator \Exception \NotBlankException ;
6- use Symfony \Component \OptionsResolver \OptionsResolver ;
76
87class NotBlank extends AbstractRule implements RuleInterface
98{
10- private array $ options ;
9+ // Using array to bypass unallowed callable type in properties
10+ private ?array $ normalizer = null ;
1111
12- public function __construct (array $ options = [])
13- {
14- $ resolver = new OptionsResolver ();
15-
16- $ resolver ->setDefaults ([
17- 'normalizer ' => null ,
18- 'message ' => 'The "{{ name }}" value should not be blank, "{{ value }}" given. '
19- ]);
12+ private ?string $ message ;
2013
21- $ resolver ->setAllowedTypes ('normalizer ' , ['null ' , 'callable ' ]);
22- $ resolver ->setAllowedTypes ('message ' , 'string ' );
23-
24- $ this ->options = $ resolver ->resolve ($ options );
14+ public function __construct (
15+ ?callable $ normalizer = null ,
16+ ?string $ message = null
17+ )
18+ {
19+ $ this ->normalizer ['callable ' ] = $ normalizer ;
20+ $ this ->message = $ message ?? 'The "{{ name }}" value should not be blank, "{{ value }}" given. ' ;
2521 }
2622
2723 /**
@@ -33,14 +29,14 @@ public function assert(mixed $value, string $name): void
3329 $ input = $ value ;
3430
3531 // Call normalizer if provided
36- if ($ this ->options [ ' normalizer ' ] !== null ) {
37- $ input = ($ this ->options [ ' normalizer ' ])($ input );
32+ if ($ this ->normalizer [ ' callable ' ] !== null ) {
33+ $ input = ($ this ->normalizer [ ' callable ' ])($ input );
3834 }
3935
4036 // Do not allow null, false, [] and ''
4137 if ($ input === false || (empty ($ input ) && $ input != '0 ' )) {
4238 throw new NotBlankException (
43- message: $ this ->options [ ' message ' ] ,
39+ message: $ this ->message ,
4440 parameters: [
4541 'value ' => $ value ,
4642 'name ' => $ name
0 commit comments