@@ -61,6 +61,13 @@ final class Filterer implements FiltererInterface
6161 */
6262 const RESPONSE_TYPE_FILTER = FilterResponse::class;
6363
64+ /**
65+ * @var string
66+ */
67+ const INVALID_THROW_ON_ERROR_VALUE_ERROR_FORMAT = (
68+ FilterOptions::THROW_ON_ERROR . " for field '%s' was not a boolean value "
69+ );
70+
6471 /**
6572 * @var array
6673 */
@@ -139,6 +146,7 @@ public function execute(array $input) : FilterResponse
139146 $ filters = $ this ->specification [$ field ];
140147 self ::assertFiltersIsAnArray ($ filters , $ field );
141148 $ customError = self ::validateCustomError ($ filters , $ field );
149+ $ throwOnError = self ::validateThrowOnError ($ filters , $ field );
142150 unset($ filters [FilterOptions::IS_REQUIRED ]);//doesn't matter if required since we have this one
143151 unset($ filters [FilterOptions::DEFAULT_VALUE ]);//doesn't matter if there is a default since we have a value
144152 $ conflicts = self ::extractConflicts ($ filters , $ field , $ conflicts );
@@ -162,6 +170,10 @@ public function execute(array $input) : FilterResponse
162170 $ this ->addUsedInputToFilter ($ uses , $ filteredInput , $ field , $ filter );
163171 $ input = call_user_func_array ($ function , $ filter );
164172 } catch (Exception $ exception ) {
173+ if ($ throwOnError ) {
174+ throw $ exception ;
175+ }
176+
165177 $ errors = self ::handleCustomError ($ field , $ input , $ exception , $ errors , $ customError );
166178 continue 2 ;//next field
167179 }
@@ -602,6 +614,24 @@ private static function assertFilterIsArray($filter, string $field)
602614 }
603615 }
604616
617+ private static function validateThrowOnError (array &$ filters , string $ field ) : bool
618+ {
619+ if (!array_key_exists (FilterOptions::THROW_ON_ERROR , $ filters )) {
620+ return false ;
621+ }
622+
623+ $ throwOnError = $ filters [FilterOptions::THROW_ON_ERROR ];
624+ if ($ throwOnError !== true && $ throwOnError !== false ) {
625+ throw new InvalidArgumentException (
626+ sprintf (self ::INVALID_THROW_ON_ERROR_VALUE_ERROR_FORMAT , $ field )
627+ );
628+ }
629+
630+ unset($ filters [FilterOptions::THROW_ON_ERROR ]);
631+
632+ return $ throwOnError ;
633+ }
634+
605635 private static function validateCustomError (array &$ filters , string $ field )
606636 {
607637 $ customError = null ;
0 commit comments