| 1 |
<?php |
| 2 |
/** |
| 3 |
* The base URL to use to trigger a preload batch. |
| 4 |
* |
| 5 |
* @package SolidWP\Performance |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace SolidWP\Performance\Preload; |
| 11 |
|
| 12 |
use InvalidArgumentException; |
| 13 |
|
| 14 |
/** |
| 15 |
* The base URL to use to trigger a preload batch. |
| 16 |
* |
| 17 |
* @package SolidWP\Performance |
| 18 |
*/ |
| 19 |
final class Trigger_Url { |
| 20 |
|
| 21 |
/** |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
private string $trigger_url; |
| 25 |
|
| 26 |
/** |
| 27 |
* @param string $trigger_url The base URL to use to trigger a preload batch. |
| 28 |
* |
| 29 |
* @throws InvalidArgumentException If the trigger URL is empty. |
| 30 |
*/ |
| 31 |
public function __construct( string $trigger_url ) { |
| 32 |
if ( strlen( $trigger_url ) === 0 ) { |
| 33 |
throw new InvalidArgumentException( 'The trigger URL cannot be empty' ); |
| 34 |
} |
| 35 |
|
| 36 |
if ( esc_url_raw( $trigger_url, [ 'http', 'https' ] ) !== $trigger_url ) { |
| 37 |
throw new InvalidArgumentException( 'The trigger URL is not a valid URL' ); |
| 38 |
} |
| 39 |
|
| 40 |
$this->trigger_url = $trigger_url; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Get the trigger URL. |
| 45 |
* |
| 46 |
* @return string |
| 47 |
*/ |
| 48 |
public function get(): string { |
| 49 |
return $this->trigger_url; |
| 50 |
} |
| 51 |
} |
| 52 |
|