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

DoctrineMetadataCacheWarmer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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