upgrade twig library

This commit is contained in:
Michael Foster 2013-09-19 16:08:25 +10:00
parent 01857d176a
commit 9c48084f3b
163 changed files with 275 additions and 94 deletions

22
inc/lib/Twig/Extension/Core.php Normal file → Executable file
View file

@ -348,7 +348,7 @@ function twig_random(Twig_Environment $env, $values = null)
return $values < 0 ? mt_rand($values, 0) : mt_rand(0, $values);
}
if ($values instanceof Traversable) {
if (is_object($values) && $values instanceof Traversable) {
$values = iterator_to_array($values);
} elseif (is_string($values)) {
if ('' === $values) {
@ -620,7 +620,7 @@ function twig_array_merge($arr1, $arr2)
*/
function twig_slice(Twig_Environment $env, $item, $start, $length = null, $preserveKeys = false)
{
if ($item instanceof Traversable) {
if (is_object($item) && $item instanceof Traversable) {
$item = iterator_to_array($item, false);
}
@ -687,7 +687,7 @@ function twig_last(Twig_Environment $env, $item)
*/
function twig_join_filter($value, $glue = '')
{
if ($value instanceof Traversable) {
if (is_object($value) && $value instanceof Traversable) {
$value = iterator_to_array($value, false);
}
@ -829,7 +829,7 @@ function twig_in_filter($value, $compare)
}
return false !== strpos($compare, (string) $value);
} elseif ($compare instanceof Traversable) {
} elseif (is_object($compare) && $compare instanceof Traversable) {
return in_array($value, iterator_to_array($compare, false), is_object($value));
}
@ -1329,13 +1329,13 @@ function twig_constant($constant, $object = null)
*
* @param array $items An array of items
* @param integer $size The size of the batch
* @param string $fill A string to fill missing items
* @param mixed $fill A value used to fill missing items
*
* @return array
*/
function twig_array_batch($items, $size, $fill = null)
{
if ($items instanceof Traversable) {
if (is_object($items) && $items instanceof Traversable) {
$items = iterator_to_array($items, false);
}
@ -1345,10 +1345,12 @@ function twig_array_batch($items, $size, $fill = null)
if (null !== $fill) {
$last = count($result) - 1;
$result[$last] = array_merge(
$result[$last],
array_fill(0, $size - count($result[$last]), $fill)
);
if ($fillCount = $size - count($result[$last])) {
$result[$last] = array_merge(
$result[$last],
array_fill(0, $fillCount, $fill)
);
}
}
return $result;

0
inc/lib/Twig/Extension/Debug.php Normal file → Executable file
View file

0
inc/lib/Twig/Extension/Escaper.php Normal file → Executable file
View file

0
inc/lib/Twig/Extension/Optimizer.php Normal file → Executable file
View file

0
inc/lib/Twig/Extension/Sandbox.php Normal file → Executable file
View file

0
inc/lib/Twig/Extension/Staging.php Normal file → Executable file
View file

12
inc/lib/Twig/Extension/StringLoader.php Normal file → Executable file
View file

@ -43,16 +43,16 @@ class Twig_Extension_StringLoader extends Twig_Extension
*/
function twig_template_from_string(Twig_Environment $env, $template)
{
static $loader;
$name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false));
if (null === $loader) {
$loader = new Twig_Loader_String();
}
$loader = new Twig_Loader_Chain(array(
new Twig_Loader_Array(array($name => $template)),
$current = $env->getLoader(),
));
$current = $env->getLoader();
$env->setLoader($loader);
try {
$template = $env->loadTemplate($template);
$template = $env->loadTemplate($name);
} catch (Exception $e) {
$env->setLoader($current);