| 1 |
<?php |
| 2 |
/** |
| 3 |
* The trusted proxy preset class. |
| 4 |
* |
| 5 |
* @package WP_Defender\Component\Trusted_Proxy_Preset |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Component\Trusted_Proxy_Preset; |
| 9 |
|
| 10 |
use Exception; |
| 11 |
use InvalidArgumentException; |
| 12 |
|
| 13 |
/** |
| 14 |
* Represents a trusted proxy preset. |
| 15 |
*/ |
| 16 |
class Trusted_Proxy_Preset { |
| 17 |
|
| 18 |
/** |
| 19 |
* Proxy preset name. |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
private $proxy_preset = ''; |
| 24 |
|
| 25 |
/** |
| 26 |
* Sets the proxy preset. |
| 27 |
* |
| 28 |
* @param string $proxy_preset Proxy preset name. |
| 29 |
*/ |
| 30 |
public function set_proxy_preset( string $proxy_preset ): void { |
| 31 |
$this->proxy_preset = $proxy_preset; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Get proxy preset instance. |
| 36 |
* |
| 37 |
* @return mixed |
| 38 |
* @throws InvalidArgumentException Unknown proxy type. |
| 39 |
*/ |
| 40 |
private function instance() { |
| 41 |
switch ( $this->proxy_preset ) { |
| 42 |
case Cloudflare_Proxy::PROXY_SLUG: |
| 43 |
return wd_di()->get( Cloudflare_Proxy::class ); |
| 44 |
default: |
| 45 |
throw new InvalidArgumentException( 'Unknown proxy type: ' . esc_html( $this->proxy_preset ) ); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Get trusted preset IPs. |
| 51 |
* |
| 52 |
* @return mixed |
| 53 |
*/ |
| 54 |
public function get_ips() { |
| 55 |
try { |
| 56 |
return $this->instance()->get_ips(); |
| 57 |
} catch ( Exception $e ) { |
| 58 |
return false; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Update trusted preset IPs. |
| 64 |
* |
| 65 |
* @return mixed |
| 66 |
*/ |
| 67 |
public function update_ips() { |
| 68 |
try { |
| 69 |
return $this->instance()->update_ips(); |
| 70 |
} catch ( Exception $e ) { |
| 71 |
return false; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Delete trusted preset IPs. |
| 77 |
* |
| 78 |
* @return bool |
| 79 |
*/ |
| 80 |
public function delete_ips() { |
| 81 |
try { |
| 82 |
return $this->instance()->delete_ips(); |
| 83 |
} catch ( Exception $e ) { |
| 84 |
return false; |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|