1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_auth\Sources\Files\Volume; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_auth\AuthException; |
7
|
|
|
use kalanis\kw_auth\Interfaces\IFile; |
8
|
|
|
use kalanis\kw_auth\Traits\TLang; |
9
|
|
|
use kalanis\kw_paths\PathsException; |
10
|
|
|
use kalanis\kw_paths\Stuff; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Trait TVolume |
15
|
|
|
* @package kalanis\kw_auth\Sources\Files\Volume |
16
|
|
|
* Processing files with accounts |
17
|
|
|
*/ |
18
|
|
|
trait TVolume |
19
|
|
|
{ |
20
|
|
|
use TLang; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param string[] $path |
24
|
|
|
* @throws AuthException |
25
|
|
|
* @return array<int, array<int, string>> |
26
|
|
|
*/ |
27
|
17 |
|
protected function openFile(array $path): array |
28
|
|
|
{ |
29
|
|
|
try { |
30
|
17 |
|
$pt = Stuff::arrayToPath($path); |
31
|
17 |
|
$content = @file($pt); |
32
|
17 |
|
if (false === $content) { |
33
|
2 |
|
throw new AuthException($this->getAuLang()->kauPassFileNotFound($pt)); |
34
|
|
|
} |
35
|
15 |
|
return array_map([$this, 'explosion'], array_filter(array_map('trim', $content), [$this, 'filterEmptyLines'])); |
36
|
2 |
|
} catch (PathsException $ex) { |
37
|
|
|
// @codeCoverageIgnoreStart |
38
|
|
|
throw new AuthException($ex->getMessage(), $ex->getCode(), $ex); |
39
|
|
|
} |
40
|
|
|
// @codeCoverageIgnoreEnd |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
abstract public function explosion(string $input): array; |
44
|
|
|
|
45
|
|
|
abstract public function filterEmptyLines(string $input): bool; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string[] $path |
49
|
|
|
* @param array<int, array<int, string|int>> $lines |
50
|
|
|
* @throws AuthException |
51
|
|
|
*/ |
52
|
5 |
|
protected function saveFile(array $path, array $lines): void |
53
|
|
|
{ |
54
|
|
|
try { |
55
|
5 |
|
$content = implode(IFile::CRLF, array_map([$this, 'implosion'], $lines)) . IFile::CRLF; |
56
|
5 |
|
$pt = Stuff::arrayToPath($path); |
57
|
5 |
|
$result = @file_put_contents($pt, $content); |
58
|
5 |
|
if (false === $result) { |
59
|
5 |
|
throw new AuthException($this->getAuLang()->kauPassFileNotSave($pt)); |
60
|
|
|
} |
61
|
1 |
|
} catch (PathsException $ex) { |
62
|
|
|
// @codeCoverageIgnoreStart |
63
|
|
|
throw new AuthException($ex->getMessage(), $ex->getCode(), $ex); |
64
|
|
|
} |
65
|
|
|
// @codeCoverageIgnoreEnd |
66
|
5 |
|
} |
67
|
|
|
|
68
|
|
|
abstract public function implosion(array $input): string; |
69
|
|
|
} |
70
|
|
|
|