TwigCacheRuntimeLoader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
dl 0
loc 20
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 7 2
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <[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
declare(strict_types=1);
13
14
namespace Cecil\Renderer;
15
16
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
17
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
18
use Twig\Extra\Cache\CacheRuntime;
19
use Twig\RuntimeLoader\RuntimeLoaderInterface;
20
21
/**
22
 * TwigCacheRuntimeLoader class.
23
 *
24
 * This class implements the RuntimeLoaderInterface to provide a CacheRuntime instance
25
 * for Twig, using a FilesystemAdapter for caching.
26
 */
27
class TwigCacheRuntimeLoader implements RuntimeLoaderInterface
28
{
29
    /**
30
     * Directory where cache files are stored.
31
     * @var string
32
     */
33
    protected string $cacheDir;
34
35
    public function __construct(string $cacheDir)
36
    {
37
        $this->cacheDir = $cacheDir;
38
    }
39
40
    public function load(string $class)
41
    {
42
        if (CacheRuntime::class === $class) {
43
            return new CacheRuntime(new TagAwareAdapter(new FilesystemAdapter(namespace: '_fragments', directory: $this->cacheDir)));
44
        }
45
46
        return null;
47
    }
48
}
49