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
|
27 |
|
public function getStorage(Config $config): IDrivingFile |
38
|
|
|
{ |
39
|
27 |
|
if ($config->drivingFileStorage instanceof IDrivingFile) { |
40
|
1 |
|
return $config->drivingFileStorage; |
41
|
|
|
} |
42
|
26 |
|
if ($config->drivingFileStorage instanceof IStorage) { |
43
|
19 |
|
return new Storage($config->drivingFileStorage, $config->tempDir, $this->getUppLang()); |
44
|
|
|
} |
45
|
7 |
|
if ($config->drivingFileStorage instanceof CompositeAdapter) { |
46
|
|
|
try { |
47
|
1 |
|
$ap = new ArrayPath(); |
48
|
1 |
|
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
|
6 |
|
switch ($config->drivingFileStorage) { |
57
|
6 |
|
case 'volume': |
58
|
5 |
|
case self::FORMAT_VOLUME: |
59
|
2 |
|
return new Volume($config->tempDir, $this->getUppLang()); |
60
|
4 |
|
case 'client': |
61
|
2 |
|
case self::FORMAT_CLIENT: |
62
|
2 |
|
return new Client($this->getUppLang()); |
63
|
|
|
default: |
64
|
2 |
|
if (is_string($config->drivingFileStorage)) { |
65
|
1 |
|
return new Volume($config->drivingFileStorage, $this->getUppLang()); |
66
|
|
|
} |
67
|
|
|
|
68
|
1 |
|
throw new UploadException($this->getUppLang()->uppDriveFileStorageNotSet()); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|