1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_files\Access; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_files\FilesException; |
7
|
|
|
use kalanis\kw_files\Interfaces; |
8
|
|
|
use kalanis\kw_files\Processing; |
9
|
|
|
use kalanis\kw_files\Traits\TLang; |
10
|
|
|
use kalanis\kw_paths\PathsException; |
11
|
|
|
use kalanis\kw_storage\Interfaces\IStorage; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Factory |
16
|
|
|
* @package kalanis\kw_files\Access |
17
|
|
|
* Create Composite access to storage |
18
|
|
|
*/ |
19
|
|
|
class Factory |
20
|
|
|
{ |
21
|
|
|
use TLang; |
22
|
|
|
|
23
|
22 |
|
public function __construct(?Interfaces\IFLTranslations $lang = null) |
24
|
|
|
{ |
25
|
22 |
|
$this->setLang($lang); |
26
|
22 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string|array<string|int, string|int|float|bool|object>|object $param |
30
|
|
|
* @throws PathsException |
31
|
|
|
* @throws FilesException |
32
|
|
|
* @return CompositeAdapter |
33
|
|
|
*/ |
34
|
22 |
|
public function getClass($param): CompositeAdapter |
35
|
|
|
{ |
36
|
22 |
|
if (is_string($param)) { |
37
|
2 |
|
return new CompositeAdapter( |
38
|
2 |
|
new Processing\Volume\ProcessNode($param, $this->lang), |
39
|
2 |
|
new Processing\Volume\ProcessDir($param, $this->lang), |
40
|
2 |
|
new Processing\Volume\ProcessFile($param, $this->lang) |
41
|
|
|
); |
42
|
|
|
|
43
|
20 |
|
} elseif (is_array($param)) { |
44
|
10 |
|
if (isset($param['path']) && is_string($param['path'])) { |
45
|
1 |
|
return new CompositeAdapter( |
46
|
1 |
|
new Processing\Volume\ProcessNode($param['path'], $this->lang), |
47
|
1 |
|
new Processing\Volume\ProcessDir($param['path'], $this->lang), |
48
|
1 |
|
new Processing\Volume\ProcessFile($param['path'], $this->lang) |
49
|
|
|
); |
50
|
|
|
|
51
|
9 |
|
} elseif (isset($param['source']) && is_string($param['source'])) { |
52
|
1 |
|
return new CompositeAdapter( |
53
|
1 |
|
new Processing\Volume\ProcessNode($param['source'], $this->lang), |
54
|
1 |
|
new Processing\Volume\ProcessDir($param['source'], $this->lang), |
55
|
1 |
|
new Processing\Volume\ProcessFile($param['source'], $this->lang) |
56
|
|
|
); |
57
|
|
|
|
58
|
8 |
|
} elseif (isset($param['source']) && is_object($param['source']) && ($param['source'] instanceof IStorage)) { |
59
|
1 |
|
return new CompositeAdapter( |
60
|
1 |
|
new Processing\Storage\ProcessNode($param['source'], $this->lang), |
61
|
1 |
|
new Processing\Storage\ProcessDir($param['source'], $this->lang), |
62
|
8 |
|
new Processing\Storage\ProcessFile($param['source'], $this->lang) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
10 |
|
} elseif (is_object($param)) { |
67
|
7 |
|
if ($param instanceof IStorage) { |
68
|
6 |
|
return new CompositeAdapter( |
69
|
6 |
|
new Processing\Storage\ProcessNode($param, $this->lang), |
70
|
6 |
|
new Processing\Storage\ProcessDir($param, $this->lang), |
71
|
6 |
|
new Processing\Storage\ProcessFile($param, $this->lang) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
11 |
|
throw new FilesException($this->getLang()->flNoAvailableClasses()); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|