/usr/share/php/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php is in php-symfony-twig-bundle 2.3.21+dfsg-4+deb8u3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | <?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\TwigBundle\Loader;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\Templating\TemplateReferenceInterface;
/**
* FilesystemLoader extends the default Twig filesystem loader
* to work with the Symfony2 paths.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class FilesystemLoader extends \Twig_Loader_Filesystem
{
protected $locator;
protected $parser;
/**
* Constructor.
*
* @param FileLocatorInterface $locator A FileLocatorInterface instance
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
*/
public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser)
{
parent::__construct(array());
$this->locator = $locator;
$this->parser = $parser;
$this->cache = array();
}
/**
* {@inheritdoc}
*
* The name parameter might also be a TemplateReferenceInterface.
*/
public function exists($name)
{
return parent::exists((string) $name);
}
/**
* Returns the path to the template file.
*
* The file locator is used to locate the template when the naming convention
* is the symfony one (i.e. the name can be parsed).
* Otherwise the template is located using the locator from the twig library.
*
* @param string|TemplateReferenceInterface $template The template
*
* @return string The path to the template file
*
* @throws \Twig_Error_Loader if the template could not be found
*/
protected function findTemplate($template)
{
$logicalName = (string) $template;
if (isset($this->cache[$logicalName])) {
return $this->cache[$logicalName];
}
$file = null;
$previous = null;
try {
$file = parent::findTemplate($logicalName);
} catch (\Twig_Error_Loader $e) {
$previous = $e;
// for BC
try {
$template = $this->parser->parse($template);
$file = $this->locator->locate($template);
} catch (\Exception $e) {
$previous = $e;
}
}
if (false === $file || null === $file) {
throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $logicalName), -1, null, $previous);
}
return $this->cache[$logicalName] = $file;
}
}
|