1<?php
2/**
3 * PHPTAL templating engine
4 *
5 * PHP Version 5
6 *
7 * @category HTML
8 * @package  PHPTAL
9 * @author   Laurent Bedubourg <lbedubourg@motion-twin.com>
10 * @author   Kornel Lesiński <kornel@aardvarkmedia.co.uk>
11 * @license  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
12 * @version  SVN: $Id$
13 * @link     http://phptal.org/
14 */
15
16
17/**
18 * Finds template on disk by looking through repositories first
19 *
20 * @package PHPTAL
21 */
22class PHPTAL_FileSourceResolver implements PHPTAL_SourceResolver
23{
24    public function __construct($repositories)
25    {
26        $this->_repositories = $repositories;
27    }
28
29    public function resolve($path)
30    {
31        foreach ($this->_repositories as $repository) {
32            $file = $repository . DIRECTORY_SEPARATOR . $path;
33            if (file_exists($file)) {
34                return new PHPTAL_FileSource($file);
35            }
36        }
37
38        if (file_exists($path)) {
39            return new PHPTAL_FileSource($path);
40        }
41
42        return null;
43    }
44
45    private $_repositories;
46}
47