forked from leftypol/leftypol
Twig update to latest Twig 1.x legacy as per vichan
This commit is contained in:
parent
4ecd84f81d
commit
e6c07544da
198 changed files with 6150 additions and 2506 deletions
|
@ -3,16 +3,17 @@
|
|||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2012 Fabien Potencier
|
||||
* (c) Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @final
|
||||
*/
|
||||
class Twig_Extension_StringLoader extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
|
@ -20,9 +21,6 @@ class Twig_Extension_StringLoader extends Twig_Extension
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'string_loader';
|
||||
|
@ -37,28 +35,13 @@ class Twig_Extension_StringLoader extends Twig_Extension
|
|||
* </pre>
|
||||
*
|
||||
* @param Twig_Environment $env A Twig_Environment instance
|
||||
* @param string $template A template as a string
|
||||
* @param string $template A template as a string or object implementing __toString()
|
||||
*
|
||||
* @return Twig_Template A Twig_Template instance
|
||||
* @return Twig_Template
|
||||
*/
|
||||
function twig_template_from_string(Twig_Environment $env, $template)
|
||||
{
|
||||
$name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false));
|
||||
|
||||
$loader = new Twig_Loader_Chain(array(
|
||||
new Twig_Loader_Array(array($name => $template)),
|
||||
$current = $env->getLoader(),
|
||||
));
|
||||
|
||||
$env->setLoader($loader);
|
||||
try {
|
||||
$template = $env->loadTemplate($name);
|
||||
} catch (Exception $e) {
|
||||
$env->setLoader($current);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
$env->setLoader($current);
|
||||
|
||||
return $template;
|
||||
return $env->createTemplate((string) $template);
|
||||
}
|
||||
|
||||
class_alias('Twig_Extension_StringLoader', 'Twig\Extension\StringLoaderExtension', false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue