| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace RenzoJohnson\Blocks\Settings; |
| 6 |
|
| 7 |
\defined( 'ABSPATH' ) || exit; |
| 8 |
|
| 9 |
final class SettingDefinition { |
| 10 |
/** @throws \InvalidArgumentException When security or naming invariants are violated. */ |
| 11 |
public function __construct( |
| 12 |
public readonly string $option_name, |
| 13 |
public readonly string $wp_type, |
| 14 |
public readonly bool|int|string $default_value, |
| 15 |
public readonly SanitizerType $sanitizer, |
| 16 |
public readonly bool $sensitive = false, |
| 17 |
public readonly bool $exportable = true, |
| 18 |
public readonly ?string $public_token = null, |
| 19 |
) { |
| 20 |
if ( ! \str_starts_with( $option_name, 'blocks_' ) ) { |
| 21 |
throw new \InvalidArgumentException( 'Blocks setting names must use the blocks_ prefix.' ); |
| 22 |
} |
| 23 |
|
| 24 |
if ( $sensitive && ( $exportable || null !== $public_token ) ) { |
| 25 |
throw new \InvalidArgumentException( 'Sensitive settings cannot be exported or public tokens.' ); |
| 26 |
} |
| 27 |
|
| 28 |
if ( PublicTokenRegistry::for_option( $option_name ) !== $public_token ) { |
| 29 |
throw new \InvalidArgumentException( 'Setting token metadata does not match the public token registry.' ); |
| 30 |
} |
| 31 |
} |
| 32 |
} |
| 33 |
|