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

TwigTemplateRecorderInjector   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 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;
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