|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\kw_auth_sources\Sources\Files\Storages; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_auth_sources\AuthSourcesException; |
|
7
|
|
|
use kalanis\kw_auth_sources\Interfaces\IKAusTranslations; |
|
8
|
|
|
use kalanis\kw_auth_sources\Traits\TLang; |
|
9
|
|
|
use kalanis\kw_files\FilesException; |
|
10
|
|
|
use kalanis\kw_files\Interfaces\IFLTranslations; |
|
11
|
|
|
use kalanis\kw_files\Interfaces\IProcessFiles; |
|
12
|
|
|
use kalanis\kw_files\Traits\TToString; |
|
13
|
|
|
use kalanis\kw_paths\PathsException; |
|
14
|
|
|
use kalanis\kw_paths\Stuff; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class Files |
|
19
|
|
|
* @package kalanis\kw_auth_sources\Sources\Files\Storages |
|
20
|
|
|
* Processing files in storage defined with interfaces from kw_files |
|
21
|
|
|
*/ |
|
22
|
|
|
class Files extends AStorage |
|
23
|
|
|
{ |
|
24
|
|
|
use TLang; |
|
25
|
|
|
use TToString; |
|
26
|
|
|
|
|
27
|
|
|
/** @var IProcessFiles */ |
|
28
|
|
|
protected $files = null; |
|
29
|
|
|
|
|
30
|
7 |
|
public function __construct(IProcessFiles $files, ?IKAusTranslations $ausLang = null, ?IFLTranslations $lang = null) |
|
31
|
|
|
{ |
|
32
|
7 |
|
$this->files = $files; |
|
33
|
7 |
|
$this->setAusLang($ausLang); |
|
34
|
7 |
|
$this->setLang($lang); |
|
35
|
7 |
|
} |
|
36
|
|
|
|
|
37
|
2 |
|
protected function open(array $path): string |
|
38
|
|
|
{ |
|
39
|
|
|
try { |
|
40
|
2 |
|
return $this->toString(Stuff::arrayToPath($path), $this->files->readFile($path)); |
|
41
|
1 |
|
} catch (FilesException | PathsException $ex) { |
|
42
|
1 |
|
throw new AuthSourcesException($ex->getMessage(), $ex->getCode(), $ex); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
2 |
|
protected function save(array $path, string $content): bool |
|
47
|
|
|
{ |
|
48
|
|
|
try { |
|
49
|
2 |
|
return $this->files->saveFile($path, $content); |
|
50
|
1 |
|
} catch (FilesException | PathsException $ex) { |
|
51
|
1 |
|
throw new AuthSourcesException($ex->getMessage(), $ex->getCode(), $ex); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return string |
|
57
|
|
|
* @codeCoverageIgnore translation |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function noDirectoryDelimiterSet(): string |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->getAusLang()->kauNoDelimiterSet(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|