Passed
Pull Request — 2.4 (#2650)
by Han Hui
03:21
created

CachePoolClearerCacheWarmer::isOptional()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[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
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\CacheWarmer;
15
16
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
17
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
18
19
/**
20
 * Clears the cache pools when warming up the cache.
21
 *
22
 * @internal
23
 */
24
final class CachePoolClearerCacheWarmer implements CacheWarmerInterface
25
{
26
    private $poolClearer;
27
    private $pools;
28
29
    public function __construct(Psr6CacheClearer $poolClearer, array $pools = [])
30
    {
31
        $this->poolClearer = $poolClearer;
32
        $this->pools = $pools;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function warmUp($cacheDirectory): void
39
    {
40
        foreach ($this->pools as $pool) {
41
            if ($this->poolClearer->hasPool($pool)) {
42
                $this->poolClearer->clearPool($pool);
43
            }
44
        }
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function isOptional(): bool
51
    {
52
        return false;
53
    }
54
}
55