| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 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 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 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 |
|
|---|