Status.php
764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace ACP\API;
use AC\Storage\KeyValuePair;
use AC\Storage\OptionFactory;
use ACP\Type;
class Status {
const OPTION_KEY = 'acp_api_status';
/**
* @var KeyValuePair
*/
private $storage;
public function __construct( Type\SiteId $site_id, $network_active ) {
$this->storage = ( new OptionFactory() )->create( self::OPTION_KEY . $site_id->get_hash(), (bool) $network_active );
}
public function save( Type\ApiStatus $status ) {
$this->storage->save( $status->get_value() );
}
public function delete() {
$this->storage->delete();
}
/**
* @return Type\ApiStatus|null
*/
public function get() {
$status = $this->storage->get();
return Type\ApiStatus::is_valid( $status )
? new Type\ApiStatus( $status )
: null;
}
}