lumen-generators/src/Template/TemplateLoader.php

33 lines
667 B
PHP
Raw Normal View History

2015-09-23 01:49:46 +01:00
<?php namespace Wn\Generators\Template;
2015-09-23 02:39:13 +01:00
use Illuminate\Filesystem\Filesystem;
2015-09-23 01:49:46 +01:00
use Wn\Generators\Exceptions\TemplateException;
2015-09-23 02:39:13 +01:00
use Wn\Generators\Template\Template;
2015-09-23 01:49:46 +01:00
class TemplateLoader {
protected $fs;
protected $loaded;
public function __construct(Filesystem $fs)
{
$this->fs = $fs;
$this->loaded = [];
}
public function load($name)
{
if(! isset($this->loaded[$name])){
$path = __DIR__ . "/../../templates/{$name}.wnt";
try {
$this->loaded[$name] = $this->fs->get($path);
} catch(\Exception $e) {
throw new TemplateException("Unable to read the file '{$path}'");
}
}
return new Template($this, $this->loaded[$name]);
}
}