This commit is contained in:
Fabien Potencier
2019-04-03 16:03:21 +02:00
parent 31912ab74d
commit c844cdbe64
5 changed files with 17 additions and 18 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
* 2.8.0 (2019-XX-XX)
* add "column" filter
* added the "column" filter
* 2.7.4 (2019-03-23)
+2 -2
View File
@@ -13,6 +13,7 @@
namespace Twig;
use Twig\Error\SyntaxError;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\AssignNameExpression;
use Twig\Node\Expression\Binary\ConcatBinary;
@@ -23,12 +24,11 @@ use Twig\Node\Expression\GetAttrExpression;
use Twig\Node\Expression\MethodCallExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\ParentExpression;
use Twig\Node\Expression\TestExpression;
use Twig\Node\Expression\Unary\NegUnary;
use Twig\Node\Expression\Unary\NotUnary;
use Twig\Node\Expression\Unary\PosUnary;
use Twig\Node\Node;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\TestExpression;
/**
* Parses expressions.
+12 -13
View File
@@ -1319,11 +1319,11 @@ function twig_to_array($seq, $preserveKeys = true)
return iterator_to_array($seq, $preserveKeys);
}
if (!is_array($seq)) {
if (!\is_array($seq)) {
return (array) $seq;
}
if(!$preserveKeys) {
if (!$preserveKeys) {
return array_values($seq);
}
@@ -1484,7 +1484,7 @@ function twig_array_batch($items, $size, $fill = null, $preserveKeys = true)
if (null !== $fill && $result) {
$last = \count($result) - 1;
if ($fillCount = $size - \count($result[$last])) {
for ($i = 0; $i < $fillCount; $i++) {
for ($i = 0; $i < $fillCount; ++$i) {
$result[$last][] = $fill;
}
}
@@ -1687,7 +1687,7 @@ function twig_get_attribute(Environment $env, Source $source, $object, $item, ar
}
/**
* Return the values from a single column in the input array.
* Returns the values from a single column in the input array.
*
* <pre>
* {% set items = [{ 'fruit' : 'apple'}, {'fruit' : 'orange' }] %}
@@ -1697,20 +1697,19 @@ function twig_get_attribute(Environment $env, Source $source, $object, $item, ar
* {# fruits now contains ['apple', 'orange'] #}
* </pre>
*
* @param array|Traversable $arr An array
* @param mixed $column_key The column key
* @param array|Traversable $array An array
* @param mixed $name The column name
*
* @return array The array of values
*/
function twig_array_column($arr, $column_key)
function twig_array_column($array, $name): array
{
if ($arr instanceof Traversable) {
$arr = \iterator_to_array($arr);
} elseif (!\is_array($arr)) {
throw new RuntimeError(sprintf('The column filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr)));
if ($array instanceof Traversable) {
$array = iterator_to_array($array);
} elseif (!\is_array($array)) {
throw new RuntimeError(sprintf('The column filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($array)));
}
return \array_column($arr, $column_key);
return array_column($array, $name);
}
}
+1 -1
View File
@@ -257,7 +257,7 @@ abstract class CallExpression extends AbstractExpression
$argument = end($parameters);
if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) {
array_pop($parameters);
} else if ($argument && $argument->isVariadic()) {
} elseif ($argument && $argument->isVariadic()) {
array_pop($parameters);
$isPhpVariadic = true;
} else {
+1 -1
View File
@@ -310,7 +310,7 @@ abstract class Template
}
if ($template === $this->getTemplateName()) {
$class = get_class($this);
$class = \get_class($this);
if (false !== $pos = strrpos($class, '___', -1)) {
$class = substr($class, 0, $pos);
}