> */ private static array $defaults = [ 'page_cache' => [ 'cache_dir' => WP_CONTENT_DIR . '/cache', 'debug' => false, 'enabled' => true, 'expiration' => 86400, // One day in seconds. 'exclusions' => [], ], ]; /** * An array of changes that will be made to the config when saved. * * @since 0.1.0 * * @var array */ private array $changes = []; /** * The class constructor. * * @param Strategy $strategy The strategy used in determining how config values should be stored and retrieved. * * @since 0.1.0 */ public function __construct( Strategy $strategy ) { $this->strategy = $strategy; } /** * Gets a specific value from the configuration determined by the registered strategy (or strategy pipeline). * If no value is found, the default value will be returned. * * @since 0.1.0 * * @param string $key The key of the value to receive. * * @return mixed */ public function get( string $key ) { $value = $this->strategy->get( $key ); if ( $value === null ) { return Arr::get( self::$defaults, explode( '.', $key ) ); } return $value; } /** * Saves configuration values via the registered strategy. * * @since 0.1.0 * * @return void */ public function save() { $settings = Arr::merge_recursive( self::$defaults, $this->changes ); $this->strategy->save( Arr::dot( $settings ) ); } /** * Sets a key and value change in the config. * * @since 0.1.0 * * @param string $key The key of the change. * @param mixed $value The value of the change. * * @return void */ public function set( string $key, $value ) { $this->changes = Arr::set( $this->changes, explode( '.', $key ), $value ); } /** * Get the default values. * * @return array */ public static function get_defaults(): array { return self::$defaults; } }