Passed
Push — master ( 429b06...f0c7c5 )
by Rafael
08:46
created

DefinitionCacheWarmer::isOptional()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Cache;
12
13
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;
15
use Symfony\Component\HttpKernel\KernelEvents;
16
use Ynlo\GraphQLBundle\Definition\Registry\DefinitionRegistry;
17
18
/**
19
 * DefinitionCacheWarmer
20
 */
21
class DefinitionCacheWarmer extends CacheWarmer implements EventSubscriberInterface
22
{
23
    /**
24
     * @var DefinitionRegistry
25
     */
26
    protected $registry;
27
28
    /**
29
     * DefinitionCacheWarmer constructor.
30
     *
31
     * @param DefinitionRegistry $registry
32
     */
33
    public function __construct(DefinitionRegistry $registry)
34
    {
35
        $this->registry = $registry;
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41
    public function isOptional()
42
    {
43
        return true;
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function warmUp($cacheDir)
50
    {
51
        $this->registry->clearCache();
52
    }
53
54
    /**
55
     * warmUp the cache on request
56
     * NOTE: this behavior its switched in the YnloGraphQLExtension
57
     */
58
    public function warmUpOnEveryRequest()
59
    {
60
        $this->warmUp(null);
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66
    public static function getSubscribedEvents()
67
    {
68
        return [
69
            KernelEvents::REQUEST => 'warmUpOnEveryRequest',
70
        ];
71
    }
72
}
73