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\CacheWarmer; |
13
|
|
|
|
14
|
|
|
use Ivory\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; |
15
|
|
|
use Ivory\Serializer\Mapping\Loader\ClassMetadataLoaderInterface; |
16
|
|
|
use Ivory\Serializer\Mapping\Loader\MappedClassMetadataLoaderInterface; |
17
|
|
|
use Psr\Cache\CacheItemPoolInterface; |
18
|
|
|
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author GeLo <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class SerializerCacheWarmer implements CacheWarmerInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var ClassMetadataFactoryInterface |
27
|
|
|
*/ |
28
|
|
|
private $factory; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var ClassMetadataLoaderInterface |
32
|
|
|
*/ |
33
|
|
|
private $loader; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var CacheItemPoolInterface |
37
|
|
|
*/ |
38
|
|
|
private $pool; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ClassMetadataFactoryInterface $factory |
42
|
|
|
* @param ClassMetadataLoaderInterface $loader |
43
|
|
|
* @param CacheItemPoolInterface $pool |
44
|
|
|
*/ |
45
|
36 |
|
public function __construct( |
46
|
|
|
ClassMetadataFactoryInterface $factory, |
47
|
|
|
ClassMetadataLoaderInterface $loader, |
48
|
|
|
CacheItemPoolInterface $pool |
49
|
|
|
) { |
50
|
36 |
|
$this->factory = $factory; |
51
|
36 |
|
$this->loader = $loader; |
52
|
36 |
|
$this->pool = $pool; |
53
|
36 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
18 |
|
public function warmUp($cacheDir) |
59
|
|
|
{ |
60
|
18 |
|
if (!$this->loader instanceof MappedClassMetadataLoaderInterface) { |
61
|
9 |
|
return; |
62
|
|
|
} |
63
|
|
|
|
64
|
9 |
|
foreach ($this->loader->getMappedClasses() as $class) { |
65
|
9 |
|
$this->factory->getClassMetadata($class); |
66
|
7 |
|
} |
67
|
|
|
|
68
|
9 |
|
$this->pool->commit(); |
69
|
9 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
9 |
|
public function isOptional() |
75
|
|
|
{ |
76
|
9 |
|
return true; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|