TemplateLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php namespace Wn\Generators\Template;
2
3
use Illuminate\Filesystem\Filesystem;
4
use Wn\Generators\Exceptions\TemplateException;
5
use Wn\Generators\Template\Template;
6
7
8
class TemplateLoader {
9
	
10
	protected $fs;
11
12
	protected $loaded;
13
14
	public function __construct(Filesystem $fs)
15
	{
16
		$this->fs = $fs;
17
		$this->loaded = [];
18
	}
19
20
	public function load($name)
21
	{
22
		if(! isset($this->loaded[$name])){
23
			$path = __DIR__ . "/../../templates/{$name}.wnt";
24
			try {
25
				$this->loaded[$name] = $this->fs->get($path);
26
			} catch(\Exception $e) {
27
				throw new TemplateException("Unable to read the file '{$path}'");
28
			}
29
		}
30
		return new Template($this, $this->loaded[$name]);
31
	}
32
33
}
34