| 1 |
<?php |
| 2 |
|
| 3 |
namespace Hostinger; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
class Config { |
| 8 |
private array $config = array(); |
| 9 |
public const TOKEN_HEADER = 'X-Hpanel-Order-Token'; |
| 10 |
public const DOMAIN_HEADER = 'X-Hpanel-Domain'; |
| 11 |
public function __construct() { |
| 12 |
$this->decode_config( HOSTINGER_WP_CONFIG_PATH ); |
| 13 |
} |
| 14 |
|
| 15 |
private function decode_config( string $path ): void { |
| 16 |
if ( file_exists( $path ) ) { |
| 17 |
$config_content = file_get_contents( $path ); |
| 18 |
$this->config = json_decode( $config_content, true ); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
public function get_config_value( string $key, $default ): string { |
| 23 |
if ( $this->config && isset( $this->config[ $key ] ) && ! empty( $this->config[ $key ] ) ) { |
| 24 |
return $this->config[ $key ]; |
| 25 |
} |
| 26 |
|
| 27 |
return $default; |
| 28 |
} |
| 29 |
} |
| 30 |
|