|
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
|
|
|
/** @var string */ |
|
22
|
|
|
protected $moduleConfPath = ''; |
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
protected $path = ''; |
|
25
|
|
|
|
|
26
|
8 |
|
public function __construct(string $moduleConfPath, ?IMdTranslations $lang = null) |
|
27
|
|
|
{ |
|
28
|
8 |
|
$this->setMdLang($lang); |
|
29
|
8 |
|
$this->moduleConfPath = $moduleConfPath; |
|
30
|
8 |
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
public function setModuleLevel(int $level): void |
|
33
|
|
|
{ |
|
34
|
1 |
|
$this->path = implode(DIRECTORY_SEPARATOR, [ |
|
35
|
1 |
|
realpath($this->moduleConfPath), |
|
36
|
1 |
|
sprintf('%s.%d.%s', IPaths::DIR_MODULE, $level, IPaths::DIR_CONF ) |
|
37
|
|
|
]); |
|
38
|
1 |
|
} |
|
39
|
|
|
|
|
40
|
2 |
|
public function load(): string |
|
41
|
|
|
{ |
|
42
|
2 |
|
$data = @ file_get_contents($this->getPath()); |
|
43
|
1 |
|
if (false === $data) { |
|
44
|
|
|
// @codeCoverageIgnoreStart |
|
45
|
|
|
throw new ModuleException($this->getMdLang()->mdStorageLoadProblem()); |
|
46
|
|
|
} |
|
47
|
|
|
// @codeCoverageIgnoreEnd |
|
48
|
1 |
|
return strval($data); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
public function save(string $records): bool |
|
52
|
|
|
{ |
|
53
|
1 |
|
return boolval(intval(@ file_put_contents($this->getPath(), $records))); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @throws ModuleException |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
2 |
|
protected function getPath(): string |
|
61
|
|
|
{ |
|
62
|
2 |
|
if (empty($this->path)) { |
|
63
|
1 |
|
throw new ModuleException($this->getMdLang()->mdStorageTargetNotSet()); |
|
64
|
|
|
} |
|
65
|
1 |
|
return $this->path; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|