Platform.php
1.19 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace ACP\Server;
use AC\Storage\KeyValuePair;
use AC\Storage\OptionFactory;
use ACP\Type;
class Platform {
const OPTION_PLATFORM_PREFIX = 'acp_platform_';
/**
* @var KeyValuePair
*/
private $storage;
public function __construct( Type\SiteId $site_id, $network_active ) {
$this->storage = ( new OptionFactory() )->create( self::OPTION_PLATFORM_PREFIX . $site_id->get_hash(), (bool) $network_active );
}
public function is_local() {
return $this->is_server_local() || $this->is_remote_local();
}
public function is_remote_local() {
return Type\Platform::LOCAL === $this->storage->get();
}
public function is_server_local() {
return isset( $_SERVER['REMOTE_ADDR'] ) && in_array( $_SERVER['REMOTE_ADDR'], [ '127.0.0.1', '::1' ], true );
}
public function remote_exists() {
return null !== $this->find();
}
/**
* @return Type\Platform|null
*/
private function find() {
$platform = $this->storage->get();
return Type\Platform::is_valid( $platform )
? new Type\Platform( $platform )
: null;
}
public function delete() {
$this->storage->delete();
}
public function save( Type\Platform $platform ) {
$this->storage->save( $platform->get_value() );
}
}