1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Bootstrappers\Assets; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Assets\CacheManager\Dummy as DummyCacheManager; |
8
|
|
|
use AbterPhp\Framework\Assets\CacheManager\Flysystem as FlysystemCacheManager; |
9
|
|
|
use AbterPhp\Framework\Assets\CacheManager\ICacheManager; |
10
|
|
|
use AbterPhp\Framework\Constant\Env; |
11
|
|
|
use League\Flysystem\Adapter\Local; |
12
|
|
|
use League\Flysystem\Filesystem; |
13
|
|
|
use Opulence\Environments\Environment; |
14
|
|
|
use Opulence\Ioc\Bootstrappers\Bootstrapper; |
15
|
|
|
use Opulence\Ioc\Bootstrappers\ILazyBootstrapper; |
16
|
|
|
use Opulence\Ioc\IContainer; |
17
|
|
|
|
18
|
|
|
class CacheManagerBootstrapper extends Bootstrapper implements ILazyBootstrapper |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @return array |
22
|
|
|
*/ |
23
|
|
|
public function getBindings(): array |
24
|
|
|
{ |
25
|
|
|
return [ |
26
|
|
|
DummyCacheManager::class, |
27
|
|
|
FlysystemCacheManager::class, |
28
|
|
|
ICacheManager::class, |
29
|
|
|
]; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param IContainer $container |
34
|
|
|
*/ |
35
|
|
|
public function registerBindings(IContainer $container) |
36
|
|
|
{ |
37
|
|
|
if (Environment::getVar(Env::ENV_NAME) === Environment::DEVELOPMENT) { |
38
|
|
|
$cacheManager = new DummyCacheManager(); |
39
|
|
|
} else { |
40
|
|
|
$cacheManager = new FlysystemCacheManager(); |
41
|
|
|
|
42
|
|
|
$this->registerCachePaths($cacheManager); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$container->bindInstance(ICacheManager::class, $cacheManager); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param ICacheManager $cacheManager |
50
|
|
|
*/ |
51
|
|
|
private function registerCachePaths(ICacheManager $cacheManager) |
52
|
|
|
{ |
53
|
|
|
$dirPublic = rtrim(getenv(Env::DIR_PUBLIC), DIRECTORY_SEPARATOR); |
54
|
|
|
|
55
|
|
|
$cacheManager->registerFilesystem(new Filesystem(new Local($dirPublic))); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|