Completed
Pull Request — master (#165)
by Paul
03:21
created

FileSystemLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getFileName() 0 13 2
1
<?php
2
/**
3
 * This file is part of the PPI Framework.
4
 *
5
 * @copyright   Copyright (c) 2012 Paul Dragoonis <[email protected]>
6
 * @license     http://opensource.org/licenses/mit-license.php MIT
7
 *
8
 * @link        http://www.ppi.io
9
 */
10
11
namespace PPI\Framework\View\Mustache\Loader;
12
13
use Symfony\Component\Config\FileLocatorInterface;
14
use Symfony\Component\Templating\TemplateNameParserInterface;
15
16
/**
17
 * This engine knows how to render Mustache templates.
18
 *
19
 * @author Justin Hileman <[email protected]>
20
 */
21
class FileSystemLoader extends \Mustache_Loader_FilesystemLoader
22
{
23
    protected $locator;
24
    protected $parser;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param FileLocatorInterface        $locator A FileLocatorInterface instance
30
     * @param TemplateNameParserInterface $parser  A TemplateNameParserInterface instance
31
     */
32
    public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser)
33
    {
34
        $this->locator = $locator;
35
        $this->parser  = $parser;
36
        $this->cache   = array();
37
    }
38
39
    /**
40
     * Helper function for getting a Mustache template file name.
41
     *
42
     * @param string $name
43
     *
44
     * @return string Template file name
45
     */
46
    protected function getFileName($name)
47
    {
48
        $name = (string) $name;
49
50
        try {
51
            $template = $this->parser->parse($name);
52
            $file     = $this->locator->locate($template);
53
        } catch (\Exception $e) {
54
            throw new \InvalidArgumentException(sprintf('Unable to find template "%s".', $name));
55
        }
56
57
        return $file;
58
    }
59
}
60