|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace WShafer\PSR11FlySystem; |
|
5
|
|
|
|
|
6
|
|
|
use Psr\Container\ContainerInterface; |
|
7
|
|
|
use WShafer\PSR11FlySystem\Adaptor\AdaptorMapper; |
|
8
|
|
|
use WShafer\PSR11FlySystem\Cache\CacheMapper; |
|
9
|
|
|
use WShafer\PSR11FlySystem\Config\MainConfig; |
|
10
|
|
|
use WShafer\PSR11FlySystem\Service\AdaptorManager; |
|
11
|
|
|
use WShafer\PSR11FlySystem\Service\CacheManager; |
|
12
|
|
|
|
|
13
|
|
|
class FlySystemManagerFactory |
|
14
|
|
|
{ |
|
15
|
|
|
protected $config; |
|
16
|
|
|
|
|
17
|
1 |
|
public function __invoke(ContainerInterface $container) |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var MainConfig $config */ |
|
20
|
1 |
|
$config = $this->getConfig($container); |
|
21
|
|
|
|
|
22
|
|
|
/** @var AdaptorManager $adaptorManager */ |
|
23
|
1 |
|
$adaptorManager = $this->getAdaptorManager($container); |
|
24
|
|
|
|
|
25
|
|
|
/** @var CacheManager $cacheManager */ |
|
26
|
1 |
|
$cacheManager = $this->getCacheManager($container); |
|
27
|
|
|
|
|
28
|
1 |
|
return new FlySystemManager($config, $adaptorManager, $cacheManager, $container); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
4 |
|
public function getConfig(ContainerInterface $container) |
|
32
|
|
|
{ |
|
33
|
4 |
|
if (!$this->config) { |
|
34
|
4 |
|
$config = $container->has('config') ? $container->get('config') : []; |
|
35
|
4 |
|
$this->config = new MainConfig($config); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
4 |
|
return $this->config; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
2 |
|
public function getAdaptorManager(ContainerInterface $container) |
|
42
|
|
|
{ |
|
43
|
|
|
/** @var MainConfig $config */ |
|
44
|
2 |
|
$config = $this->getConfig($container); |
|
45
|
|
|
|
|
46
|
|
|
/** @var AdaptorMapper $adaptorMapper */ |
|
47
|
2 |
|
$adaptorMapper = $this->getAdaptorMapper($container); |
|
48
|
|
|
|
|
49
|
2 |
|
return new AdaptorManager($config, $adaptorMapper, $container); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
3 |
|
public function getAdaptorMapper(ContainerInterface $container) |
|
53
|
|
|
{ |
|
54
|
3 |
|
return new AdaptorMapper($container); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
2 |
|
public function getCacheManager(ContainerInterface $container) |
|
58
|
|
|
{ |
|
59
|
|
|
/** @var MainConfig $config */ |
|
60
|
2 |
|
$config = $this->getConfig($container); |
|
61
|
|
|
|
|
62
|
|
|
/** @var CacheMapper $cacheMapper */ |
|
63
|
2 |
|
$cacheMapper = $this->getCacheMapper($container); |
|
64
|
|
|
|
|
65
|
2 |
|
return new CacheManager($config, $cacheMapper, $container); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
3 |
|
public function getCacheMapper(ContainerInterface $container) |
|
69
|
|
|
{ |
|
70
|
3 |
|
return new CacheMapper($container); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|