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

TwigTemplateRecorderInjector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A initRuntime() 0 12 3
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