|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the jade/jade package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Slince <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Jade\Provider; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\Common\Annotations\CachedReader; |
|
15
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
|
16
|
|
|
use Jade\ContainerInterface; |
|
17
|
|
|
use Jade\ServiceProviderInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Sérgio Rafael Siqueira <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class AnnotationsServiceProvider implements ServiceProviderInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public function register(ContainerInterface $container) |
|
25
|
|
|
{ |
|
26
|
|
|
$container->add([ |
|
27
|
|
|
'annotations.debug' => false, |
|
28
|
|
|
'annotations.options' => [ |
|
29
|
|
|
'cache_driver' => 'array', |
|
30
|
|
|
'cache_dir' => null, |
|
31
|
|
|
] |
|
32
|
|
|
]); |
|
33
|
|
|
$container['annotation_reader'] = function () use ($container) { |
|
34
|
|
|
return new AnnotationReader(); |
|
35
|
|
|
}; |
|
36
|
|
|
|
|
37
|
|
|
$container['annotations.cached_reader.factory'] = $container->protect(function ($options) use ($container) { |
|
38
|
|
|
if (!isset($container['cache'])) { |
|
39
|
|
|
throw new \LogicException( |
|
40
|
|
|
'You must register the DoctrineCacheServiceProvider to use the AnnotationServiceProvider.' |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return $container['cache_factory']($options['cache_driver'], $options); |
|
45
|
|
|
}); |
|
46
|
|
|
|
|
47
|
|
|
$container['annotations.cached_reader'] = function () use ($container) { |
|
48
|
|
|
return new CachedReader( |
|
49
|
|
|
$container['annotation_reader'], |
|
50
|
|
|
$container['annotations.cached_reader.factory']($container['annotations.options']), |
|
51
|
|
|
$container['annotations.debug'] |
|
52
|
|
|
); |
|
53
|
|
|
}; |
|
54
|
|
|
|
|
55
|
|
|
$container['annotations'] = function () use ($container) { |
|
56
|
|
|
return $container['annotations.cached_reader']; |
|
57
|
|
|
}; |
|
58
|
|
|
} |
|
59
|
|
|
} |