Files
Twig/test/lib/Twig_Loader_Var.php
T
fabien fd0646e4cf initial commit
git-svn-id: http://svn.twig-project.org/trunk@4 93ef8e89-cb99-4229-a87c-7fa0fa45744b
2009-10-07 21:21:11 +00:00

44 lines
1017 B
PHP

<?php
/*
* This file is part of Twig.
*
* (c) 2009 Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Loads a template from variables.
*
* @package twig
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id$
*/
class Twig_Loader_Var extends Twig_Loader
{
protected $templates;
protected $prefix;
public function __construct(array $templates, $prefix)
{
$this->prefix = $prefix;
$this->templates = array();
foreach ($templates as $name => $template)
{
$this->templates[$this->prefix.'_'.$name] = $template;
}
}
public function getSource($name)
{
if (!isset($this->templates[$this->prefix.'_'.$name]))
{
throw new LogicException(sprintf('Template "%s" is not defined.', $name));
}
return array(str_replace('%prefix%', $this->prefix.'_', $this->templates[$this->prefix.'_'.$name]), false);
}
}