@@ -64,9 +64,7 @@ final class Filterer implements FiltererInterface
6464 /**
6565 * @var string
6666 */
67- const INVALID_THROW_ON_ERROR_VALUE_ERROR_FORMAT = (
68- FilterOptions::THROW_ON_ERROR . " for field '%s' was not a boolean value "
69- );
67+ const INVALID_BOOLEAN_FILTER_OPTION = "%s for field '%s' was not a boolean value " ;
7068
7169 /**
7270 * @var array
@@ -147,6 +145,7 @@ public function execute(array $input) : FilterResponse
147145 self ::assertFiltersIsAnArray ($ filters , $ field );
148146 $ customError = self ::validateCustomError ($ filters , $ field );
149147 $ throwOnError = self ::validateThrowOnError ($ filters , $ field );
148+ $ returnOnNull = self ::validateReturnOnNull ($ filters , $ field );
150149 unset($ filters [FilterOptions::IS_REQUIRED ]);//doesn't matter if required since we have this one
151150 unset($ filters [FilterOptions::DEFAULT_VALUE ]);//doesn't matter if there is a default since we have a value
152151 $ conflicts = self ::extractConflicts ($ filters , $ field , $ conflicts );
@@ -169,6 +168,9 @@ public function execute(array $input) : FilterResponse
169168 try {
170169 $ this ->addUsedInputToFilter ($ uses , $ filteredInput , $ field , $ filter );
171170 $ input = call_user_func_array ($ function , $ filter );
171+ if ($ input === null && $ returnOnNull ) {
172+ break ;
173+ }
172174 } catch (Exception $ exception ) {
173175 if ($ throwOnError ) {
174176 throw $ exception ;
@@ -623,7 +625,7 @@ private static function validateThrowOnError(array &$filters, string $field) : b
623625 $ throwOnError = $ filters [FilterOptions::THROW_ON_ERROR ];
624626 if ($ throwOnError !== true && $ throwOnError !== false ) {
625627 throw new InvalidArgumentException (
626- sprintf (self ::INVALID_THROW_ON_ERROR_VALUE_ERROR_FORMAT , $ field )
628+ sprintf (self ::INVALID_BOOLEAN_FILTER_OPTION , FilterOptions:: THROW_ON_ERROR , $ field )
627629 );
628630 }
629631
@@ -632,6 +634,24 @@ private static function validateThrowOnError(array &$filters, string $field) : b
632634 return $ throwOnError ;
633635 }
634636
637+ private static function validateReturnOnNull (array &$ filters , string $ field ) : bool
638+ {
639+ if (!array_key_exists (FilterOptions::RETURN_ON_NULL , $ filters )) {
640+ return false ;
641+ }
642+
643+ $ returnOnNull = $ filters [FilterOptions::RETURN_ON_NULL ];
644+ if ($ returnOnNull !== true && $ returnOnNull !== false ) {
645+ throw new InvalidArgumentException (
646+ sprintf (self ::INVALID_BOOLEAN_FILTER_OPTION , FilterOptions::RETURN_ON_NULL , $ field )
647+ );
648+ }
649+
650+ unset($ filters [FilterOptions::RETURN_ON_NULL ]);
651+
652+ return $ returnOnNull ;
653+ }
654+
635655 private static function validateCustomError (array &$ filters , string $ field )
636656 {
637657 $ customError = null ;
0 commit comments