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
|
|
|
/** @var IPassDirs */ |
20
|
|
|
protected $storage = null; |
21
|
|
|
|
22
|
9 |
|
public function __construct(IPassDirs $storage, ?IFLTranslations $lang = null) |
23
|
|
|
{ |
24
|
9 |
|
$this->storage = $storage; |
25
|
9 |
|
$this->setLang($lang); |
26
|
9 |
|
} |
27
|
|
|
|
28
|
2 |
|
public function copyFile(array $source, array $dest): bool |
29
|
|
|
{ |
30
|
2 |
|
$src = $this->getStorageSeparator() . $this->compactName($source, $this->getStorageSeparator()); |
31
|
2 |
|
$dst = $this->getStorageSeparator() . $this->compactName($dest, $this->getStorageSeparator()); |
32
|
|
|
try { |
33
|
2 |
|
return $this->storage->copy($src, $dst); |
34
|
1 |
|
} catch (StorageException $ex) { |
35
|
1 |
|
throw new FilesException($this->getLang()->flCannotCopyFile($src, $dst), $ex->getCode(), $ex); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
2 |
|
public function moveFile(array $source, array $dest): bool |
40
|
|
|
{ |
41
|
2 |
|
$src = $this->getStorageSeparator() . $this->compactName($source, $this->getStorageSeparator()); |
42
|
2 |
|
$dst = $this->getStorageSeparator() . $this->compactName($dest, $this->getStorageSeparator()); |
43
|
|
|
try { |
44
|
2 |
|
return $this->storage->move($src, $dst); |
45
|
1 |
|
} catch (StorageException $ex) { |
46
|
1 |
|
throw new FilesException($this->getLang()->flCannotMoveFile($src, $dst), $ex->getCode(), $ex); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string |
52
|
|
|
* @codeCoverageIgnore only when path fails |
53
|
|
|
*/ |
54
|
|
|
protected function noDirectoryDelimiterSet(): string |
55
|
|
|
{ |
56
|
|
|
return $this->getLang()->flNoDirectoryDelimiterSet(); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|