Completed
Pull Request — master (#1196)
by Gocha
01:45
created

DoctrineMetadataCacheWarmer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A doWarmUp() 0 9 1
1
<?php
2
3
namespace Doctrine\Bundle\DoctrineBundle\CacheWarmer;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\Mapping\ClassMetadataFactory;
7
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AbstractPhpFileCacheWarmer;
8
use Symfony\Component\Cache\Adapter\ArrayAdapter;
9
use Symfony\Component\Cache\DoctrineProvider;
10
11
class DoctrineMetadataCacheWarmer extends AbstractPhpFileCacheWarmer
12
{
13
    /**
14
     * @var EntityManagerInterface
15
     */
16
    private $entityManager;
17
18
    public function __construct(EntityManagerInterface $entityManager, string $phpArrayFile)
19
    {
20
        $this->entityManager = $entityManager;
21
22
        parent::__construct($phpArrayFile);
23
    }
24
25
    /**
26
     * @param string $cacheDir
27
     *
28
     * @return bool false if there is nothing to warm-up
29
     */
30
    protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
31
    {
32
        $metadataFactory = new ClassMetadataFactory();
33
        $metadataFactory->setEntityManager($this->entityManager);
34
        $metadataFactory->setCacheDriver(new DoctrineProvider($arrayAdapter));
35
        $metadataFactory->getAllMetadata();
36
37
        return true;
38
    }
39
}
40