1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Serializer bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\SerializerBundle\DependencyInjection\Compiler; |
13
|
|
|
|
14
|
|
|
use Ivory\Serializer\Mapping\Factory\CacheClassMetadataFactory; |
15
|
|
|
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass; |
16
|
|
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter; |
17
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
20
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author GeLo <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class RegisterCachePoolPass implements CompilerPassInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
234 |
|
public function process(ContainerBuilder $container) |
31
|
|
|
{ |
32
|
234 |
|
if (!$container->hasDefinition($classMetadataFactoryService = 'ivory.serializer.mapping.factory')) { |
33
|
198 |
|
return; |
34
|
|
|
} |
35
|
|
|
|
36
|
36 |
|
$classMetadataFactory = $container->getDefinition($classMetadataFactoryService); |
37
|
|
|
|
38
|
36 |
|
if ($classMetadataFactory->getClass() !== CacheClassMetadataFactory::class) { |
39
|
36 |
|
return; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$cache = (string) $classMetadataFactory->getArgument(1); |
43
|
|
|
|
44
|
|
|
if (class_exists(CachePoolPass::class) || $container->hasDefinition($cache)) { |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$cachePath = $container->getParameter('kernel.cache_dir').'/ivory-serializer'; |
49
|
|
|
|
50
|
|
|
$container->setDefinition( |
51
|
|
|
$cache = 'ivory.serializer.cache', |
52
|
|
|
new Definition(FilesystemAdapter::class, ['', 0, $cachePath]) |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$classMetadataFactory->replaceArgument(1, $cachePool = new Reference($cache)); |
56
|
|
|
|
57
|
|
|
$container |
58
|
|
|
->getDefinition('ivory.serializer.cache_warmer') |
59
|
|
|
->replaceArgument(2, $cachePool); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|