1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_modules\ModulesLists\File; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_modules\Interfaces\IMdTranslations; |
7
|
|
|
use kalanis\kw_modules\Interfaces\Lists\IFile; |
8
|
|
|
use kalanis\kw_modules\ModuleException; |
9
|
|
|
use kalanis\kw_modules\Traits\TMdLang; |
10
|
|
|
use kalanis\kw_paths\Interfaces\IPaths; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Volume |
15
|
|
|
* @package kalanis\kw_modules\ModulesLists\File |
16
|
|
|
*/ |
17
|
|
|
class Volume implements IFile |
18
|
|
|
{ |
19
|
|
|
use TMdLang; |
20
|
|
|
|
21
|
|
|
protected string $moduleConfPath = ''; |
22
|
|
|
protected string $path = ''; |
23
|
|
|
|
24
|
8 |
|
public function __construct(string $moduleConfPath, ?IMdTranslations $lang = null) |
25
|
|
|
{ |
26
|
8 |
|
$this->setMdLang($lang); |
27
|
8 |
|
$this->moduleConfPath = $moduleConfPath; |
28
|
8 |
|
} |
29
|
|
|
|
30
|
1 |
|
public function setModuleLevel(int $level): void |
31
|
|
|
{ |
32
|
1 |
|
$this->path = implode(DIRECTORY_SEPARATOR, [ |
33
|
1 |
|
realpath($this->moduleConfPath), |
34
|
1 |
|
sprintf('%s.%d.%s', IPaths::DIR_MODULE, $level, IPaths::DIR_CONF ) |
35
|
|
|
]); |
36
|
1 |
|
} |
37
|
|
|
|
38
|
2 |
|
public function load(): string |
39
|
|
|
{ |
40
|
2 |
|
$data = @ file_get_contents($this->getPath()); |
41
|
1 |
|
if (false === $data) { |
42
|
|
|
// @codeCoverageIgnoreStart |
43
|
|
|
throw new ModuleException($this->getMdLang()->mdStorageLoadProblem()); |
44
|
|
|
} |
45
|
|
|
// @codeCoverageIgnoreEnd |
46
|
1 |
|
return strval($data); |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
public function save(string $records): bool |
50
|
|
|
{ |
51
|
1 |
|
return boolval(intval(@ file_put_contents($this->getPath(), $records))); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @throws ModuleException |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
2 |
|
protected function getPath(): string |
59
|
|
|
{ |
60
|
2 |
|
if (empty($this->path)) { |
61
|
1 |
|
throw new ModuleException($this->getMdLang()->mdStorageTargetNotSet()); |
62
|
|
|
} |
63
|
1 |
|
return $this->path; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|