| 1 |
<?php |
| 2 |
/** |
| 3 |
* Contains the default configuration items. |
| 4 |
* |
| 5 |
* @package SolidWP\Performance |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace SolidWP\Performance\Config; |
| 11 |
|
| 12 |
use SolidWP\Performance\StellarWP\Arrays\Arr; |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Contains the default configuration items. |
| 20 |
* |
| 21 |
* @template T of array{page_cache: array{cache_dir: string, debug: bool, enabled: bool, expiration: int, exclusions: string[]}} |
| 22 |
* |
| 23 |
* @see Provider::register() |
| 24 |
* |
| 25 |
* @package SolidWP\Performance |
| 26 |
*/ |
| 27 |
final class Default_Config { |
| 28 |
|
| 29 |
/** |
| 30 |
* The default configuration items. |
| 31 |
* |
| 32 |
* @var T |
| 33 |
*/ |
| 34 |
private array $defaults; |
| 35 |
|
| 36 |
/** |
| 37 |
* @param array<string, mixed> $defaults The default config items. |
| 38 |
*/ |
| 39 |
public function __construct( array $defaults ) { |
| 40 |
$this->defaults = $defaults; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Get the value of a default config item. |
| 45 |
* |
| 46 |
* @param string|null $key The config key, if no key we'll return all items. |
| 47 |
* |
| 48 |
* @return mixed|T |
| 49 |
*/ |
| 50 |
public function get( ?string $key = null ) { |
| 51 |
if ( is_null( $key ) ) { |
| 52 |
return $this->defaults; |
| 53 |
} |
| 54 |
|
| 55 |
return Arr::get( $this->defaults, explode( '.', $key ) ); |
| 56 |
} |
| 57 |
} |
| 58 |
|