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\IPassDirs; |
9
|
|
|
use kalanis\kw_storage\StorageException; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class CanDir |
14
|
|
|
* @package kalanis\kw_files\Processing\Storage\Files |
15
|
|
|
* Process files via predefined api |
16
|
|
|
*/ |
17
|
|
|
class CanDir extends AFiles |
18
|
|
|
{ |
19
|
|
|
protected IPassDirs $passStorage; |
20
|
|
|
|
21
|
13 |
|
public function __construct(IPassDirs $storage, ?IFLTranslations $lang = null) |
22
|
|
|
{ |
23
|
13 |
|
parent::__construct($storage, $lang); |
24
|
13 |
|
$this->passStorage = $storage; |
25
|
|
|
} |
26
|
|
|
|
27
|
2 |
|
public function copyFile(array $source, array $dest): bool |
28
|
|
|
{ |
29
|
2 |
|
$src = $this->getStorageSeparator() . $this->compactName($source, $this->getStorageSeparator()); |
30
|
2 |
|
$dst = $this->getStorageSeparator() . $this->compactName($dest, $this->getStorageSeparator()); |
31
|
|
|
try { |
32
|
2 |
|
return $this->passStorage->copy($src, $dst); |
33
|
1 |
|
} catch (StorageException $ex) { |
34
|
1 |
|
throw new FilesException($this->getFlLang()->flCannotCopyFile($src, $dst), $ex->getCode(), $ex); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
2 |
|
public function moveFile(array $source, array $dest): bool |
39
|
|
|
{ |
40
|
2 |
|
$src = $this->getStorageSeparator() . $this->compactName($source, $this->getStorageSeparator()); |
41
|
2 |
|
$dst = $this->getStorageSeparator() . $this->compactName($dest, $this->getStorageSeparator()); |
42
|
|
|
try { |
43
|
2 |
|
return $this->passStorage->move($src, $dst); |
44
|
1 |
|
} catch (StorageException $ex) { |
45
|
1 |
|
throw new FilesException($this->getFlLang()->flCannotMoveFile($src, $dst), $ex->getCode(), $ex); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return string |
51
|
|
|
* @codeCoverageIgnore only when path fails |
52
|
|
|
*/ |
53
|
|
|
protected function noDirectoryDelimiterSet(): string |
54
|
|
|
{ |
55
|
|
|
return $this->getFlLang()->flNoDirectoryDelimiterSet(); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|