| 1 |
<?php |
| 2 |
/** |
| 3 |
* OpenStation App Framework — standalone Settings adapter. |
| 4 |
* |
| 5 |
* Two plain arrays. The host seeds them; apps read them. |
| 6 |
* |
| 7 |
* @package OpenStation |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace OpenStation\App\Standalone; |
| 11 |
|
| 12 |
use OpenStation\App\Contracts\Settings as SettingsContract; |
| 13 |
|
| 14 |
// Direct access, unless a standalone host is booting on bare PHP. |
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
defined( 'OPENSTATION_STANDALONE' ) || exit; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Array-backed settings. |
| 21 |
*/ |
| 22 |
final class Settings implements SettingsContract { |
| 23 |
|
| 24 |
/** |
| 25 |
* @var array<string,mixed> |
| 26 |
*/ |
| 27 |
private $preferences; |
| 28 |
|
| 29 |
/** |
| 30 |
* @var array<string,mixed> |
| 31 |
*/ |
| 32 |
private $options; |
| 33 |
|
| 34 |
/** |
| 35 |
* @param array<string,mixed> $preferences Per-user preferences. |
| 36 |
* @param array<string,mixed> $options Site options. |
| 37 |
*/ |
| 38 |
public function __construct( array $preferences = array(), array $options = array() ) { |
| 39 |
$this->preferences = $preferences; |
| 40 |
$this->options = $options; |
| 41 |
} |
| 42 |
|
| 43 |
/** {@inheritDoc} */ |
| 44 |
public function user_preference( $key, $fallback = null ) { |
| 45 |
return array_key_exists( $key, $this->preferences ) ? $this->preferences[ $key ] : $fallback; |
| 46 |
} |
| 47 |
|
| 48 |
/** {@inheritDoc} */ |
| 49 |
public function site_option( $key, $fallback = null ) { |
| 50 |
return array_key_exists( $key, $this->options ) ? $this->options[ $key ] : $fallback; |
| 51 |
} |
| 52 |
} |
| 53 |
|