Completed
Pull Request — 2.x (#212)
by
unknown
09:32
created

TwigTemplateRecorderInjector::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
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;
17
18
/**
19
 * @internal
20
 *
21
 * Ugly hack to run this code on twig initialization
22
 *
23
 * NEXT_MAJOR: remove
24
 */
25
final class TwigTemplateRecorderInjector extends Twig_Extension
26
{
27
    public function __construct(Twig_Environment $twig, Recorder $recorder)
28
    {
29
        $baseTemplateClass = $twig->getBaseTemplateClass();
30
31
        if (empty($baseTemplateClass)) {
32
            return;
33
        }
34
35
        if (method_exists($baseTemplateClass, 'attachRecorder')) {
36
            call_user_func([$baseTemplateClass, 'attachRecorder'], $recorder);
37
        }
38
    }
39
}
40