Passed
Branch master (3e058b)
by Allan
02:59
created

TemplateLoader::load()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 18
rs 9.9666
c 0
b 0
f 0
cc 4
nc 6
nop 1
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerChangelogs\Loaders;
7
8
class TemplateLoader implements \Mustache_Loader
9
{
10
    /**
11
     * @var array
12
     */
13
    private $content = array();
14
15
    /**
16
     * @var \Closure
17
     */
18
    private $pathResolver;
19
20
    public function __construct(
21
        \Closure $pathResolver = null
22
    ) {
23
        $this->pathResolver = $pathResolver;
24
    }
25
26
    public function load($path)
27
    {
28
        if ($this->pathResolver !== null) {
29
            $resolver = $this->pathResolver;
30
            $path = $resolver($path);
31
        }
32
        
33
        if (!isset($this->content[$path])) {
34
            if (!file_exists($path)) {
35
                throw new \Exception(
36
                    sprintf('Could not find template file %s', $path)
37
                );
38
            }
39
40
            $this->content[$path] = file_get_contents($path);
41
        }
42
43
        return $this->content[$path];
44
    }
45
}
46