| 1 |
<?php |
| 2 |
/** |
| 3 |
* OpenStation App Framework — standalone Store adapter. |
| 4 |
* |
| 5 |
* In-memory. A bare PHP host that needs durability passes its own |
| 6 |
* implementation to `Os::standalone( array( 'store' => … ) )`. |
| 7 |
* |
| 8 |
* @package OpenStation |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace OpenStation\App\Standalone; |
| 12 |
|
| 13 |
use OpenStation\App\Contracts\Store as StoreContract; |
| 14 |
|
| 15 |
// Direct access, unless a standalone host is booting on bare PHP. |
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
defined( 'OPENSTATION_STANDALONE' ) || exit; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* In-memory key/value store. |
| 22 |
*/ |
| 23 |
final class Store implements StoreContract { |
| 24 |
|
| 25 |
/** |
| 26 |
* @var array<string,array<string,mixed>> |
| 27 |
*/ |
| 28 |
private $data = array( |
| 29 |
'user' => array(), |
| 30 |
'site' => array(), |
| 31 |
); |
| 32 |
|
| 33 |
/** {@inheritDoc} */ |
| 34 |
public function get( $scope, $key, $fallback = null ) { |
| 35 |
return isset( $this->data[ $scope ] ) && array_key_exists( $key, $this->data[ $scope ] ) |
| 36 |
? $this->data[ $scope ][ $key ] |
| 37 |
: $fallback; |
| 38 |
} |
| 39 |
|
| 40 |
/** {@inheritDoc} */ |
| 41 |
public function set( $scope, $key, $value ) { |
| 42 |
$this->data[ $scope ][ $key ] = $value; |
| 43 |
} |
| 44 |
|
| 45 |
/** {@inheritDoc} */ |
| 46 |
public function delete( $scope, $key ) { |
| 47 |
unset( $this->data[ $scope ][ $key ] ); |
| 48 |
} |
| 49 |
} |
| 50 |
|