|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the BEAR.Package package. |
|
4
|
|
|
* |
|
5
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace BEAR\Package\Context; |
|
8
|
|
|
|
|
9
|
|
|
use BEAR\Package\Context\Provider\FilesystemCacheProvider; |
|
10
|
|
|
use BEAR\RepositoryModule\Annotation\Storage; |
|
11
|
|
|
use BEAR\Resource\Annotation\LogicCache; |
|
12
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
|
13
|
|
|
use Doctrine\Common\Annotations\CachedReader; |
|
14
|
|
|
use Doctrine\Common\Annotations\Reader; |
|
15
|
|
|
use Doctrine\Common\Cache\ApcuCache; |
|
16
|
|
|
use Doctrine\Common\Cache\Cache; |
|
17
|
|
|
use Doctrine\Common\Cache\CacheProvider; |
|
18
|
|
|
use Ray\Di\AbstractModule; |
|
19
|
|
|
use Ray\Di\Scope; |
|
20
|
|
|
|
|
21
|
|
|
class ProdModule extends AbstractModule |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
1 |
|
protected function configure() |
|
27
|
|
|
{ |
|
28
|
1 |
|
if (function_exists('apcu_fetch') && class_exists(ApcuCache::class)) { |
|
29
|
|
|
$this->installApcuCache(ApcuCache::class); |
|
30
|
|
|
|
|
31
|
|
|
return; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
$this->installFileCache(); |
|
35
|
1 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
private function installApcuCache($apcClass) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->bind(Cache::class)->to($apcClass)->in(Scope::SINGLETON); |
|
40
|
|
|
$this->bind(Reader::class)->toConstructor( |
|
41
|
|
|
CachedReader::class, |
|
42
|
|
|
'reader=annotation_reader' |
|
43
|
|
|
); |
|
44
|
|
|
$this->bind(Reader::class)->annotatedWith('annotation_reader')->to(AnnotationReader::class); |
|
45
|
|
|
$this->bind(CacheProvider::class)->annotatedWith(Storage::class)->to($apcClass)->in(Scope::SINGLETON); |
|
46
|
|
|
$this->bind(Cache::class)->annotatedWith(LogicCache::class)->to($apcClass)->in(Scope::SINGLETON); |
|
47
|
|
|
$this->bind(Cache::class)->annotatedWith(Storage::class)->to($apcClass)->in(Scope::SINGLETON); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
private function installFileCache() |
|
51
|
|
|
{ |
|
52
|
1 |
|
$this->bind(Cache::class)->toProvider(FilesystemCacheProvider::class)->in(Scope::SINGLETON); |
|
53
|
1 |
|
$this->bind(Reader::class)->toConstructor( |
|
54
|
1 |
|
CachedReader::class, |
|
55
|
|
|
'reader=annotation_reader' |
|
56
|
1 |
|
); |
|
57
|
1 |
|
$this->bind(Reader::class)->annotatedWith('annotation_reader')->to(AnnotationReader::class); |
|
58
|
1 |
|
$this->bind(CacheProvider::class)->annotatedWith(Storage::class)->toProvider(FilesystemCacheProvider::class)->in(Scope::SINGLETON); |
|
59
|
1 |
|
$this->bind(Cache::class)->annotatedWith(LogicCache::class)->toProvider(FilesystemCacheProvider::class)->in(Scope::SINGLETON); |
|
60
|
1 |
|
$this->bind(Cache::class)->annotatedWith(Storage::class)->toProvider(FilesystemCacheProvider::class)->in(Scope::SINGLETON); |
|
61
|
1 |
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|