Passed
Push — cache ( c9eef1...19442f )
by Arnaud
03:52
created

TwigCacheRuntimeLoader::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
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
class TwigCacheRuntimeLoader implements RuntimeLoaderInterface
22
{
23
    protected string $cacheDir;
24
25
    public function __construct(string $cacheDir)
26
    {
27
        $this->cacheDir = $cacheDir;
28
    }
29
30
    public function load(string $class)
31
    {
32
        if (CacheRuntime::class === $class) {
33
            return new CacheRuntime(new TagAwareAdapter(new FilesystemAdapter(namespace: '_fragments', directory: $this->cacheDir)));
34
        }
35
36
        return null;
37
    }
38
}
39