NullStorage.php
1.45 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace YahnisElsts\AdminMenuEditor\Customizable\Storage;
use ameMultiDictionary;
class NullStorage implements StorageInterface {
private $isPreviewing;
private $previewValue;
public function getValue($defaultValue = null) {
return $this->isPreviewing ? $this->previewValue : $defaultValue;
}
public function getPath($path, $defaultValue = null) {
if ( $this->isPreviewing && is_array($this->previewValue) ) {
return ameMultiDictionary::get($this->previewValue, $path, $defaultValue);
}
return $defaultValue;
}
public function setValue($value) {
//Do nothing.
return true;
}
public function setPath($path, $value) {
//Do nothing.
return true;
}
public function deleteValue() {
//Also do nothing here.
}
public function deletePath($path) {
//Do nothing.
}
public function buildSlot($path) {
return new Slot($this, $path);
}
public function save() {
//Do nothing.
}
public function getStorageKey() {
return '{NullStorage}';
}
public function addReadAliases($aliases) {
//We store nothing, so we don't need aliases.
}
public function getSmallestSavable() {
return $this;
}
public function setPreviewValue($value) {
$this->isPreviewing = true;
$this->previewValue = $value;
}
public function setPreviewByPath($path, $value) {
$this->isPreviewing = true;
if ( !is_array($this->previewValue) ) {
$this->previewValue = [];
}
ameMultiDictionary::set($this->previewValue, $path, $value);
}
}