| 1 |
<?php |
| 2 |
namespace Give\DonationForms\Rules; |
| 3 |
|
| 4 |
use Closure; |
| 5 |
use Give\Vendors\StellarWP\Validation\Contracts\ValidationRule; |
| 6 |
|
| 7 |
/** |
| 8 |
* @since 3.0.0 |
| 9 |
*/ |
| 10 |
class BillingAddressStateRule implements ValidationRule |
| 11 |
{ |
| 12 |
/** |
| 13 |
* @since 3.0.0 |
| 14 |
*/ |
| 15 |
public static function id(): string |
| 16 |
{ |
| 17 |
return 'state'; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* @since 3.0.0 |
| 22 |
*/ |
| 23 |
public static function fromString(string $options = null): ValidationRule |
| 24 |
{ |
| 25 |
return new self(); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* @since 3.0.0 |
| 30 |
*/ |
| 31 |
public function __invoke($value, Closure $fail, string $key, array $values) |
| 32 |
{ |
| 33 |
if ( !$value && !array_key_exists( $values['country'], give_states_not_required_country_list() ) ) { |
| 34 |
$fail(__('State required.', 'give')); |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|