1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\RemoteRequest\Protocols\Fsp\Query; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\RemoteRequest\Protocols\Fsp; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class SetProtection |
11
|
|
|
* @package kalanis\RemoteRequest\Protocols\Fsp\Query |
12
|
|
|
* Set dir protection details |
13
|
|
|
*/ |
14
|
|
|
class SetProtection extends AQuery |
15
|
|
|
{ |
16
|
|
|
public const CAN_CREATE_FILE = 'c'; |
17
|
|
|
public const CAN_DELETE_FILE = 'd'; |
18
|
|
|
public const CAN_GET_FILE = 'g'; |
19
|
|
|
public const CAN_PRESERVE_FILE = 'p'; // backward compatibility |
20
|
|
|
public const CAN_CREATE_DIR = 'c'; |
21
|
|
|
public const CAN_LIST_DIR = 'd'; |
22
|
|
|
public const CAN_RENAME_FILE = 'g'; |
23
|
|
|
|
24
|
|
|
public const ALLOW = '+'; |
25
|
|
|
public const DISCARD = '-'; |
26
|
|
|
|
27
|
|
|
protected string $dirPath = ''; |
28
|
|
|
protected string $operation = ''; |
29
|
|
|
protected ?bool $allow = null; |
30
|
|
|
|
31
|
1 |
|
protected function getCommand(): int |
32
|
|
|
{ |
33
|
1 |
|
return Fsp::CC_SET_PRO; |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
public function setDirPath(string $filePath): self |
37
|
|
|
{ |
38
|
1 |
|
$this->dirPath = $filePath; |
39
|
1 |
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function setOperation(string $operation): self |
43
|
|
|
{ |
44
|
1 |
|
if (in_array($operation, [ |
45
|
1 |
|
static::CAN_CREATE_FILE, |
46
|
1 |
|
static::CAN_DELETE_FILE, |
47
|
1 |
|
static::CAN_GET_FILE, |
48
|
1 |
|
static::CAN_PRESERVE_FILE, |
49
|
1 |
|
static::CAN_CREATE_DIR, |
50
|
1 |
|
static::CAN_LIST_DIR, |
51
|
1 |
|
static::CAN_RENAME_FILE, |
52
|
1 |
|
])) { |
53
|
1 |
|
$this->operation = $operation; |
54
|
|
|
} |
55
|
1 |
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
1 |
|
public function allowOperation(bool $allow): self |
59
|
|
|
{ |
60
|
1 |
|
$this->allow = $allow; |
61
|
1 |
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
protected function getFilePosition(): int |
65
|
|
|
{ |
66
|
1 |
|
return strlen($this->getExtraData()); |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
protected function getData(): string |
70
|
|
|
{ |
71
|
1 |
|
return $this->dirPath . chr(0); |
72
|
|
|
} |
73
|
|
|
|
74
|
1 |
|
protected function getExtraData(): string |
75
|
|
|
{ |
76
|
1 |
|
if (static::CAN_PRESERVE_FILE == $this->operation) { |
77
|
1 |
|
$this->operation = static::CAN_RENAME_FILE; |
78
|
1 |
|
$this->allow = !$this->allow; |
79
|
|
|
} |
80
|
1 |
|
return ($this->allow ? static::ALLOW : static::DISCARD) . $this->operation ; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|