Commit 617dc6e6 authored by Markus Willman's avatar Markus Willman

update Twig to 1.12.1

parent 66fca77d
......@@ -7,7 +7,7 @@ programming or templating systems used by various software making use of the MVC
#### 4.1 Twig syntax primer
Here we will quickly cover the basics of Twig syntax, however, this is not intended as a replacement of reading the Twig
[documentation](http://twig.sensiolabs.org/doc/templates.html).
[documentation](https://twig.symfony.com/doc/2.x/templates.html).
- Template variables or function calls intended to produce output on the page will be surrounded by ``{{`` and ``}}``.
- Block level tags, control flow and assignment statements (if, else, for, etc.) will be surrounded by ``{%`` and ``%}``.
......@@ -22,12 +22,12 @@ the content is replaced.
- Associative arrays and objects are accessed using the dot notation.
- Any file paths referenced in Twig templates are relative from Twig's template directories (the virtual document root
and the template directory specifically).
- String concatenation is done with the tilde (~) character.
- String concatenation is done with the tilde (\~) character.
<div class="alert alert-info" role="alert" markdown="1">
<i class="fas fa-info-circle fa-lg" title="Info:"></i>
The full Twig documentation, including complete reference of built in features, can also be found as a PDF over
[here](http://twig.sensiolabs.org/pdf/Twig.pdf).
[here](https://twig.symfony.com/pdf/2.x/Twig.pdf).
</div>
#### 4.2 Getting started
......
......@@ -5,12 +5,12 @@ predefined macros and global variables.
#### 5.1 Custom functions and filters
The backend exposes a handful of custom Twig functions and filters for templates to use. On more about Twig functions
see the [documentation](http://twig.sensiolabs.org/doc/templates.html#functions) and Twig's list of built in functions.
see the [documentation](https://twig.symfony.com/doc/2.x/templates.html#functions) and Twig's list of built in functions.
Unlike functions filters are applied to template variables using the pipe (|) character, so for example
``{{ timestamp | date_relative(now) }}`` would apply the below relative_date filter to template variable timestamp with
now as the optional argument. Multiple filters may be applied to a single variable by repeating the syntax. On more
advanced use of filters see the Twig [documentation](http://twig.sensiolabs.org/doc/templates.html#filters) and Twig's
advanced use of filters see the Twig [documentation](https://twig.symfony.com/doc/2.x/templates.html#filters) and Twig's
list of built-in filters.
......
......@@ -4,7 +4,7 @@ This directory contains files used by the template files on [dcbase.org](https:/
pull page content or copy into the final resulting pages served to the user. Although they may also
be viewed separately as "headless" versions of the documents.
The files use markdown but may be passed through [Twig](http://twig.sensiolabs.org/) for preprocessing
The files use markdown but may be passed through [Twig](https://twig.symfony.com/) for preprocessing
before they are parsed. This is determined by the actual file extension, if the *real* file extension
is .twig the contents are first rendered using Twig before being parsed as markdown. Some template
files may also additionally contain inline markdown blocks as part of the file itself.
......@@ -52,9 +52,9 @@ This website is powered by a collection of open source software, including but n
particular order).
- [Git](https://git-scm.com/) - Free and open source distributed version control system.
- [PHP](http://php.net/) - Popular general-purpose scripting language that is especially suited to web development.
- [Twig](http://twig.sensiolabs.org/) - Flexible, fast, and secure template engine for PHP.
- [Parsedown](http://parsedown.org/) - Better Markdown Parser in PHP.
- [PHP](https://php.net/) - Popular general-purpose scripting language that is especially suited to web development.
- [Twig](https://twig.symfony.com/) - Flexible, fast, and secure template engine for PHP.
- [Parsedown](https://parsedown.org/) - Better Markdown Parser in PHP.
- [phpBB](https://www.phpbb.com/) - Free flat-forum bulletin board software solution written using PHP.
- [jQuery](https://jquery.com/) - The Write Less, Do More, JavaScript Library.
- [Bootstrap](https://getbootstrap.com/) - Sleek, intuitive and powerful mobile first front-end framework for the web.
......
......@@ -9,7 +9,7 @@ Additionally the [Litera](https://bootswatch.com/litera/) theme from bootswatch.
the basis for the theme when pages are printed and users have the option to switch to a darker base
theme [Slate](https://bootswatch.com/slate/) also from bootswatch.com.
The organization's entire website, including the base [Twig](http://twig.sensiolabs.org/) template
The organization's entire website, including the base [Twig](https://twig.symfony.com/) template
files with the supporting markup and utilities, is publically available over on
[GitLab.com](https://gitlab.com/groups/dcnf) released collectively under the terms of the
[GNU General Public License](https://www.dcbase.org/DCBase/LICENSE) (version 2), *unless otherwise
......
......@@ -9,7 +9,7 @@ Additionally the [Readable](https://bootswatch.com/readable/) theme from bootswa
the basis for the theme when pages are printed and users have the option to switch to a darker base
theme [Darkly](https://bootswatch.com/darkly/) also from bootswatch.com.
The organization's entire website, including the base [Twig](http://twig.sensiolabs.org/) template
The organization's entire website, including the base [Twig](https://twig.symfony.com/) template
files with the supporting markup and utilities, is publically available over on
[GitLab.com](https://gitlab.com/groups/dcnf) released collectively under the terms of the
[GNU General Public License](https://www.dcbase.org/DCBase/LICENSE) (version 2), *unless otherwise stated*.
......
* 2.12.1 (2019-10-17)
* added the String extension in the "extra" repositories: "u" filter
* 2.12.0 (2019-10-05)
* added the spaceship operator ("<=>"), useful when using an arrow function in the "sort" filter
* added support for an "arrow" function on the "sort" filter
* added the CssInliner extension in the "extra" repositories: "inline_css"
filter
* added the Inky extension in the "extra" repositories: "inky_to_html" filter
* added Intl extension in the "extra" repositories: "country_name",
"currency_name", "currency_symbol", "language_name", "locale_name",
"timezone_name", "format_currency", "format_number",
"format_*_number", "format_datetime", "format_date", and "format_time"
filters, and the "country_timezones" function
* added the Markdown extension in the "extra" repositories: "markdown_to_html",
and "html_to_markdown" filters
* added the HtmlExtension extension in the "extra" repositories: "date_uri"
filter, and "html_classes" function
* optimized "block('foo') ?? 'bar'"
* fixed the empty test on Traversable instances
* fixed array_key_exists() on objects
* fixed cache when opcache is installed but disabled
* fixed using macros in arrow functions
* fixed split filter on edge case
* 2.11.3 (2019-06-18)
* display partial output (PHP buffer) when an error occurs in debug mode
* fixed the filter filter (allow the result to be used several times)
* fixed macro auto-import when a template contains only macros
......@@ -254,7 +282,19 @@
* improved the performance of the filesystem loader
* removed features that were deprecated in 1.x
* 1.42.2 (2019-XX-XX)
* 1.42.4 (2019-XX-XX)
* n/a
* 1.42.3 (2019-08-24)
* fixed the "split" filter when the delimiter is "0"
* fixed the "empty" test on Traversable instances
* fixed cache when opcache is installed but disabled
* fixed PHP 7.4 compatibility
* bumped the minimal PHP version to 5.5
* 1.42.2 (2019-06-18)
* Display partial output (PHP buffer) when an error occurs in debug mode
......
......@@ -67,8 +67,8 @@ class FilesystemCache implements CacheInterface
if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
// Compile cached file into bytecode cache
if (\function_exists('opcache_invalidate')) {
opcache_invalidate($key, true);
if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) {
@opcache_invalidate($key, true);
} elseif (\function_exists('apc_compile_file')) {
apc_compile_file($key);
}
......
......@@ -38,11 +38,11 @@ use Twig\TokenParser\TokenParserInterface;
*/
class Environment
{
const VERSION = '2.11.3';
const VERSION_ID = 21103;
const VERSION = '2.12.1';
const VERSION_ID = 21201;
const MAJOR_VERSION = 2;
const MINOR_VERSION = 11;
const RELEASE_VERSION = 3;
const MINOR_VERSION = 12;
const RELEASE_VERSION = 1;
const EXTRA_VERSION = '';
private $charset;
......
......@@ -34,6 +34,7 @@ use Twig\Node\Expression\Binary\NotInBinary;
use Twig\Node\Expression\Binary\OrBinary;
use Twig\Node\Expression\Binary\PowerBinary;
use Twig\Node\Expression\Binary\RangeBinary;
use Twig\Node\Expression\Binary\SpaceshipBinary;
use Twig\Node\Expression\Binary\StartsWithBinary;
use Twig\Node\Expression\Binary\SubBinary;
use Twig\Node\Expression\Filter\DefaultFilter;
......@@ -309,6 +310,7 @@ final class CoreExtension extends AbstractExtension
'b-and' => ['precedence' => 18, 'class' => BitwiseAndBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
'==' => ['precedence' => 20, 'class' => EqualBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
'!=' => ['precedence' => 20, 'class' => NotEqualBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
'<=>' => ['precedence' => 20, 'class' => SpaceshipBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
'<' => ['precedence' => 20, 'class' => LessBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
'>' => ['precedence' => 20, 'class' => GreaterBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
'>=' => ['precedence' => 20, 'class' => GreaterEqualBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
......@@ -778,7 +780,7 @@ function twig_join_filter($value, $glue = '', $and = null)
*/
function twig_split_filter(Environment $env, $value, $delimiter, $limit = null)
{
if (!empty($delimiter)) {
if (\strlen($delimiter) > 0) {
return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
}
......@@ -904,7 +906,7 @@ function twig_reverse_filter(Environment $env, $item, $preserveKeys = false)
*
* @return array
*/
function twig_sort_filter($array)
function twig_sort_filter($array, $arrow = null)
{
if ($array instanceof \Traversable) {
$array = iterator_to_array($array);
......@@ -912,7 +914,11 @@ function twig_sort_filter($array)
throw new RuntimeError(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', \gettype($array)));
}
asort($array);
if (null !== $arrow) {
uasort($array, $arrow);
} else {
asort($array);
}
return $array;
}
......@@ -1145,6 +1151,10 @@ function twig_test_empty($value)
return 0 == \count($value);
}
if ($value instanceof \Traversable) {
return !iterator_count($value);
}
if (\is_object($value) && method_exists($value, '__toString')) {
return '' === (string) $value;
}
......@@ -1322,7 +1332,7 @@ function twig_get_attribute(Environment $env, Source $source, $object, $item, ar
if (/* Template::METHOD_CALL */ 'method' !== $type) {
$arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item;
if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, $object)))
if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, (array) $object)))
|| ($object instanceof ArrayAccess && isset($object[$arrayItem]))
) {
if ($isDefinedTest) {
......@@ -1393,7 +1403,7 @@ function twig_get_attribute(Environment $env, Source $source, $object, $item, ar
// object property
if (/* Template::METHOD_CALL */ 'method' !== $type) {
if (isset($object->$item) || \array_key_exists((string) $item, $object)) {
if (isset($object->$item) || \array_key_exists((string) $item, (array) $object)) {
if ($isDefinedTest) {
return true;
}
......@@ -1506,10 +1516,11 @@ function twig_get_attribute(Environment $env, Source $source, $object, $item, ar
*
* @param array|Traversable $array An array
* @param mixed $name The column name
* @param mixed $index The column to use as the index/keys for the returned array
*
* @return array The array of values
*/
function twig_array_column($array, $name): array
function twig_array_column($array, $name, $index = null): array
{
if ($array instanceof Traversable) {
$array = iterator_to_array($array);
......@@ -1517,7 +1528,7 @@ function twig_array_column($array, $name): array
throw new RuntimeError(sprintf('The column filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($array)));
}
return array_column($array, $name);
return array_column($array, $name, $index);
}
function twig_array_filter($array, $arrow)
......
......@@ -44,7 +44,7 @@ class ArrowFunctionExpression extends AbstractExpression
;
}
$compiler
->raw(') use ($context) { ')
->raw(') use ($context, $macros) { ')
;
foreach ($this->getNode('names') as $name) {
$compiler
......
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Node\Expression\Binary;
use Twig\Compiler;
class SpaceshipBinary extends AbstractBinary
{
public function operator(Compiler $compiler)
{
return $compiler->raw('<=>');
}
}
......@@ -22,11 +22,15 @@ class NullCoalesceExpression extends ConditionalExpression
{
public function __construct(Node $left, Node $right, int $lineno)
{
$test = new AndBinary(
new DefinedTest(clone $left, 'defined', new Node(), $left->getTemplateLine()),
new NotUnary(new NullTest($left, 'null', new Node(), $left->getTemplateLine()), $left->getTemplateLine()),
$left->getTemplateLine()
);
$test = new DefinedTest(clone $left, 'defined', new Node(), $left->getTemplateLine());
// for "block()", we don't need the null test as the return value is always a string
if (!$left instanceof BlockReferenceExpression) {
$test = new AndBinary(
$test,
new NotUnary(new NullTest($left, 'null', new Node(), $left->getTemplateLine()), $left->getTemplateLine()),
$left->getTemplateLine()
);
}
parent::__construct($test, $left, $right, $lineno);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment