Completed
Pull Request — 2.x (#212)
by
unknown
04:21
created

TwigTemplateRecorderInjector::initRuntime()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[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
namespace Sonata\CacheBundle\Cache;
13
14
use Sonata\Cache\Invalidation\Recorder;
15
use Twig\Environment;
16
use Twig\Extension\AbstractExtension;
17
use Twig\Extension\InitRuntimeInterface;
18
19
/**
20
 * @internal
21
 *
22
 * NEXT_MAJOR: remove
23
 */
24
final class TwigTemplateRecorderInjector extends AbstractExtension implements InitRuntimeInterface
25
{
26
    /**
27
     * @var Recorder
28
     */
29
    private $recorder;
30
31
    public function __construct(Recorder $recorder)
32
    {
33
        $this->recorder = $recorder;
34
    }
35
36
    public function initRuntime(Environment $environment)
37
    {
38
        $baseTemplateClass = $environment->getBaseTemplateClass();
39
40
        if (empty($baseTemplateClass)) {
41
            return;
42
        }
43
44
        if (method_exists($baseTemplateClass, 'attachRecorder')) {
45
            call_user_func([$baseTemplateClass, 'attachRecorder'], $this->recorder);
46
        }
47
    }
48
}
49