|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\UploadPerPartes\Target\Local\DrivingFile\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\IDrivingFile; |
|
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\DrivingFile\Storage |
|
19
|
|
|
* Key data storage - Factory to get where to store info data |
|
20
|
|
|
*/ |
|
21
|
|
|
class Factory |
|
22
|
|
|
{ |
|
23
|
|
|
use TLangInit; |
|
24
|
|
|
|
|
25
|
|
|
public const FORMAT_VOLUME = 1; |
|
26
|
|
|
public const FORMAT_STORAGE = 2; |
|
27
|
|
|
public const FORMAT_FILES = 3; |
|
28
|
|
|
public const FORMAT_REDIS = 4; |
|
29
|
|
|
public const FORMAT_PREDIS = 5; |
|
30
|
|
|
public const FORMAT_CLIENT = 6; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param Config $config |
|
34
|
|
|
* @throws UploadException |
|
35
|
|
|
* @return IDrivingFile |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getStorage(Config $config): IDrivingFile |
|
38
|
|
|
{ |
|
39
|
|
|
if ($config->drivingFileStorage instanceof IDrivingFile) { |
|
40
|
|
|
return $config->drivingFileStorage; |
|
41
|
|
|
} |
|
42
|
|
|
if ($config->drivingFileStorage instanceof IStorage) { |
|
43
|
|
|
return new Storage($config->drivingFileStorage, $config->tempDir, $this->getUppLang()); |
|
44
|
|
|
} |
|
45
|
|
|
if ($config->drivingFileStorage instanceof CompositeAdapter) { |
|
46
|
|
|
try { |
|
47
|
|
|
$ap = new ArrayPath(); |
|
48
|
|
|
return new Files($config->drivingFileStorage, $ap->setString($config->tempDir)->getArray(), $ap, $this->getUppLang()); |
|
49
|
|
|
// @codeCoverageIgnoreStart |
|
50
|
|
|
} catch (PathsException $ex) { |
|
51
|
|
|
throw new UploadException($ex->getMessage(), $ex->getCode(), $ex); |
|
52
|
|
|
} |
|
53
|
|
|
// @codeCoverageIgnoreEnd |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
switch ($config->drivingFileStorage) { |
|
57
|
|
|
case 'volume': |
|
58
|
|
|
case self::FORMAT_VOLUME: |
|
59
|
|
|
return new Volume($config->tempDir, $this->getUppLang()); |
|
60
|
|
|
case 'client': |
|
61
|
|
|
case self::FORMAT_CLIENT: |
|
62
|
|
|
return new Client($this->getUppLang()); |
|
63
|
|
|
default: |
|
64
|
|
|
if (is_string($config->drivingFileStorage)) { |
|
65
|
|
|
return new Volume($config->drivingFileStorage, $this->getUppLang()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
throw new UploadException($this->getUppLang()->uppDriveFileStorageNotSet()); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|