Development

/branches/2.0/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php

You must first sign up to be able to contribute.

root/branches/2.0/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php

Revision 32457, 1.9 kB (checked in by fabien, 2 years ago)

Merge branch 'master' of git://github.com/symfony/symfony

Line 
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace SymfonyWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0BundleWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0FrameworkBundleWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0TemplatingWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0Loader;
13
14 use SymfonyWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0ComponentWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0ConfigWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0FileLocatorInterface;
15 use SymfonyWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0ComponentWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0TemplatingWarning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0TemplateReferenceInterface;
16
17 /**
18  * TemplateLocator locates templates in bundles.
19  *
20  * @author Fabien Potencier <fabien@symfony.com>
21  */
22 class TemplateLocator implements FileLocatorInterface
23 {
24     protected $locator;
25     protected $path;
26     protected $cache;
27
28     /**
29      * Constructor.
30      *
31      * @param FileLocatorInterface $locator A FileLocatorInterface instance
32      * @param string               $path    A global fallback path
33      */
34     public function __construct(FileLocatorInterface $locator, $path)
35     {
36         $this->locator = $locator;
37         $this->path = $path;
38         $this->cache = array();
39     }
40
41     /**
42      * Returns a full path for a given file.
43      *
44      * @param TemplateReferenceInterface    $template     A template
45      * @param string                        $currentPath  Unused
46      * @param Boolean                       $first        Unused
47      *
48      * @return string The full path for the file
49      *
50      * @throws \InvalidArgumentException When file is not found
51      */
52     public function locate($template, $currentPath = null, $first = true)
53     {
54         $key = $template->getSignature();
55
56         if (isset($this->cache[$key])) {
57             return $this->cache[$key];
58         }
59
60         try {
61             return $this->cache[$key] = $this->locator->locate($template->getPath(), $this->path);
62         } catch (Warning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0InvalidArgumentException $e) {
63             throw new Warning: Unexpected character in input:  '\' (ASCII=92) state=1 in Unknown on line 0InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template->getPath(), $this->path), 0, $e);
64         }
65     }
66 }
67
Note: See TracBrowser for help on using the browser.