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