1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_files\Processing\Storage\Files; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_files\FilesException; |
7
|
|
|
use kalanis\kw_files\Interfaces\IFLTranslations; |
8
|
|
|
use kalanis\kw_storage\Interfaces\IStorage; |
9
|
|
|
use kalanis\kw_storage\StorageException; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Basic |
14
|
|
|
* @package kalanis\kw_files\Processing\Storage\Files |
15
|
|
|
* Process files via lookup |
16
|
|
|
*/ |
17
|
|
|
class Basic extends AFiles |
18
|
|
|
{ |
19
|
18 |
|
public function __construct(IStorage $storage, ?IFLTranslations $lang = null) |
20
|
|
|
{ |
21
|
18 |
|
$this->storage = $storage; |
22
|
18 |
|
$this->setLang($lang); |
23
|
18 |
|
} |
24
|
|
|
|
25
|
3 |
|
public function copyFile(array $source, array $dest): bool |
26
|
|
|
{ |
27
|
3 |
|
$src = $this->getStorageSeparator() . $this->filledName($this->compactName($source, $this->getStorageSeparator())); |
28
|
3 |
|
$dst = $this->getStorageSeparator() . $this->filledName($this->compactName($dest, $this->getStorageSeparator())); |
29
|
|
|
try { |
30
|
3 |
|
return $this->storage->write($dst, $this->storage->read($src)); |
31
|
2 |
|
} catch (StorageException $ex) { |
32
|
2 |
|
throw new FilesException($this->getLang()->flCannotCopyFile($src, $dst), $ex->getCode(), $ex); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
2 |
|
public function moveFile(array $source, array $dest): bool |
37
|
|
|
{ |
38
|
2 |
|
$v1 = $this->copyFile($source, $dest); |
39
|
1 |
|
$v2 = $this->deleteFile($source); |
40
|
1 |
|
return $v1 && $v2; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return string |
45
|
|
|
* @codeCoverageIgnore only when path fails |
46
|
|
|
*/ |
47
|
|
|
protected function noDirectoryDelimiterSet(): string |
48
|
|
|
{ |
49
|
|
|
return $this->getLang()->flNoDirectoryDelimiterSet(); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|