Source of file FilesystemLoader.php
Size: 2,652 Bytes - Last Modified: 2013-07-17T08:22:21+02:00
/home/theseer/Downloads/Symfony/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 | <?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; /** * 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(); } /** * 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($template); } catch (\Twig_Error_Loader $e) { $previous = $e; // for BC try { $template = $this->parser->parse($template); try { $file = $this->locator->locate($template); } catch (\InvalidArgumentException $e) { $previous = $e; } } 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; } } |