TwigCacheRuntimeLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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