summaryrefslogtreecommitdiff
path: root/src/Renderer/TwigLoader.php
blob: 1bcbbd71df947214e9c6f0faead32315e993845e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php

namespace Engelsystem\Renderer;

use Twig\Error\LoaderError as ErrorLoader;
use Twig\Loader\FilesystemLoader as FilesystemLoader;

class TwigLoader extends FilesystemLoader
{
    /**
     * @param string $name
     * @param bool   $throw
     * @return string|null
     * @throws ErrorLoader
     */
    public function findTemplate(string $name, bool $throw = true): ?string
    {
        $extension = '.twig';
        $extensionLength = mb_strlen($extension);
        if (mb_substr($name, -$extensionLength, $extensionLength) !== $extension) {
            $name .= $extension;
        }

        return parent::findTemplate($name, $throw);
    }
}