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
|
23 |
|
public function __construct(?Interfaces\IFLTranslations $lang = null) |
24
|
|
|
{ |
25
|
23 |
|
$this->setFlLang($lang); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param mixed $param |
30
|
|
|
* @throws PathsException |
31
|
|
|
* @throws FilesException |
32
|
|
|
* @return CompositeAdapter |
33
|
|
|
*/ |
34
|
23 |
|
public function getClass($param): CompositeAdapter |
35
|
|
|
{ |
36
|
23 |
|
if (is_string($param)) { |
37
|
2 |
|
return new CompositeAdapter( |
38
|
2 |
|
new Processing\Volume\ProcessNode($param, $this->flLang), |
39
|
2 |
|
new Processing\Volume\ProcessDir($param, $this->flLang), |
40
|
2 |
|
new Processing\Volume\ProcessFile($param, $this->flLang), |
41
|
2 |
|
new Processing\Volume\ProcessFile($param, $this->flLang) |
42
|
2 |
|
); |
43
|
|
|
|
44
|
21 |
|
} elseif (is_array($param)) { |
45
|
10 |
|
if (isset($param['files'])) { |
46
|
1 |
|
return $this->getClass($param['files']); |
47
|
|
|
} |
48
|
10 |
|
if (isset($param['path']) && is_string($param['path'])) { |
49
|
1 |
|
return new CompositeAdapter( |
50
|
1 |
|
new Processing\Volume\ProcessNode($param['path'], $this->flLang), |
51
|
1 |
|
new Processing\Volume\ProcessDir($param['path'], $this->flLang), |
52
|
1 |
|
new Processing\Volume\ProcessFile($param['path'], $this->flLang), |
53
|
1 |
|
new Processing\Volume\ProcessFile($param['path'], $this->flLang) |
54
|
1 |
|
); |
55
|
|
|
|
56
|
9 |
|
} elseif (isset($param['source']) && is_string($param['source'])) { |
57
|
1 |
|
return new CompositeAdapter( |
58
|
1 |
|
new Processing\Volume\ProcessNode($param['source'], $this->flLang), |
59
|
1 |
|
new Processing\Volume\ProcessDir($param['source'], $this->flLang), |
60
|
1 |
|
new Processing\Volume\ProcessFile($param['source'], $this->flLang), |
61
|
1 |
|
new Processing\Volume\ProcessFile($param['source'], $this->flLang) |
62
|
1 |
|
); |
63
|
|
|
|
64
|
8 |
|
} elseif (isset($param['source']) && is_object($param['source']) && ($param['source'] instanceof IStorage)) { |
65
|
8 |
|
return new CompositeAdapter( |
66
|
8 |
|
new Processing\Storage\ProcessNode($param['source'], $this->flLang), |
67
|
8 |
|
new Processing\Storage\ProcessDir($param['source'], $this->flLang), |
68
|
8 |
|
new Processing\Storage\ProcessFile($param['source'], $this->flLang), |
69
|
8 |
|
new Processing\Storage\ProcessFileStream($param['source'], $this->flLang) |
70
|
8 |
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
11 |
|
} elseif (is_object($param)) { |
74
|
8 |
|
if ($param instanceof CompositeAdapter) { |
75
|
1 |
|
return $param; |
76
|
|
|
|
77
|
7 |
|
} elseif ($param instanceof IStorage) { |
78
|
6 |
|
return new CompositeAdapter( |
79
|
6 |
|
new Processing\Storage\ProcessNode($param, $this->flLang), |
80
|
6 |
|
new Processing\Storage\ProcessDir($param, $this->flLang), |
81
|
6 |
|
new Processing\Storage\ProcessFile($param, $this->flLang), |
82
|
6 |
|
new Processing\Storage\ProcessFileStream($param, $this->flLang) |
83
|
6 |
|
); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
11 |
|
throw new FilesException($this->getFlLang()->flNoAvailableClasses()); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|