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