|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\UploadPerPartes\Target\Local\FinalStorage\Storage; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\kw_files\Access\CompositeAdapter; |
|
7
|
|
|
use kalanis\kw_paths\ArrayPath; |
|
8
|
|
|
use kalanis\kw_paths\PathsException; |
|
9
|
|
|
use kalanis\kw_storage\Interfaces\IStorage; |
|
10
|
|
|
use kalanis\UploadPerPartes\Interfaces\IFinalStorage; |
|
11
|
|
|
use kalanis\UploadPerPartes\Traits\TLangInit; |
|
12
|
|
|
use kalanis\UploadPerPartes\Uploader\Config; |
|
13
|
|
|
use kalanis\UploadPerPartes\UploadException; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class Factory |
|
18
|
|
|
* @package kalanis\UploadPerPartes\Target\Local\FinalStorage\Storage |
|
19
|
|
|
* Content data storage - Factory to get where to store main data |
|
20
|
|
|
*/ |
|
21
|
|
|
class Factory |
|
22
|
|
|
{ |
|
23
|
|
|
use TLangInit; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param Config $config |
|
27
|
|
|
* @throws UploadException |
|
28
|
|
|
* @return IFinalStorage |
|
29
|
|
|
*/ |
|
30
|
|
|
public function getStorage(Config $config): IFinalStorage |
|
31
|
|
|
{ |
|
32
|
|
|
if ($config->finalStorage instanceof IFinalStorage) { |
|
33
|
|
|
return $config->finalStorage; |
|
34
|
|
|
} |
|
35
|
|
|
if ($config->finalStorage instanceof IStorage) { |
|
36
|
|
|
return new Storage($config->finalStorage, $config->targetDir, $this->getUppLang()); |
|
37
|
|
|
} |
|
38
|
|
|
if ($config->finalStorage instanceof CompositeAdapter) { |
|
39
|
|
|
try { |
|
40
|
|
|
$ap = new ArrayPath(); |
|
41
|
|
|
return new Files($config->finalStorage, $ap->setString($config->targetDir)->getArray(), $ap, $this->getUppLang()); |
|
42
|
|
|
// @codeCoverageIgnoreStart |
|
43
|
|
|
} catch (PathsException $ex) { |
|
44
|
|
|
throw new UploadException($ex->getMessage(), $ex->getCode(), $ex); |
|
45
|
|
|
} |
|
46
|
|
|
// @codeCoverageIgnoreEnd |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
switch ($config->finalStorage) { |
|
50
|
|
|
case 'volume': |
|
51
|
|
|
return new Volume($config->targetDir, $this->getUppLang()); |
|
52
|
|
|
default: |
|
53
|
|
|
if (is_string($config->finalStorage)) { |
|
54
|
|
|
return new Volume($config->finalStorage, $this->getUppLang()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
throw new UploadException($this->getUppLang()->uppFinalStorageNotSet()); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|