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_paths\PathsException; |
10
|
|
|
use kalanis\kw_paths\Stuff; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Volume |
15
|
|
|
* @package kalanis\kw_auth_sources\Sources\Files\Volume |
16
|
|
|
* Processing files on local volume |
17
|
|
|
*/ |
18
|
|
|
class Volume extends AStorage |
19
|
|
|
{ |
20
|
|
|
use TLang; |
21
|
|
|
|
22
|
|
|
protected string $startDirectory = ''; |
23
|
|
|
|
24
|
14 |
|
public function __construct(string $where, ?IKAusTranslations $ausLang = null) |
25
|
|
|
{ |
26
|
14 |
|
$this->startDirectory = $where; |
27
|
14 |
|
$this->setAusLang($ausLang); |
28
|
14 |
|
} |
29
|
|
|
|
30
|
2 |
|
protected function open(array $path): string |
31
|
|
|
{ |
32
|
|
|
try { |
33
|
2 |
|
$pt = $this->startDirectory . Stuff::arrayToPath($path); |
34
|
2 |
|
$content = @file_get_contents($pt); |
35
|
2 |
|
if (false === $content) { |
36
|
1 |
|
throw new AuthSourcesException($this->getAusLang()->kauPassFileNotFound($pt)); |
37
|
|
|
} |
38
|
1 |
|
return strval($content); |
39
|
|
|
// @codeCoverageIgnoreStart |
40
|
1 |
|
} catch (PathsException $ex) { |
41
|
|
|
throw new AuthSourcesException($ex->getMessage(), $ex->getCode(), $ex); |
42
|
|
|
} |
43
|
|
|
// @codeCoverageIgnoreEnd |
44
|
|
|
} |
45
|
|
|
|
46
|
2 |
|
protected function save(array $path, string $content): bool |
47
|
|
|
{ |
48
|
|
|
try { |
49
|
2 |
|
$pt = $this->startDirectory . Stuff::arrayToPath($path); |
50
|
2 |
|
return boolval(@file_put_contents($pt, $content)); |
51
|
|
|
// @codeCoverageIgnoreStart |
52
|
|
|
} catch (PathsException $ex) { |
53
|
|
|
throw new AuthSourcesException($ex->getMessage(), $ex->getCode(), $ex); |
54
|
|
|
} |
55
|
|
|
// @codeCoverageIgnoreEnd |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return string |
60
|
|
|
* @codeCoverageIgnore translation |
61
|
|
|
*/ |
62
|
|
|
protected function noDirectoryDelimiterSet(): string |
63
|
|
|
{ |
64
|
|
|
return $this->getAusLang()->kauNoDelimiterSet(); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|