|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\Core\Helpers; |
|
4
|
|
|
|
|
5
|
|
|
use League\Flysystem\Adapter\Local; |
|
6
|
|
|
use League\Flysystem\FilesystemInterface; |
|
7
|
|
|
use Maniaplanet\DedicatedServer\Connection; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class FileSystem |
|
11
|
|
|
* |
|
12
|
|
|
* @package eXpansion\Framework\Core\Helpers; |
|
13
|
|
|
* @author oliver de Cramer <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class FileSystem |
|
16
|
|
|
{ |
|
17
|
|
|
const CONNECTION_TYPE_LOCAL = 'local'; |
|
18
|
|
|
const CONNECTION_TYPE_REMOTE = 'remote'; |
|
19
|
|
|
|
|
20
|
|
|
/** @var Connection */ |
|
21
|
|
|
protected $connection; |
|
22
|
|
|
|
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
protected $connectionType; |
|
25
|
|
|
|
|
26
|
|
|
/** @var array */ |
|
27
|
|
|
protected $adapterParams; |
|
28
|
|
|
|
|
29
|
|
|
/** @var Local */ |
|
30
|
|
|
protected $localAdapter; |
|
31
|
|
|
|
|
32
|
|
|
/** @var FilesystemInterface */ |
|
33
|
|
|
protected $remoteAdapter; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* FileSystem constructor. |
|
37
|
|
|
* |
|
38
|
|
|
* @param Connection $connection |
|
39
|
|
|
* @param string $connectionType |
|
40
|
|
|
* @param FilesystemInterface $remoteAdapter |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct(Connection $connection, string $connectionType, FilesystemInterface $remoteAdapter) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->connection = $connection; |
|
45
|
|
|
$this->connectionType = $connectionType; |
|
46
|
|
|
$this->remoteAdapter = $remoteAdapter; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get Filesystem adapter for the user data directory of the dedicated server. |
|
51
|
|
|
* |
|
52
|
|
|
* @return FilesystemInterface |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getUserData() : FilesystemInterface |
|
55
|
|
|
{ |
|
56
|
|
|
if ($this->connectionType == self::CONNECTION_TYPE_LOCAL) { |
|
57
|
|
|
return $this->getLocalAdapter(); |
|
58
|
|
|
} else { |
|
59
|
|
|
return $this->remoteAdapter; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Get local adapter if dedicated is installed on same host. |
|
65
|
|
|
* |
|
66
|
|
|
* @return FilesystemInterface |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function getLocalAdapter() : FilesystemInterface |
|
69
|
|
|
{ |
|
70
|
|
|
if (is_null($this->localAdapter)) { |
|
71
|
|
|
$dir = $this->connection->getMapsDirectory(); |
|
72
|
|
|
$this->localAdapter = new \League\Flysystem\Filesystem(new Local($dir . '/../')); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $this->localAdapter; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..