mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
Update Twig from 1.35.0 to 1.42.4 (PHP 5.5 is now required!)
This fixes some errors on PHP 7.4 and contains even more fixes Also bumped PHP version to 5.5 as Twig requires it.
This commit is contained in:
parent
d9e449b6cf
commit
8021308822
@ -23,7 +23,7 @@
|
|||||||
* @copyright 2019 MyAAC
|
* @copyright 2019 MyAAC
|
||||||
* @link https://my-aac.org
|
* @link https://my-aac.org
|
||||||
*/
|
*/
|
||||||
if (version_compare(phpversion(), '5.3.3', '<')) die('PHP version 5.3.3 or higher is required.');
|
if (version_compare(phpversion(), '5.5', '<')) die('PHP version 5.5 or higher is required.');
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
define('MYAAC', true);
|
define('MYAAC', true);
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Twig\Environment as Twig_Environment;
|
||||||
|
use Twig\Loader\FilesystemLoader as Twig_FilesystemLoader;
|
||||||
|
|
||||||
require '../common.php';
|
require '../common.php';
|
||||||
|
|
||||||
define('MYAAC_INSTALL', true);
|
define('MYAAC_INSTALL', true);
|
||||||
@ -12,14 +16,10 @@ require SYSTEM . 'clients.conf.php';
|
|||||||
if(file_exists(BASE . 'config.local.php'))
|
if(file_exists(BASE . 'config.local.php'))
|
||||||
require BASE . 'config.local.php';
|
require BASE . 'config.local.php';
|
||||||
|
|
||||||
// twig
|
|
||||||
require_once LIBS . 'Twig/Autoloader.php';
|
|
||||||
Twig_Autoloader::register();
|
|
||||||
|
|
||||||
// ignore undefined index from Twig autoloader
|
// ignore undefined index from Twig autoloader
|
||||||
$config['env'] = 'prod';
|
$config['env'] = 'prod';
|
||||||
|
|
||||||
$twig_loader = new Twig_Loader_Filesystem(SYSTEM . 'templates');
|
$twig_loader = new Twig_FilesystemLoader(SYSTEM . 'templates');
|
||||||
$twig = new Twig_Environment($twig_loader, array(
|
$twig = new Twig_Environment($twig_loader, array(
|
||||||
'cache' => CACHE . 'twig/',
|
'cache' => CACHE . 'twig/',
|
||||||
'auto_reload' => true
|
'auto_reload' => true
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
* @copyright 2019 MyAAC
|
* @copyright 2019 MyAAC
|
||||||
* @link https://my-aac.org
|
* @link https://my-aac.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Twig\Loader\ArrayLoader as Twig_ArrayLoader;
|
||||||
|
|
||||||
defined('MYAAC') or die('Direct access not allowed!');
|
defined('MYAAC') or die('Direct access not allowed!');
|
||||||
|
|
||||||
function message($message, $type, $return)
|
function message($message, $type, $return)
|
||||||
@ -1190,7 +1193,7 @@ function getCustomPage($page, &$success)
|
|||||||
else {
|
else {
|
||||||
$oldLoader = $twig->getLoader();
|
$oldLoader = $twig->getLoader();
|
||||||
|
|
||||||
$twig_loader_array = new Twig_Loader_Array(array(
|
$twig_loader_array = new Twig_ArrayLoader(array(
|
||||||
'content.html' => $query['body']
|
'content.html' => $query['body']
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
<?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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Twig_BaseNodeVisitor can be used to make node visitors compatible with Twig 1.x and 2.x.
|
|
||||||
*
|
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
|
||||||
*/
|
|
||||||
abstract class Twig_BaseNodeVisitor implements Twig_NodeVisitorInterface
|
|
||||||
{
|
|
||||||
final public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
|
|
||||||
{
|
|
||||||
if (!$node instanceof Twig_Node) {
|
|
||||||
throw new LogicException('Twig_BaseNodeVisitor only supports Twig_Node instances.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->doEnterNode($node, $env);
|
|
||||||
}
|
|
||||||
|
|
||||||
final public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
|
|
||||||
{
|
|
||||||
if (!$node instanceof Twig_Node) {
|
|
||||||
throw new LogicException('Twig_BaseNodeVisitor only supports Twig_Node instances.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->doLeaveNode($node, $env);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called before child nodes are visited.
|
|
||||||
*
|
|
||||||
* @return Twig_Node The modified node
|
|
||||||
*/
|
|
||||||
abstract protected function doEnterNode(Twig_Node $node, Twig_Environment $env);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called after child nodes are visited.
|
|
||||||
*
|
|
||||||
* @return Twig_Node|false The modified node or false if the node must be removed
|
|
||||||
*/
|
|
||||||
abstract protected function doLeaveNode(Twig_Node $node, Twig_Environment $env);
|
|
||||||
}
|
|
||||||
|
|
||||||
class_alias('Twig_BaseNodeVisitor', 'Twig\NodeVisitor\AbstractNodeVisitor', false);
|
|
||||||
class_exists('Twig_Environment');
|
|
||||||
class_exists('Twig_Node');
|
|
@ -9,6 +9,8 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface implemented by cache classes.
|
* Interface implemented by cache classes.
|
||||||
*
|
*
|
||||||
@ -18,7 +20,7 @@
|
|||||||
*
|
*
|
||||||
* @author Andrew Tch <andrew@noop.lv>
|
* @author Andrew Tch <andrew@noop.lv>
|
||||||
*/
|
*/
|
||||||
interface Twig_CacheInterface
|
interface CacheInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Generates a cache key for the given template class name.
|
* Generates a cache key for the given template class name.
|
||||||
@ -55,4 +57,4 @@ interface Twig_CacheInterface
|
|||||||
public function getTimestamp($key);
|
public function getTimestamp($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_CacheInterface', 'Twig\Cache\CacheInterface', false);
|
class_alias('Twig\Cache\CacheInterface', 'Twig_CacheInterface');
|
@ -9,12 +9,14 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements a cache on the filesystem.
|
* Implements a cache on the filesystem.
|
||||||
*
|
*
|
||||||
* @author Andrew Tch <andrew@noop.lv>
|
* @author Andrew Tch <andrew@noop.lv>
|
||||||
*/
|
*/
|
||||||
class Twig_Cache_Filesystem implements Twig_CacheInterface
|
class FilesystemCache implements CacheInterface
|
||||||
{
|
{
|
||||||
const FORCE_BYTECODE_INVALIDATION = 1;
|
const FORCE_BYTECODE_INVALIDATION = 1;
|
||||||
|
|
||||||
@ -22,8 +24,8 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
|
|||||||
private $options;
|
private $options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $directory string The root cache directory
|
* @param string $directory The root cache directory
|
||||||
* @param $options int A set of options
|
* @param int $options A set of options
|
||||||
*/
|
*/
|
||||||
public function __construct($directory, $options = 0)
|
public function __construct($directory, $options = 0)
|
||||||
{
|
{
|
||||||
@ -47,18 +49,16 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
|
|||||||
|
|
||||||
public function write($key, $content)
|
public function write($key, $content)
|
||||||
{
|
{
|
||||||
$dir = dirname($key);
|
$dir = \dirname($key);
|
||||||
if (!is_dir($dir)) {
|
if (!is_dir($dir)) {
|
||||||
if (false === @mkdir($dir, 0777, true)) {
|
if (false === @mkdir($dir, 0777, true)) {
|
||||||
if (PHP_VERSION_ID >= 50300) {
|
clearstatcache(true, $dir);
|
||||||
clearstatcache(true, $dir);
|
|
||||||
}
|
|
||||||
if (!is_dir($dir)) {
|
if (!is_dir($dir)) {
|
||||||
throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
|
throw new \RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (!is_writable($dir)) {
|
} elseif (!is_writable($dir)) {
|
||||||
throw new RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
|
throw new \RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmpFile = tempnam($dir, basename($key));
|
$tmpFile = tempnam($dir, basename($key));
|
||||||
@ -67,9 +67,9 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
|
|||||||
|
|
||||||
if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
|
if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
|
||||||
// Compile cached file into bytecode cache
|
// Compile cached file into bytecode cache
|
||||||
if (function_exists('opcache_invalidate')) {
|
if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) {
|
||||||
opcache_invalidate($key, true);
|
@opcache_invalidate($key, true);
|
||||||
} elseif (function_exists('apc_compile_file')) {
|
} elseif (\function_exists('apc_compile_file')) {
|
||||||
apc_compile_file($key);
|
apc_compile_file($key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new RuntimeException(sprintf('Failed to write cache file "%s".', $key));
|
throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTimestamp($key)
|
public function getTimestamp($key)
|
||||||
@ -90,4 +90,4 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Cache_Filesystem', 'Twig\Cache\FilesystemCache', false);
|
class_alias('Twig\Cache\FilesystemCache', 'Twig_Cache_Filesystem');
|
@ -9,6 +9,8 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements a no-cache strategy.
|
* Implements a no-cache strategy.
|
||||||
*
|
*
|
||||||
@ -16,7 +18,7 @@
|
|||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Cache_Null implements Twig_CacheInterface
|
class NullCache implements CacheInterface
|
||||||
{
|
{
|
||||||
public function generateKey($name, $className)
|
public function generateKey($name, $className)
|
||||||
{
|
{
|
||||||
@ -37,4 +39,4 @@ class Twig_Cache_Null implements Twig_CacheInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Cache_Null', 'Twig\Cache\NullCache', false);
|
class_alias('Twig\Cache\NullCache', 'Twig_Cache_Null');
|
@ -10,23 +10,28 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig;
|
||||||
|
|
||||||
|
use Twig\Node\ModuleNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles a node to PHP code.
|
* Compiles a node to PHP code.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Compiler implements Twig_CompilerInterface
|
class Compiler implements \Twig_CompilerInterface
|
||||||
{
|
{
|
||||||
protected $lastLine;
|
protected $lastLine;
|
||||||
protected $source;
|
protected $source;
|
||||||
protected $indentation;
|
protected $indentation;
|
||||||
protected $env;
|
protected $env;
|
||||||
protected $debugInfo = array();
|
protected $debugInfo = [];
|
||||||
protected $sourceOffset;
|
protected $sourceOffset;
|
||||||
protected $sourceLine;
|
protected $sourceLine;
|
||||||
protected $filename;
|
protected $filename;
|
||||||
|
private $varNameSalt = 0;
|
||||||
|
|
||||||
public function __construct(Twig_Environment $env)
|
public function __construct(Environment $env)
|
||||||
{
|
{
|
||||||
$this->env = $env;
|
$this->env = $env;
|
||||||
}
|
}
|
||||||
@ -44,7 +49,7 @@ class Twig_Compiler implements Twig_CompilerInterface
|
|||||||
/**
|
/**
|
||||||
* Returns the environment instance related to this compiler.
|
* Returns the environment instance related to this compiler.
|
||||||
*
|
*
|
||||||
* @return Twig_Environment
|
* @return Environment
|
||||||
*/
|
*/
|
||||||
public function getEnvironment()
|
public function getEnvironment()
|
||||||
{
|
{
|
||||||
@ -64,22 +69,22 @@ class Twig_Compiler implements Twig_CompilerInterface
|
|||||||
/**
|
/**
|
||||||
* Compiles a node.
|
* Compiles a node.
|
||||||
*
|
*
|
||||||
* @param Twig_NodeInterface $node The node to compile
|
* @param int $indentation The current indentation
|
||||||
* @param int $indentation The current indentation
|
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function compile(Twig_NodeInterface $node, $indentation = 0)
|
public function compile(\Twig_NodeInterface $node, $indentation = 0)
|
||||||
{
|
{
|
||||||
$this->lastLine = null;
|
$this->lastLine = null;
|
||||||
$this->source = '';
|
$this->source = '';
|
||||||
$this->debugInfo = array();
|
$this->debugInfo = [];
|
||||||
$this->sourceOffset = 0;
|
$this->sourceOffset = 0;
|
||||||
// source code starts at 1 (as we then increment it when we encounter new lines)
|
// source code starts at 1 (as we then increment it when we encounter new lines)
|
||||||
$this->sourceLine = 1;
|
$this->sourceLine = 1;
|
||||||
$this->indentation = $indentation;
|
$this->indentation = $indentation;
|
||||||
|
$this->varNameSalt = 0;
|
||||||
|
|
||||||
if ($node instanceof Twig_Node_Module) {
|
if ($node instanceof ModuleNode) {
|
||||||
// to be removed in 2.0
|
// to be removed in 2.0
|
||||||
$this->filename = $node->getTemplateName();
|
$this->filename = $node->getTemplateName();
|
||||||
}
|
}
|
||||||
@ -89,7 +94,7 @@ class Twig_Compiler implements Twig_CompilerInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function subcompile(Twig_NodeInterface $node, $raw = true)
|
public function subcompile(\Twig_NodeInterface $node, $raw = true)
|
||||||
{
|
{
|
||||||
if (false === $raw) {
|
if (false === $raw) {
|
||||||
$this->source .= str_repeat(' ', $this->indentation * 4);
|
$this->source .= str_repeat(' ', $this->indentation * 4);
|
||||||
@ -121,7 +126,7 @@ class Twig_Compiler implements Twig_CompilerInterface
|
|||||||
*/
|
*/
|
||||||
public function write()
|
public function write()
|
||||||
{
|
{
|
||||||
$strings = func_get_args();
|
$strings = \func_get_args();
|
||||||
foreach ($strings as $string) {
|
foreach ($strings as $string) {
|
||||||
$this->source .= str_repeat(' ', $this->indentation * 4).$string;
|
$this->source .= str_repeat(' ', $this->indentation * 4).$string;
|
||||||
}
|
}
|
||||||
@ -168,22 +173,22 @@ class Twig_Compiler implements Twig_CompilerInterface
|
|||||||
*/
|
*/
|
||||||
public function repr($value)
|
public function repr($value)
|
||||||
{
|
{
|
||||||
if (is_int($value) || is_float($value)) {
|
if (\is_int($value) || \is_float($value)) {
|
||||||
if (false !== $locale = setlocale(LC_NUMERIC, '0')) {
|
if (false !== $locale = setlocale(LC_NUMERIC, '0')) {
|
||||||
setlocale(LC_NUMERIC, 'C');
|
setlocale(LC_NUMERIC, 'C');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->raw($value);
|
$this->raw(var_export($value, true));
|
||||||
|
|
||||||
if (false !== $locale) {
|
if (false !== $locale) {
|
||||||
setlocale(LC_NUMERIC, $locale);
|
setlocale(LC_NUMERIC, $locale);
|
||||||
}
|
}
|
||||||
} elseif (null === $value) {
|
} elseif (null === $value) {
|
||||||
$this->raw('null');
|
$this->raw('null');
|
||||||
} elseif (is_bool($value)) {
|
} elseif (\is_bool($value)) {
|
||||||
$this->raw($value ? 'true' : 'false');
|
$this->raw($value ? 'true' : 'false');
|
||||||
} elseif (is_array($value)) {
|
} elseif (\is_array($value)) {
|
||||||
$this->raw('array(');
|
$this->raw('[');
|
||||||
$first = true;
|
$first = true;
|
||||||
foreach ($value as $key => $v) {
|
foreach ($value as $key => $v) {
|
||||||
if (!$first) {
|
if (!$first) {
|
||||||
@ -194,7 +199,7 @@ class Twig_Compiler implements Twig_CompilerInterface
|
|||||||
$this->raw(' => ');
|
$this->raw(' => ');
|
||||||
$this->repr($v);
|
$this->repr($v);
|
||||||
}
|
}
|
||||||
$this->raw(')');
|
$this->raw(']');
|
||||||
} else {
|
} else {
|
||||||
$this->string($value);
|
$this->string($value);
|
||||||
}
|
}
|
||||||
@ -207,7 +212,7 @@ class Twig_Compiler implements Twig_CompilerInterface
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function addDebugInfo(Twig_NodeInterface $node)
|
public function addDebugInfo(\Twig_NodeInterface $node)
|
||||||
{
|
{
|
||||||
if ($node->getTemplateLine() != $this->lastLine) {
|
if ($node->getTemplateLine() != $this->lastLine) {
|
||||||
$this->write(sprintf("// line %d\n", $node->getTemplateLine()));
|
$this->write(sprintf("// line %d\n", $node->getTemplateLine()));
|
||||||
@ -223,7 +228,7 @@ class Twig_Compiler implements Twig_CompilerInterface
|
|||||||
} else {
|
} else {
|
||||||
$this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset);
|
$this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset);
|
||||||
}
|
}
|
||||||
$this->sourceOffset = strlen($this->source);
|
$this->sourceOffset = \strlen($this->source);
|
||||||
$this->debugInfo[$this->sourceLine] = $node->getTemplateLine();
|
$this->debugInfo[$this->sourceLine] = $node->getTemplateLine();
|
||||||
|
|
||||||
$this->lastLine = $node->getTemplateLine();
|
$this->lastLine = $node->getTemplateLine();
|
||||||
@ -260,13 +265,13 @@ class Twig_Compiler implements Twig_CompilerInterface
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*
|
*
|
||||||
* @throws LogicException When trying to outdent too much so the indentation would become negative
|
* @throws \LogicException When trying to outdent too much so the indentation would become negative
|
||||||
*/
|
*/
|
||||||
public function outdent($step = 1)
|
public function outdent($step = 1)
|
||||||
{
|
{
|
||||||
// can't outdent by more steps than the current indentation level
|
// can't outdent by more steps than the current indentation level
|
||||||
if ($this->indentation < $step) {
|
if ($this->indentation < $step) {
|
||||||
throw new LogicException('Unable to call outdent() as the indentation would become negative.');
|
throw new \LogicException('Unable to call outdent() as the indentation would become negative.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->indentation -= $step;
|
$this->indentation -= $step;
|
||||||
@ -276,9 +281,8 @@ class Twig_Compiler implements Twig_CompilerInterface
|
|||||||
|
|
||||||
public function getVarName()
|
public function getVarName()
|
||||||
{
|
{
|
||||||
return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false));
|
return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->varNameSalt++));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Compiler', 'Twig\Compiler', false);
|
class_alias('Twig\Compiler', 'Twig_Compiler');
|
||||||
class_exists('Twig_Node');
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
90
system/libs/Twig/Error.php → system/libs/Twig/Error/Error.php
Executable file → Normal file
90
system/libs/Twig/Error.php → system/libs/Twig/Error/Error.php
Executable file → Normal file
@ -9,6 +9,11 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Error;
|
||||||
|
|
||||||
|
use Twig\Source;
|
||||||
|
use Twig\Template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Twig base exception.
|
* Twig base exception.
|
||||||
*
|
*
|
||||||
@ -31,13 +36,12 @@
|
|||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Error extends Exception
|
class Error extends \Exception
|
||||||
{
|
{
|
||||||
protected $lineno;
|
protected $lineno;
|
||||||
// to be renamed to name in 2.0
|
// to be renamed to name in 2.0
|
||||||
protected $filename;
|
protected $filename;
|
||||||
protected $rawMessage;
|
protected $rawMessage;
|
||||||
protected $previous;
|
|
||||||
|
|
||||||
private $sourcePath;
|
private $sourcePath;
|
||||||
private $sourceCode;
|
private $sourceCode;
|
||||||
@ -45,25 +49,19 @@ class Twig_Error extends Exception
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* Set both the line number and the name to false to
|
|
||||||
* disable automatic guessing of the original template name
|
|
||||||
* and line number.
|
|
||||||
*
|
|
||||||
* Set the line number to -1 to enable its automatic guessing.
|
* Set the line number to -1 to enable its automatic guessing.
|
||||||
* Set the name to null to enable its automatic guessing.
|
* Set the name to null to enable its automatic guessing.
|
||||||
*
|
*
|
||||||
* By default, automatic guessing is enabled.
|
* @param string $message The error message
|
||||||
*
|
* @param int $lineno The template line where the error occurred
|
||||||
* @param string $message The error message
|
* @param Source|string|null $source The source context where the error occurred
|
||||||
* @param int $lineno The template line where the error occurred
|
* @param \Exception $previous The previous exception
|
||||||
* @param Twig_Source|string|null $source The source context where the error occurred
|
|
||||||
* @param Exception $previous The previous exception
|
|
||||||
*/
|
*/
|
||||||
public function __construct($message, $lineno = -1, $source = null, Exception $previous = null)
|
public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null)
|
||||||
{
|
{
|
||||||
if (null === $source) {
|
if (null === $source) {
|
||||||
$name = null;
|
$name = null;
|
||||||
} elseif (!$source instanceof Twig_Source) {
|
} elseif (!$source instanceof Source) {
|
||||||
// for compat with the Twig C ext., passing the template name as string is accepted
|
// for compat with the Twig C ext., passing the template name as string is accepted
|
||||||
$name = $source;
|
$name = $source;
|
||||||
} else {
|
} else {
|
||||||
@ -71,22 +69,11 @@ class Twig_Error extends Exception
|
|||||||
$this->sourceCode = $source->getCode();
|
$this->sourceCode = $source->getCode();
|
||||||
$this->sourcePath = $source->getPath();
|
$this->sourcePath = $source->getPath();
|
||||||
}
|
}
|
||||||
if (PHP_VERSION_ID < 50300) {
|
parent::__construct('', 0, $previous);
|
||||||
$this->previous = $previous;
|
|
||||||
parent::__construct('');
|
|
||||||
} else {
|
|
||||||
parent::__construct('', 0, $previous);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->lineno = $lineno;
|
$this->lineno = $lineno;
|
||||||
$this->filename = $name;
|
$this->filename = $name;
|
||||||
|
|
||||||
if (-1 === $lineno || null === $name || null === $this->sourcePath) {
|
|
||||||
$this->guessTemplateInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->rawMessage = $message;
|
$this->rawMessage = $message;
|
||||||
|
|
||||||
$this->updateRepr();
|
$this->updateRepr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,17 +173,17 @@ class Twig_Error extends Exception
|
|||||||
/**
|
/**
|
||||||
* Gets the source context of the Twig template where the error occurred.
|
* Gets the source context of the Twig template where the error occurred.
|
||||||
*
|
*
|
||||||
* @return Twig_Source|null
|
* @return Source|null
|
||||||
*/
|
*/
|
||||||
public function getSourceContext()
|
public function getSourceContext()
|
||||||
{
|
{
|
||||||
return $this->filename ? new Twig_Source($this->sourceCode, $this->filename, $this->sourcePath) : null;
|
return $this->filename ? new Source($this->sourceCode, $this->filename, $this->sourcePath) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the source context of the Twig template where the error occurred.
|
* Sets the source context of the Twig template where the error occurred.
|
||||||
*/
|
*/
|
||||||
public function setSourceContext(Twig_Source $source = null)
|
public function setSourceContext(Source $source = null)
|
||||||
{
|
{
|
||||||
if (null === $source) {
|
if (null === $source) {
|
||||||
$this->sourceCode = $this->filename = $this->sourcePath = null;
|
$this->sourceCode = $this->filename = $this->sourcePath = null;
|
||||||
@ -215,25 +202,6 @@ class Twig_Error extends Exception
|
|||||||
$this->updateRepr();
|
$this->updateRepr();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* For PHP < 5.3.0, provides access to the getPrevious() method.
|
|
||||||
*
|
|
||||||
* @param string $method The method name
|
|
||||||
* @param array $arguments The parameters to be passed to the method
|
|
||||||
*
|
|
||||||
* @return Exception The previous exception or null
|
|
||||||
*
|
|
||||||
* @throws BadMethodCallException
|
|
||||||
*/
|
|
||||||
public function __call($method, $arguments)
|
|
||||||
{
|
|
||||||
if ('getprevious' == strtolower($method)) {
|
|
||||||
return $this->previous;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new BadMethodCallException(sprintf('Method "Twig_Error::%s()" does not exist.', $method));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function appendMessage($rawMessage)
|
public function appendMessage($rawMessage)
|
||||||
{
|
{
|
||||||
$this->rawMessage .= $rawMessage;
|
$this->rawMessage .= $rawMessage;
|
||||||
@ -267,7 +235,7 @@ class Twig_Error extends Exception
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->filename) {
|
if ($this->filename) {
|
||||||
if (is_string($this->filename) || (is_object($this->filename) && method_exists($this->filename, '__toString'))) {
|
if (\is_string($this->filename) || (\is_object($this->filename) && method_exists($this->filename, '__toString'))) {
|
||||||
$name = sprintf('"%s"', $this->filename);
|
$name = sprintf('"%s"', $this->filename);
|
||||||
} else {
|
} else {
|
||||||
$name = json_encode($this->filename);
|
$name = json_encode($this->filename);
|
||||||
@ -296,19 +264,14 @@ class Twig_Error extends Exception
|
|||||||
$template = null;
|
$template = null;
|
||||||
$templateClass = null;
|
$templateClass = null;
|
||||||
|
|
||||||
if (PHP_VERSION_ID >= 50306) {
|
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
|
||||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
|
|
||||||
} else {
|
|
||||||
$backtrace = debug_backtrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($backtrace as $trace) {
|
foreach ($backtrace as $trace) {
|
||||||
if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) {
|
if (isset($trace['object']) && $trace['object'] instanceof Template && 'Twig_Template' !== \get_class($trace['object'])) {
|
||||||
$currentClass = get_class($trace['object']);
|
$currentClass = \get_class($trace['object']);
|
||||||
$isEmbedContainer = 0 === strpos($templateClass, $currentClass);
|
$isEmbedContainer = 0 === strpos($templateClass, $currentClass);
|
||||||
if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) {
|
if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) {
|
||||||
$template = $trace['object'];
|
$template = $trace['object'];
|
||||||
$templateClass = get_class($trace['object']);
|
$templateClass = \get_class($trace['object']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -329,17 +292,17 @@ class Twig_Error extends Exception
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = new ReflectionObject($template);
|
$r = new \ReflectionObject($template);
|
||||||
$file = $r->getFileName();
|
$file = $r->getFileName();
|
||||||
|
|
||||||
$exceptions = array($e = $this);
|
$exceptions = [$e = $this];
|
||||||
while (($e instanceof self || method_exists($e, 'getPrevious')) && $e = $e->getPrevious()) {
|
while ($e instanceof self && $e = $e->getPrevious()) {
|
||||||
$exceptions[] = $e;
|
$exceptions[] = $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ($e = array_pop($exceptions)) {
|
while ($e = array_pop($exceptions)) {
|
||||||
$traces = $e->getTrace();
|
$traces = $e->getTrace();
|
||||||
array_unshift($traces, array('file' => $e->getFile(), 'line' => $e->getLine()));
|
array_unshift($traces, ['file' => $e->getFile(), 'line' => $e->getLine()]);
|
||||||
|
|
||||||
while ($trace = array_shift($traces)) {
|
while ($trace = array_shift($traces)) {
|
||||||
if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) {
|
if (!isset($trace['file']) || !isset($trace['line']) || $file != $trace['file']) {
|
||||||
@ -359,5 +322,4 @@ class Twig_Error extends Exception
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Error', 'Twig\Error\Error', false);
|
class_alias('Twig\Error\Error', 'Twig_Error');
|
||||||
class_exists('Twig_Source');
|
|
@ -1,40 +0,0 @@
|
|||||||
<?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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception thrown when an error occurs during template loading.
|
|
||||||
*
|
|
||||||
* Automatic template information guessing is always turned off as
|
|
||||||
* if a template cannot be loaded, there is nothing to guess.
|
|
||||||
* However, when a template is loaded from another one, then, we need
|
|
||||||
* to find the current context and this is automatically done by
|
|
||||||
* Twig_Template::displayWithErrorHandling().
|
|
||||||
*
|
|
||||||
* This strategy makes Twig_Environment::resolveTemplate() much faster.
|
|
||||||
*
|
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
|
||||||
*/
|
|
||||||
class Twig_Error_Loader extends Twig_Error
|
|
||||||
{
|
|
||||||
public function __construct($message, $lineno = -1, $source = null, Exception $previous = null)
|
|
||||||
{
|
|
||||||
if (PHP_VERSION_ID < 50300) {
|
|
||||||
$this->previous = $previous;
|
|
||||||
Exception::__construct('');
|
|
||||||
} else {
|
|
||||||
Exception::__construct('', 0, $previous);
|
|
||||||
}
|
|
||||||
$this->appendMessage($message);
|
|
||||||
$this->setTemplateLine(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class_alias('Twig_Error_Loader', 'Twig\Error\LoaderError', false);
|
|
23
system/libs/Twig/Error/LoaderError.php
Normal file
23
system/libs/Twig/Error/LoaderError.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?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\Error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception thrown when an error occurs during template loading.
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*/
|
||||||
|
class LoaderError extends Error
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
class_alias('Twig\Error\LoaderError', 'Twig_Error_Loader');
|
6
system/libs/Twig/Error/Runtime.php → system/libs/Twig/Error/RuntimeError.php
Executable file → Normal file
6
system/libs/Twig/Error/Runtime.php → system/libs/Twig/Error/RuntimeError.php
Executable file → Normal file
@ -10,13 +10,15 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown when an error occurs at runtime.
|
* Exception thrown when an error occurs at runtime.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Error_Runtime extends Twig_Error
|
class RuntimeError extends Error
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Error_Runtime', 'Twig\Error\RuntimeError', false);
|
class_alias('Twig\Error\RuntimeError', 'Twig_Error_Runtime');
|
12
system/libs/Twig/Error/Syntax.php → system/libs/Twig/Error/SyntaxError.php
Executable file → Normal file
12
system/libs/Twig/Error/Syntax.php → system/libs/Twig/Error/SyntaxError.php
Executable file → Normal file
@ -10,12 +10,14 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown when a syntax error occurs during lexing or parsing of a template.
|
* \Exception thrown when a syntax error occurs during lexing or parsing of a template.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Error_Syntax extends Twig_Error
|
class SyntaxError extends Error
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Tweaks the error message to include suggestions.
|
* Tweaks the error message to include suggestions.
|
||||||
@ -39,10 +41,10 @@ class Twig_Error_Syntax extends Twig_Error
|
|||||||
*/
|
*/
|
||||||
public static function computeAlternatives($name, $items)
|
public static function computeAlternatives($name, $items)
|
||||||
{
|
{
|
||||||
$alternatives = array();
|
$alternatives = [];
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
$lev = levenshtein($name, $item);
|
$lev = levenshtein($name, $item);
|
||||||
if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) {
|
if ($lev <= \strlen($name) / 3 || false !== strpos($item, $name)) {
|
||||||
$alternatives[$item] = $lev;
|
$alternatives[$item] = $lev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,4 +54,4 @@ class Twig_Error_Syntax extends Twig_Error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Error_Syntax', 'Twig\Error\SyntaxError', false);
|
class_alias('Twig\Error\SyntaxError', 'Twig_Error_Syntax');
|
@ -10,19 +10,38 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig;
|
||||||
|
|
||||||
|
use Twig\Error\SyntaxError;
|
||||||
|
use Twig\Node\Expression\ArrayExpression;
|
||||||
|
use Twig\Node\Expression\ArrowFunctionExpression;
|
||||||
|
use Twig\Node\Expression\AssignNameExpression;
|
||||||
|
use Twig\Node\Expression\Binary\ConcatBinary;
|
||||||
|
use Twig\Node\Expression\BlockReferenceExpression;
|
||||||
|
use Twig\Node\Expression\ConditionalExpression;
|
||||||
|
use Twig\Node\Expression\ConstantExpression;
|
||||||
|
use Twig\Node\Expression\GetAttrExpression;
|
||||||
|
use Twig\Node\Expression\MethodCallExpression;
|
||||||
|
use Twig\Node\Expression\NameExpression;
|
||||||
|
use Twig\Node\Expression\ParentExpression;
|
||||||
|
use Twig\Node\Expression\Unary\NegUnary;
|
||||||
|
use Twig\Node\Expression\Unary\NotUnary;
|
||||||
|
use Twig\Node\Expression\Unary\PosUnary;
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses expressions.
|
* Parses expressions.
|
||||||
*
|
*
|
||||||
* This parser implements a "Precedence climbing" algorithm.
|
* This parser implements a "Precedence climbing" algorithm.
|
||||||
*
|
*
|
||||||
* @see http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm
|
* @see https://www.engr.mun.ca/~theo/Misc/exp_parsing.htm
|
||||||
* @see http://en.wikipedia.org/wiki/Operator-precedence_parser
|
* @see https://en.wikipedia.org/wiki/Operator-precedence_parser
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class Twig_ExpressionParser
|
class ExpressionParser
|
||||||
{
|
{
|
||||||
const OPERATOR_LEFT = 1;
|
const OPERATOR_LEFT = 1;
|
||||||
const OPERATOR_RIGHT = 2;
|
const OPERATOR_RIGHT = 2;
|
||||||
@ -33,11 +52,11 @@ class Twig_ExpressionParser
|
|||||||
|
|
||||||
private $env;
|
private $env;
|
||||||
|
|
||||||
public function __construct(Twig_Parser $parser, $env = null)
|
public function __construct(Parser $parser, $env = null)
|
||||||
{
|
{
|
||||||
$this->parser = $parser;
|
$this->parser = $parser;
|
||||||
|
|
||||||
if ($env instanceof Twig_Environment) {
|
if ($env instanceof Environment) {
|
||||||
$this->env = $env;
|
$this->env = $env;
|
||||||
$this->unaryOperators = $env->getUnaryOperators();
|
$this->unaryOperators = $env->getUnaryOperators();
|
||||||
$this->binaryOperators = $env->getBinaryOperators();
|
$this->binaryOperators = $env->getBinaryOperators();
|
||||||
@ -50,8 +69,12 @@ class Twig_ExpressionParser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseExpression($precedence = 0)
|
public function parseExpression($precedence = 0, $allowArrow = false)
|
||||||
{
|
{
|
||||||
|
if ($allowArrow && $arrow = $this->parseArrow()) {
|
||||||
|
return $arrow;
|
||||||
|
}
|
||||||
|
|
||||||
$expr = $this->getPrimary();
|
$expr = $this->getPrimary();
|
||||||
$token = $this->parser->getCurrentToken();
|
$token = $this->parser->getCurrentToken();
|
||||||
while ($this->isBinary($token) && $this->binaryOperators[$token->getValue()]['precedence'] >= $precedence) {
|
while ($this->isBinary($token) && $this->binaryOperators[$token->getValue()]['precedence'] >= $precedence) {
|
||||||
@ -63,7 +86,7 @@ class Twig_ExpressionParser
|
|||||||
} elseif ('is' === $token->getValue()) {
|
} elseif ('is' === $token->getValue()) {
|
||||||
$expr = $this->parseTestExpression($expr);
|
$expr = $this->parseTestExpression($expr);
|
||||||
} elseif (isset($op['callable'])) {
|
} elseif (isset($op['callable'])) {
|
||||||
$expr = call_user_func($op['callable'], $this->parser, $expr);
|
$expr = \call_user_func($op['callable'], $this->parser, $expr);
|
||||||
} else {
|
} else {
|
||||||
$expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']);
|
$expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']);
|
||||||
$class = $op['class'];
|
$class = $op['class'];
|
||||||
@ -80,6 +103,64 @@ class Twig_ExpressionParser
|
|||||||
return $expr;
|
return $expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ArrowFunctionExpression|null
|
||||||
|
*/
|
||||||
|
private function parseArrow()
|
||||||
|
{
|
||||||
|
$stream = $this->parser->getStream();
|
||||||
|
|
||||||
|
// short array syntax (one argument, no parentheses)?
|
||||||
|
if ($stream->look(1)->test(Token::ARROW_TYPE)) {
|
||||||
|
$line = $stream->getCurrent()->getLine();
|
||||||
|
$token = $stream->expect(Token::NAME_TYPE);
|
||||||
|
$names = [new AssignNameExpression($token->getValue(), $token->getLine())];
|
||||||
|
$stream->expect(Token::ARROW_TYPE);
|
||||||
|
|
||||||
|
return new ArrowFunctionExpression($this->parseExpression(0), new Node($names), $line);
|
||||||
|
}
|
||||||
|
|
||||||
|
// first, determine if we are parsing an arrow function by finding => (long form)
|
||||||
|
$i = 0;
|
||||||
|
if (!$stream->look($i)->test(Token::PUNCTUATION_TYPE, '(')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
++$i;
|
||||||
|
while (true) {
|
||||||
|
// variable name
|
||||||
|
++$i;
|
||||||
|
if (!$stream->look($i)->test(Token::PUNCTUATION_TYPE, ',')) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++$i;
|
||||||
|
}
|
||||||
|
if (!$stream->look($i)->test(Token::PUNCTUATION_TYPE, ')')) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
++$i;
|
||||||
|
if (!$stream->look($i)->test(Token::ARROW_TYPE)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// yes, let's parse it properly
|
||||||
|
$token = $stream->expect(Token::PUNCTUATION_TYPE, '(');
|
||||||
|
$line = $token->getLine();
|
||||||
|
|
||||||
|
$names = [];
|
||||||
|
while (true) {
|
||||||
|
$token = $stream->expect(Token::NAME_TYPE);
|
||||||
|
$names[] = new AssignNameExpression($token->getValue(), $token->getLine());
|
||||||
|
|
||||||
|
if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$stream->expect(Token::PUNCTUATION_TYPE, ')');
|
||||||
|
$stream->expect(Token::ARROW_TYPE);
|
||||||
|
|
||||||
|
return new ArrowFunctionExpression($this->parseExpression(0), new Node($names), $line);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getPrimary()
|
protected function getPrimary()
|
||||||
{
|
{
|
||||||
$token = $this->parser->getCurrentToken();
|
$token = $this->parser->getCurrentToken();
|
||||||
@ -91,10 +172,10 @@ class Twig_ExpressionParser
|
|||||||
$class = $operator['class'];
|
$class = $operator['class'];
|
||||||
|
|
||||||
return $this->parsePostfixExpression(new $class($expr, $token->getLine()));
|
return $this->parsePostfixExpression(new $class($expr, $token->getLine()));
|
||||||
} elseif ($token->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
|
} elseif ($token->test(Token::PUNCTUATION_TYPE, '(')) {
|
||||||
$this->parser->getStream()->next();
|
$this->parser->getStream()->next();
|
||||||
$expr = $this->parseExpression();
|
$expr = $this->parseExpression();
|
||||||
$this->parser->getStream()->expect(Twig_Token::PUNCTUATION_TYPE, ')', 'An opened parenthesis is not properly closed');
|
$this->parser->getStream()->expect(Token::PUNCTUATION_TYPE, ')', 'An opened parenthesis is not properly closed');
|
||||||
|
|
||||||
return $this->parsePostfixExpression($expr);
|
return $this->parsePostfixExpression($expr);
|
||||||
}
|
}
|
||||||
@ -104,92 +185,95 @@ class Twig_ExpressionParser
|
|||||||
|
|
||||||
protected function parseConditionalExpression($expr)
|
protected function parseConditionalExpression($expr)
|
||||||
{
|
{
|
||||||
while ($this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, '?')) {
|
while ($this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, '?')) {
|
||||||
if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) {
|
if (!$this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ':')) {
|
||||||
$expr2 = $this->parseExpression();
|
$expr2 = $this->parseExpression();
|
||||||
if ($this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) {
|
if ($this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ':')) {
|
||||||
$expr3 = $this->parseExpression();
|
$expr3 = $this->parseExpression();
|
||||||
} else {
|
} else {
|
||||||
$expr3 = new Twig_Node_Expression_Constant('', $this->parser->getCurrentToken()->getLine());
|
$expr3 = new ConstantExpression('', $this->parser->getCurrentToken()->getLine());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$expr2 = $expr;
|
$expr2 = $expr;
|
||||||
$expr3 = $this->parseExpression();
|
$expr3 = $this->parseExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
$expr = new Twig_Node_Expression_Conditional($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine());
|
$expr = new ConditionalExpression($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $expr;
|
return $expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isUnary(Twig_Token $token)
|
protected function isUnary(Token $token)
|
||||||
{
|
{
|
||||||
return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]);
|
return $token->test(Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isBinary(Twig_Token $token)
|
protected function isBinary(Token $token)
|
||||||
{
|
{
|
||||||
return $token->test(Twig_Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]);
|
return $token->test(Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parsePrimaryExpression()
|
public function parsePrimaryExpression()
|
||||||
{
|
{
|
||||||
$token = $this->parser->getCurrentToken();
|
$token = $this->parser->getCurrentToken();
|
||||||
switch ($token->getType()) {
|
switch ($token->getType()) {
|
||||||
case Twig_Token::NAME_TYPE:
|
case Token::NAME_TYPE:
|
||||||
$this->parser->getStream()->next();
|
$this->parser->getStream()->next();
|
||||||
switch ($token->getValue()) {
|
switch ($token->getValue()) {
|
||||||
case 'true':
|
case 'true':
|
||||||
case 'TRUE':
|
case 'TRUE':
|
||||||
$node = new Twig_Node_Expression_Constant(true, $token->getLine());
|
$node = new ConstantExpression(true, $token->getLine());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'false':
|
case 'false':
|
||||||
case 'FALSE':
|
case 'FALSE':
|
||||||
$node = new Twig_Node_Expression_Constant(false, $token->getLine());
|
$node = new ConstantExpression(false, $token->getLine());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'none':
|
case 'none':
|
||||||
case 'NONE':
|
case 'NONE':
|
||||||
case 'null':
|
case 'null':
|
||||||
case 'NULL':
|
case 'NULL':
|
||||||
$node = new Twig_Node_Expression_Constant(null, $token->getLine());
|
$node = new ConstantExpression(null, $token->getLine());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if ('(' === $this->parser->getCurrentToken()->getValue()) {
|
if ('(' === $this->parser->getCurrentToken()->getValue()) {
|
||||||
$node = $this->getFunctionNode($token->getValue(), $token->getLine());
|
$node = $this->getFunctionNode($token->getValue(), $token->getLine());
|
||||||
} else {
|
} else {
|
||||||
$node = new Twig_Node_Expression_Name($token->getValue(), $token->getLine());
|
$node = new NameExpression($token->getValue(), $token->getLine());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Twig_Token::NUMBER_TYPE:
|
case Token::NUMBER_TYPE:
|
||||||
$this->parser->getStream()->next();
|
$this->parser->getStream()->next();
|
||||||
$node = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine());
|
$node = new ConstantExpression($token->getValue(), $token->getLine());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Twig_Token::STRING_TYPE:
|
case Token::STRING_TYPE:
|
||||||
case Twig_Token::INTERPOLATION_START_TYPE:
|
case Token::INTERPOLATION_START_TYPE:
|
||||||
$node = $this->parseStringExpression();
|
$node = $this->parseStringExpression();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Twig_Token::OPERATOR_TYPE:
|
case Token::OPERATOR_TYPE:
|
||||||
if (preg_match(Twig_Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) {
|
if (preg_match(Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) {
|
||||||
// in this context, string operators are variable names
|
// in this context, string operators are variable names
|
||||||
$this->parser->getStream()->next();
|
$this->parser->getStream()->next();
|
||||||
$node = new Twig_Node_Expression_Name($token->getValue(), $token->getLine());
|
$node = new NameExpression($token->getValue(), $token->getLine());
|
||||||
break;
|
break;
|
||||||
} elseif (isset($this->unaryOperators[$token->getValue()])) {
|
} elseif (isset($this->unaryOperators[$token->getValue()])) {
|
||||||
$class = $this->unaryOperators[$token->getValue()]['class'];
|
$class = $this->unaryOperators[$token->getValue()]['class'];
|
||||||
|
|
||||||
$ref = new ReflectionClass($class);
|
$ref = new \ReflectionClass($class);
|
||||||
$negClass = 'Twig_Node_Expression_Unary_Neg';
|
$negClass = 'Twig\Node\Expression\Unary\NegUnary';
|
||||||
$posClass = 'Twig_Node_Expression_Unary_Pos';
|
$posClass = 'Twig\Node\Expression\Unary\PosUnary';
|
||||||
if (!(in_array($ref->getName(), array($negClass, $posClass)) || $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass))) {
|
if (!(\in_array($ref->getName(), [$negClass, $posClass, 'Twig_Node_Expression_Unary_Neg', 'Twig_Node_Expression_Unary_Pos'])
|
||||||
throw new Twig_Error_Syntax(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
|
|| $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass)
|
||||||
|
|| $ref->isSubclassOf('Twig_Node_Expression_Unary_Neg') || $ref->isSubclassOf('Twig_Node_Expression_Unary_Pos'))
|
||||||
|
) {
|
||||||
|
throw new SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->parser->getStream()->next();
|
$this->parser->getStream()->next();
|
||||||
@ -199,13 +283,16 @@ class Twig_ExpressionParser
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// no break
|
||||||
default:
|
default:
|
||||||
if ($token->test(Twig_Token::PUNCTUATION_TYPE, '[')) {
|
if ($token->test(Token::PUNCTUATION_TYPE, '[')) {
|
||||||
$node = $this->parseArrayExpression();
|
$node = $this->parseArrayExpression();
|
||||||
} elseif ($token->test(Twig_Token::PUNCTUATION_TYPE, '{')) {
|
} elseif ($token->test(Token::PUNCTUATION_TYPE, '{')) {
|
||||||
$node = $this->parseHashExpression();
|
$node = $this->parseHashExpression();
|
||||||
|
} elseif ($token->test(Token::OPERATOR_TYPE, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) {
|
||||||
|
throw new SyntaxError(sprintf('Unexpected operator of value "%s". Did you try to use "===" or "!==" for strict comparison? Use "is same as(value)" instead.', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
|
||||||
} else {
|
} else {
|
||||||
throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s".', Twig_Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
|
throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,16 +303,16 @@ class Twig_ExpressionParser
|
|||||||
{
|
{
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
|
|
||||||
$nodes = array();
|
$nodes = [];
|
||||||
// a string cannot be followed by another string in a single expression
|
// a string cannot be followed by another string in a single expression
|
||||||
$nextCanBeString = true;
|
$nextCanBeString = true;
|
||||||
while (true) {
|
while (true) {
|
||||||
if ($nextCanBeString && $token = $stream->nextIf(Twig_Token::STRING_TYPE)) {
|
if ($nextCanBeString && $token = $stream->nextIf(Token::STRING_TYPE)) {
|
||||||
$nodes[] = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine());
|
$nodes[] = new ConstantExpression($token->getValue(), $token->getLine());
|
||||||
$nextCanBeString = false;
|
$nextCanBeString = false;
|
||||||
} elseif ($stream->nextIf(Twig_Token::INTERPOLATION_START_TYPE)) {
|
} elseif ($stream->nextIf(Token::INTERPOLATION_START_TYPE)) {
|
||||||
$nodes[] = $this->parseExpression();
|
$nodes[] = $this->parseExpression();
|
||||||
$stream->expect(Twig_Token::INTERPOLATION_END_TYPE);
|
$stream->expect(Token::INTERPOLATION_END_TYPE);
|
||||||
$nextCanBeString = true;
|
$nextCanBeString = true;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@ -234,7 +321,7 @@ class Twig_ExpressionParser
|
|||||||
|
|
||||||
$expr = array_shift($nodes);
|
$expr = array_shift($nodes);
|
||||||
foreach ($nodes as $node) {
|
foreach ($nodes as $node) {
|
||||||
$expr = new Twig_Node_Expression_Binary_Concat($expr, $node, $node->getTemplateLine());
|
$expr = new ConcatBinary($expr, $node, $node->getTemplateLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $expr;
|
return $expr;
|
||||||
@ -243,16 +330,16 @@ class Twig_ExpressionParser
|
|||||||
public function parseArrayExpression()
|
public function parseArrayExpression()
|
||||||
{
|
{
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, '[', 'An array element was expected');
|
$stream->expect(Token::PUNCTUATION_TYPE, '[', 'An array element was expected');
|
||||||
|
|
||||||
$node = new Twig_Node_Expression_Array(array(), $stream->getCurrent()->getLine());
|
$node = new ArrayExpression([], $stream->getCurrent()->getLine());
|
||||||
$first = true;
|
$first = true;
|
||||||
while (!$stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) {
|
while (!$stream->test(Token::PUNCTUATION_TYPE, ']')) {
|
||||||
if (!$first) {
|
if (!$first) {
|
||||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'An array element must be followed by a comma');
|
$stream->expect(Token::PUNCTUATION_TYPE, ',', 'An array element must be followed by a comma');
|
||||||
|
|
||||||
// trailing ,?
|
// trailing ,?
|
||||||
if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) {
|
if ($stream->test(Token::PUNCTUATION_TYPE, ']')) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,7 +347,7 @@ class Twig_ExpressionParser
|
|||||||
|
|
||||||
$node->addElement($this->parseExpression());
|
$node->addElement($this->parseExpression());
|
||||||
}
|
}
|
||||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ']', 'An opened array is not properly closed');
|
$stream->expect(Token::PUNCTUATION_TYPE, ']', 'An opened array is not properly closed');
|
||||||
|
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
@ -268,16 +355,16 @@ class Twig_ExpressionParser
|
|||||||
public function parseHashExpression()
|
public function parseHashExpression()
|
||||||
{
|
{
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, '{', 'A hash element was expected');
|
$stream->expect(Token::PUNCTUATION_TYPE, '{', 'A hash element was expected');
|
||||||
|
|
||||||
$node = new Twig_Node_Expression_Array(array(), $stream->getCurrent()->getLine());
|
$node = new ArrayExpression([], $stream->getCurrent()->getLine());
|
||||||
$first = true;
|
$first = true;
|
||||||
while (!$stream->test(Twig_Token::PUNCTUATION_TYPE, '}')) {
|
while (!$stream->test(Token::PUNCTUATION_TYPE, '}')) {
|
||||||
if (!$first) {
|
if (!$first) {
|
||||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'A hash value must be followed by a comma');
|
$stream->expect(Token::PUNCTUATION_TYPE, ',', 'A hash value must be followed by a comma');
|
||||||
|
|
||||||
// trailing ,?
|
// trailing ,?
|
||||||
if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '}')) {
|
if ($stream->test(Token::PUNCTUATION_TYPE, '}')) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,22 +376,22 @@ class Twig_ExpressionParser
|
|||||||
// * a string -- 'a'
|
// * a string -- 'a'
|
||||||
// * a name, which is equivalent to a string -- a
|
// * a name, which is equivalent to a string -- a
|
||||||
// * an expression, which must be enclosed in parentheses -- (1 + 2)
|
// * an expression, which must be enclosed in parentheses -- (1 + 2)
|
||||||
if (($token = $stream->nextIf(Twig_Token::STRING_TYPE)) || ($token = $stream->nextIf(Twig_Token::NAME_TYPE)) || $token = $stream->nextIf(Twig_Token::NUMBER_TYPE)) {
|
if (($token = $stream->nextIf(Token::STRING_TYPE)) || ($token = $stream->nextIf(Token::NAME_TYPE)) || $token = $stream->nextIf(Token::NUMBER_TYPE)) {
|
||||||
$key = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine());
|
$key = new ConstantExpression($token->getValue(), $token->getLine());
|
||||||
} elseif ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
|
} elseif ($stream->test(Token::PUNCTUATION_TYPE, '(')) {
|
||||||
$key = $this->parseExpression();
|
$key = $this->parseExpression();
|
||||||
} else {
|
} else {
|
||||||
$current = $stream->getCurrent();
|
$current = $stream->getCurrent();
|
||||||
|
|
||||||
throw new Twig_Error_Syntax(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s".', Twig_Token::typeToEnglish($current->getType()), $current->getValue()), $current->getLine(), $stream->getSourceContext());
|
throw new SyntaxError(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s".', Token::typeToEnglish($current->getType()), $current->getValue()), $current->getLine(), $stream->getSourceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)');
|
$stream->expect(Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)');
|
||||||
$value = $this->parseExpression();
|
$value = $this->parseExpression();
|
||||||
|
|
||||||
$node->addElement($value, $key);
|
$node->addElement($value, $key);
|
||||||
}
|
}
|
||||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, '}', 'An opened hash is not properly closed');
|
$stream->expect(Token::PUNCTUATION_TYPE, '}', 'An opened hash is not properly closed');
|
||||||
|
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
@ -313,7 +400,7 @@ class Twig_ExpressionParser
|
|||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
$token = $this->parser->getCurrentToken();
|
$token = $this->parser->getCurrentToken();
|
||||||
if ($token->getType() == Twig_Token::PUNCTUATION_TYPE) {
|
if (Token::PUNCTUATION_TYPE == $token->getType()) {
|
||||||
if ('.' == $token->getValue() || '[' == $token->getValue()) {
|
if ('.' == $token->getValue() || '[' == $token->getValue()) {
|
||||||
$node = $this->parseSubscriptExpression($node);
|
$node = $this->parseSubscriptExpression($node);
|
||||||
} elseif ('|' == $token->getValue()) {
|
} elseif ('|' == $token->getValue()) {
|
||||||
@ -334,37 +421,37 @@ class Twig_ExpressionParser
|
|||||||
switch ($name) {
|
switch ($name) {
|
||||||
case 'parent':
|
case 'parent':
|
||||||
$this->parseArguments();
|
$this->parseArguments();
|
||||||
if (!count($this->parser->getBlockStack())) {
|
if (!\count($this->parser->getBlockStack())) {
|
||||||
throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext());
|
throw new SyntaxError('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->parser->getParent() && !$this->parser->hasTraits()) {
|
if (!$this->parser->getParent() && !$this->parser->hasTraits()) {
|
||||||
throw new Twig_Error_Syntax('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext());
|
throw new SyntaxError('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $line);
|
return new ParentExpression($this->parser->peekBlockStack(), $line);
|
||||||
case 'block':
|
case 'block':
|
||||||
$args = $this->parseArguments();
|
$args = $this->parseArguments();
|
||||||
if (count($args) < 1) {
|
if (\count($args) < 1) {
|
||||||
throw new Twig_Error_Syntax('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext());
|
throw new SyntaxError('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Twig_Node_Expression_BlockReference($args->getNode(0), count($args) > 1 ? $args->getNode(1) : null, $line);
|
return new BlockReferenceExpression($args->getNode(0), \count($args) > 1 ? $args->getNode(1) : null, $line);
|
||||||
case 'attribute':
|
case 'attribute':
|
||||||
$args = $this->parseArguments();
|
$args = $this->parseArguments();
|
||||||
if (count($args) < 2) {
|
if (\count($args) < 2) {
|
||||||
throw new Twig_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext());
|
throw new SyntaxError('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : null, Twig_Template::ANY_CALL, $line);
|
return new GetAttrExpression($args->getNode(0), $args->getNode(1), \count($args) > 2 ? $args->getNode(2) : null, Template::ANY_CALL, $line);
|
||||||
default:
|
default:
|
||||||
if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) {
|
if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) {
|
||||||
$arguments = new Twig_Node_Expression_Array(array(), $line);
|
$arguments = new ArrayExpression([], $line);
|
||||||
foreach ($this->parseArguments() as $n) {
|
foreach ($this->parseArguments() as $n) {
|
||||||
$arguments->addElement($n);
|
$arguments->addElement($n);
|
||||||
}
|
}
|
||||||
|
|
||||||
$node = new Twig_Node_Expression_MethodCall($alias['node'], $alias['name'], $arguments, $line);
|
$node = new MethodCallExpression($alias['node'], $alias['name'], $arguments, $line);
|
||||||
$node->setAttribute('safe', true);
|
$node->setAttribute('safe', true);
|
||||||
|
|
||||||
return $node;
|
return $node;
|
||||||
@ -382,81 +469,81 @@ class Twig_ExpressionParser
|
|||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
$token = $stream->next();
|
$token = $stream->next();
|
||||||
$lineno = $token->getLine();
|
$lineno = $token->getLine();
|
||||||
$arguments = new Twig_Node_Expression_Array(array(), $lineno);
|
$arguments = new ArrayExpression([], $lineno);
|
||||||
$type = Twig_Template::ANY_CALL;
|
$type = Template::ANY_CALL;
|
||||||
if ($token->getValue() == '.') {
|
if ('.' == $token->getValue()) {
|
||||||
$token = $stream->next();
|
$token = $stream->next();
|
||||||
if (
|
if (
|
||||||
$token->getType() == Twig_Token::NAME_TYPE
|
Token::NAME_TYPE == $token->getType()
|
||||||
||
|
||
|
||||||
$token->getType() == Twig_Token::NUMBER_TYPE
|
Token::NUMBER_TYPE == $token->getType()
|
||||||
||
|
||
|
||||||
($token->getType() == Twig_Token::OPERATOR_TYPE && preg_match(Twig_Lexer::REGEX_NAME, $token->getValue()))
|
(Token::OPERATOR_TYPE == $token->getType() && preg_match(Lexer::REGEX_NAME, $token->getValue()))
|
||||||
) {
|
) {
|
||||||
$arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno);
|
$arg = new ConstantExpression($token->getValue(), $lineno);
|
||||||
|
|
||||||
if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
|
if ($stream->test(Token::PUNCTUATION_TYPE, '(')) {
|
||||||
$type = Twig_Template::METHOD_CALL;
|
$type = Template::METHOD_CALL;
|
||||||
foreach ($this->parseArguments() as $n) {
|
foreach ($this->parseArguments() as $n) {
|
||||||
$arguments->addElement($n);
|
$arguments->addElement($n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Twig_Error_Syntax('Expected name or number.', $lineno, $stream->getSourceContext());
|
throw new SyntaxError('Expected name or number.', $lineno, $stream->getSourceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($node instanceof Twig_Node_Expression_Name && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) {
|
if ($node instanceof NameExpression && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) {
|
||||||
if (!$arg instanceof Twig_Node_Expression_Constant) {
|
if (!$arg instanceof ConstantExpression) {
|
||||||
throw new Twig_Error_Syntax(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext());
|
throw new SyntaxError(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = $arg->getAttribute('value');
|
$name = $arg->getAttribute('value');
|
||||||
|
|
||||||
if ($this->parser->isReservedMacroName($name)) {
|
if ($this->parser->isReservedMacroName($name)) {
|
||||||
throw new Twig_Error_Syntax(sprintf('"%s" cannot be called as macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
|
throw new SyntaxError(sprintf('"%s" cannot be called as macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
$node = new Twig_Node_Expression_MethodCall($node, 'get'.$name, $arguments, $lineno);
|
$node = new MethodCallExpression($node, 'get'.$name, $arguments, $lineno);
|
||||||
$node->setAttribute('safe', true);
|
$node->setAttribute('safe', true);
|
||||||
|
|
||||||
return $node;
|
return $node;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$type = Twig_Template::ARRAY_CALL;
|
$type = Template::ARRAY_CALL;
|
||||||
|
|
||||||
// slice?
|
// slice?
|
||||||
$slice = false;
|
$slice = false;
|
||||||
if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ':')) {
|
if ($stream->test(Token::PUNCTUATION_TYPE, ':')) {
|
||||||
$slice = true;
|
$slice = true;
|
||||||
$arg = new Twig_Node_Expression_Constant(0, $token->getLine());
|
$arg = new ConstantExpression(0, $token->getLine());
|
||||||
} else {
|
} else {
|
||||||
$arg = $this->parseExpression();
|
$arg = $this->parseExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ':')) {
|
if ($stream->nextIf(Token::PUNCTUATION_TYPE, ':')) {
|
||||||
$slice = true;
|
$slice = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($slice) {
|
if ($slice) {
|
||||||
if ($stream->test(Twig_Token::PUNCTUATION_TYPE, ']')) {
|
if ($stream->test(Token::PUNCTUATION_TYPE, ']')) {
|
||||||
$length = new Twig_Node_Expression_Constant(null, $token->getLine());
|
$length = new ConstantExpression(null, $token->getLine());
|
||||||
} else {
|
} else {
|
||||||
$length = $this->parseExpression();
|
$length = $this->parseExpression();
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = $this->getFilterNodeClass('slice', $token->getLine());
|
$class = $this->getFilterNodeClass('slice', $token->getLine());
|
||||||
$arguments = new Twig_Node(array($arg, $length));
|
$arguments = new Node([$arg, $length]);
|
||||||
$filter = new $class($node, new Twig_Node_Expression_Constant('slice', $token->getLine()), $arguments, $token->getLine());
|
$filter = new $class($node, new ConstantExpression('slice', $token->getLine()), $arguments, $token->getLine());
|
||||||
|
|
||||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ']');
|
$stream->expect(Token::PUNCTUATION_TYPE, ']');
|
||||||
|
|
||||||
return $filter;
|
return $filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ']');
|
$stream->expect(Token::PUNCTUATION_TYPE, ']');
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Twig_Node_Expression_GetAttr($node, $arg, $arguments, $type, $lineno);
|
return new GetAttrExpression($node, $arg, $arguments, $type, $lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseFilterExpression($node)
|
public function parseFilterExpression($node)
|
||||||
@ -469,20 +556,20 @@ class Twig_ExpressionParser
|
|||||||
public function parseFilterExpressionRaw($node, $tag = null)
|
public function parseFilterExpressionRaw($node, $tag = null)
|
||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
$token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE);
|
$token = $this->parser->getStream()->expect(Token::NAME_TYPE);
|
||||||
|
|
||||||
$name = new Twig_Node_Expression_Constant($token->getValue(), $token->getLine());
|
$name = new ConstantExpression($token->getValue(), $token->getLine());
|
||||||
if (!$this->parser->getStream()->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
|
if (!$this->parser->getStream()->test(Token::PUNCTUATION_TYPE, '(')) {
|
||||||
$arguments = new Twig_Node();
|
$arguments = new Node();
|
||||||
} else {
|
} else {
|
||||||
$arguments = $this->parseArguments(true);
|
$arguments = $this->parseArguments(true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = $this->getFilterNodeClass($name->getAttribute('value'), $token->getLine());
|
$class = $this->getFilterNodeClass($name->getAttribute('value'), $token->getLine());
|
||||||
|
|
||||||
$node = new $class($node, $name, $arguments, $token->getLine(), $tag);
|
$node = new $class($node, $name, $arguments, $token->getLine(), $tag);
|
||||||
|
|
||||||
if (!$this->parser->getStream()->test(Twig_Token::PUNCTUATION_TYPE, '|')) {
|
if (!$this->parser->getStream()->test(Token::PUNCTUATION_TYPE, '|')) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -498,32 +585,32 @@ class Twig_ExpressionParser
|
|||||||
* @param bool $namedArguments Whether to allow named arguments or not
|
* @param bool $namedArguments Whether to allow named arguments or not
|
||||||
* @param bool $definition Whether we are parsing arguments for a function definition
|
* @param bool $definition Whether we are parsing arguments for a function definition
|
||||||
*
|
*
|
||||||
* @return Twig_Node
|
* @return Node
|
||||||
*
|
*
|
||||||
* @throws Twig_Error_Syntax
|
* @throws SyntaxError
|
||||||
*/
|
*/
|
||||||
public function parseArguments($namedArguments = false, $definition = false)
|
public function parseArguments($namedArguments = false, $definition = false, $allowArrow = false)
|
||||||
{
|
{
|
||||||
$args = array();
|
$args = [];
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
|
|
||||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis');
|
$stream->expect(Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis');
|
||||||
while (!$stream->test(Twig_Token::PUNCTUATION_TYPE, ')')) {
|
while (!$stream->test(Token::PUNCTUATION_TYPE, ')')) {
|
||||||
if (!empty($args)) {
|
if (!empty($args)) {
|
||||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma');
|
$stream->expect(Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($definition) {
|
if ($definition) {
|
||||||
$token = $stream->expect(Twig_Token::NAME_TYPE, null, 'An argument must be a name');
|
$token = $stream->expect(Token::NAME_TYPE, null, 'An argument must be a name');
|
||||||
$value = new Twig_Node_Expression_Name($token->getValue(), $this->parser->getCurrentToken()->getLine());
|
$value = new NameExpression($token->getValue(), $this->parser->getCurrentToken()->getLine());
|
||||||
} else {
|
} else {
|
||||||
$value = $this->parseExpression();
|
$value = $this->parseExpression(0, $allowArrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = null;
|
$name = null;
|
||||||
if ($namedArguments && $token = $stream->nextIf(Twig_Token::OPERATOR_TYPE, '=')) {
|
if ($namedArguments && $token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) {
|
||||||
if (!$value instanceof Twig_Node_Expression_Name) {
|
if (!$value instanceof NameExpression) {
|
||||||
throw new Twig_Error_Syntax(sprintf('A parameter name must be a string, "%s" given.', get_class($value)), $token->getLine(), $stream->getSourceContext());
|
throw new SyntaxError(sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext());
|
||||||
}
|
}
|
||||||
$name = $value->getAttribute('name');
|
$name = $value->getAttribute('name');
|
||||||
|
|
||||||
@ -531,17 +618,17 @@ class Twig_ExpressionParser
|
|||||||
$value = $this->parsePrimaryExpression();
|
$value = $this->parsePrimaryExpression();
|
||||||
|
|
||||||
if (!$this->checkConstantExpression($value)) {
|
if (!$this->checkConstantExpression($value)) {
|
||||||
throw new Twig_Error_Syntax(sprintf('A default value for an argument must be a constant (a boolean, a string, a number, or an array).'), $token->getLine(), $stream->getSourceContext());
|
throw new SyntaxError(sprintf('A default value for an argument must be a constant (a boolean, a string, a number, or an array).'), $token->getLine(), $stream->getSourceContext());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$value = $this->parseExpression();
|
$value = $this->parseExpression(0, $allowArrow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($definition) {
|
if ($definition) {
|
||||||
if (null === $name) {
|
if (null === $name) {
|
||||||
$name = $value->getAttribute('name');
|
$name = $value->getAttribute('name');
|
||||||
$value = new Twig_Node_Expression_Constant(null, $this->parser->getCurrentToken()->getLine());
|
$value = new ConstantExpression(null, $this->parser->getCurrentToken()->getLine());
|
||||||
}
|
}
|
||||||
$args[$name] = $value;
|
$args[$name] = $value;
|
||||||
} else {
|
} else {
|
||||||
@ -552,58 +639,64 @@ class Twig_ExpressionParser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis');
|
$stream->expect(Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis');
|
||||||
|
|
||||||
return new Twig_Node($args);
|
return new Node($args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseAssignmentExpression()
|
public function parseAssignmentExpression()
|
||||||
{
|
{
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
$targets = array();
|
$targets = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
$token = $stream->expect(Twig_Token::NAME_TYPE, null, 'Only variables can be assigned to');
|
$token = $this->parser->getCurrentToken();
|
||||||
$value = $token->getValue();
|
if ($stream->test(Token::OPERATOR_TYPE) && preg_match(Lexer::REGEX_NAME, $token->getValue())) {
|
||||||
if (in_array(strtolower($value), array('true', 'false', 'none', 'null'))) {
|
// in this context, string operators are variable names
|
||||||
throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext());
|
$this->parser->getStream()->next();
|
||||||
|
} else {
|
||||||
|
$stream->expect(Token::NAME_TYPE, null, 'Only variables can be assigned to');
|
||||||
}
|
}
|
||||||
$targets[] = new Twig_Node_Expression_AssignName($value, $token->getLine());
|
$value = $token->getValue();
|
||||||
|
if (\in_array(strtolower($value), ['true', 'false', 'none', 'null'])) {
|
||||||
|
throw new SyntaxError(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext());
|
||||||
|
}
|
||||||
|
$targets[] = new AssignNameExpression($value, $token->getLine());
|
||||||
|
|
||||||
if (!$stream->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
|
if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Twig_Node($targets);
|
return new Node($targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parseMultitargetExpression()
|
public function parseMultitargetExpression()
|
||||||
{
|
{
|
||||||
$targets = array();
|
$targets = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
$targets[] = $this->parseExpression();
|
$targets[] = $this->parseExpression();
|
||||||
if (!$this->parser->getStream()->nextIf(Twig_Token::PUNCTUATION_TYPE, ',')) {
|
if (!$this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ',')) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Twig_Node($targets);
|
return new Node($targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseNotTestExpression(Twig_NodeInterface $node)
|
private function parseNotTestExpression(\Twig_NodeInterface $node)
|
||||||
{
|
{
|
||||||
return new Twig_Node_Expression_Unary_Not($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine());
|
return new NotUnary($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseTestExpression(Twig_NodeInterface $node)
|
private function parseTestExpression(\Twig_NodeInterface $node)
|
||||||
{
|
{
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
list($name, $test) = $this->getTest($node->getTemplateLine());
|
list($name, $test) = $this->getTest($node->getTemplateLine());
|
||||||
|
|
||||||
$class = $this->getTestNodeClass($test);
|
$class = $this->getTestNodeClass($test);
|
||||||
$arguments = null;
|
$arguments = null;
|
||||||
if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
|
if ($stream->test(Token::PUNCTUATION_TYPE, '(')) {
|
||||||
$arguments = $this->parser->getExpressionParser()->parseArguments(true);
|
$arguments = $this->parseArguments(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new $class($node, $name, $arguments, $this->parser->getCurrentToken()->getLine());
|
return new $class($node, $name, $arguments, $this->parser->getCurrentToken()->getLine());
|
||||||
@ -612,24 +705,24 @@ class Twig_ExpressionParser
|
|||||||
private function getTest($line)
|
private function getTest($line)
|
||||||
{
|
{
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
|
$name = $stream->expect(Token::NAME_TYPE)->getValue();
|
||||||
|
|
||||||
if ($test = $this->env->getTest($name)) {
|
if ($test = $this->env->getTest($name)) {
|
||||||
return array($name, $test);
|
return [$name, $test];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($stream->test(Twig_Token::NAME_TYPE)) {
|
if ($stream->test(Token::NAME_TYPE)) {
|
||||||
// try 2-words tests
|
// try 2-words tests
|
||||||
$name = $name.' '.$this->parser->getCurrentToken()->getValue();
|
$name = $name.' '.$this->parser->getCurrentToken()->getValue();
|
||||||
|
|
||||||
if ($test = $this->env->getTest($name)) {
|
if ($test = $this->env->getTest($name)) {
|
||||||
$stream->next();
|
$stream->next();
|
||||||
|
|
||||||
return array($name, $test);
|
return [$name, $test];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$e = new Twig_Error_Syntax(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext());
|
$e = new SyntaxError(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext());
|
||||||
$e->addSuggestions($name, array_keys($this->env->getTests()));
|
$e->addSuggestions($name, array_keys($this->env->getTests()));
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
@ -637,10 +730,10 @@ class Twig_ExpressionParser
|
|||||||
|
|
||||||
private function getTestNodeClass($test)
|
private function getTestNodeClass($test)
|
||||||
{
|
{
|
||||||
if ($test instanceof Twig_SimpleTest && $test->isDeprecated()) {
|
if ($test instanceof TwigTest && $test->isDeprecated()) {
|
||||||
$stream = $this->parser->getStream();
|
$stream = $this->parser->getStream();
|
||||||
$message = sprintf('Twig Test "%s" is deprecated', $test->getName());
|
$message = sprintf('Twig Test "%s" is deprecated', $test->getName());
|
||||||
if (!is_bool($test->getDeprecatedVersion())) {
|
if (!\is_bool($test->getDeprecatedVersion())) {
|
||||||
$message .= sprintf(' since version %s', $test->getDeprecatedVersion());
|
$message .= sprintf(' since version %s', $test->getDeprecatedVersion());
|
||||||
}
|
}
|
||||||
if ($test->getAlternative()) {
|
if ($test->getAlternative()) {
|
||||||
@ -652,25 +745,25 @@ class Twig_ExpressionParser
|
|||||||
@trigger_error($message, E_USER_DEPRECATED);
|
@trigger_error($message, E_USER_DEPRECATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($test instanceof Twig_SimpleTest) {
|
if ($test instanceof TwigTest) {
|
||||||
return $test->getNodeClass();
|
return $test->getNodeClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $test instanceof Twig_Test_Node ? $test->getClass() : 'Twig_Node_Expression_Test';
|
return $test instanceof \Twig_Test_Node ? $test->getClass() : 'Twig\Node\Expression\TestExpression';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getFunctionNodeClass($name, $line)
|
protected function getFunctionNodeClass($name, $line)
|
||||||
{
|
{
|
||||||
if (false === $function = $this->env->getFunction($name)) {
|
if (false === $function = $this->env->getFunction($name)) {
|
||||||
$e = new Twig_Error_Syntax(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext());
|
$e = new SyntaxError(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext());
|
||||||
$e->addSuggestions($name, array_keys($this->env->getFunctions()));
|
$e->addSuggestions($name, array_keys($this->env->getFunctions()));
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($function instanceof Twig_SimpleFunction && $function->isDeprecated()) {
|
if ($function instanceof TwigFunction && $function->isDeprecated()) {
|
||||||
$message = sprintf('Twig Function "%s" is deprecated', $function->getName());
|
$message = sprintf('Twig Function "%s" is deprecated', $function->getName());
|
||||||
if (!is_bool($function->getDeprecatedVersion())) {
|
if (!\is_bool($function->getDeprecatedVersion())) {
|
||||||
$message .= sprintf(' since version %s', $function->getDeprecatedVersion());
|
$message .= sprintf(' since version %s', $function->getDeprecatedVersion());
|
||||||
}
|
}
|
||||||
if ($function->getAlternative()) {
|
if ($function->getAlternative()) {
|
||||||
@ -682,25 +775,25 @@ class Twig_ExpressionParser
|
|||||||
@trigger_error($message, E_USER_DEPRECATED);
|
@trigger_error($message, E_USER_DEPRECATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($function instanceof Twig_SimpleFunction) {
|
if ($function instanceof TwigFunction) {
|
||||||
return $function->getNodeClass();
|
return $function->getNodeClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $function instanceof Twig_Function_Node ? $function->getClass() : 'Twig_Node_Expression_Function';
|
return $function instanceof \Twig_Function_Node ? $function->getClass() : 'Twig\Node\Expression\FunctionExpression';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getFilterNodeClass($name, $line)
|
protected function getFilterNodeClass($name, $line)
|
||||||
{
|
{
|
||||||
if (false === $filter = $this->env->getFilter($name)) {
|
if (false === $filter = $this->env->getFilter($name)) {
|
||||||
$e = new Twig_Error_Syntax(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext());
|
$e = new SyntaxError(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext());
|
||||||
$e->addSuggestions($name, array_keys($this->env->getFilters()));
|
$e->addSuggestions($name, array_keys($this->env->getFilters()));
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($filter instanceof Twig_SimpleFilter && $filter->isDeprecated()) {
|
if ($filter instanceof TwigFilter && $filter->isDeprecated()) {
|
||||||
$message = sprintf('Twig Filter "%s" is deprecated', $filter->getName());
|
$message = sprintf('Twig Filter "%s" is deprecated', $filter->getName());
|
||||||
if (!is_bool($filter->getDeprecatedVersion())) {
|
if (!\is_bool($filter->getDeprecatedVersion())) {
|
||||||
$message .= sprintf(' since version %s', $filter->getDeprecatedVersion());
|
$message .= sprintf(' since version %s', $filter->getDeprecatedVersion());
|
||||||
}
|
}
|
||||||
if ($filter->getAlternative()) {
|
if ($filter->getAlternative()) {
|
||||||
@ -712,18 +805,18 @@ class Twig_ExpressionParser
|
|||||||
@trigger_error($message, E_USER_DEPRECATED);
|
@trigger_error($message, E_USER_DEPRECATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($filter instanceof Twig_SimpleFilter) {
|
if ($filter instanceof TwigFilter) {
|
||||||
return $filter->getNodeClass();
|
return $filter->getNodeClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $filter instanceof Twig_Filter_Node ? $filter->getClass() : 'Twig_Node_Expression_Filter';
|
return $filter instanceof \Twig_Filter_Node ? $filter->getClass() : 'Twig\Node\Expression\FilterExpression';
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks that the node only contains "constant" elements
|
// checks that the node only contains "constant" elements
|
||||||
protected function checkConstantExpression(Twig_NodeInterface $node)
|
protected function checkConstantExpression(\Twig_NodeInterface $node)
|
||||||
{
|
{
|
||||||
if (!($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array
|
if (!($node instanceof ConstantExpression || $node instanceof ArrayExpression
|
||||||
|| $node instanceof Twig_Node_Expression_Unary_Neg || $node instanceof Twig_Node_Expression_Unary_Pos
|
|| $node instanceof NegUnary || $node instanceof PosUnary
|
||||||
)) {
|
)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -738,4 +831,4 @@ class Twig_ExpressionParser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_ExpressionParser', 'Twig\ExpressionParser', false);
|
class_alias('Twig\ExpressionParser', 'Twig_ExpressionParser');
|
||||||
|
31
system/libs/Twig/Extension.php → system/libs/Twig/Extension/AbstractExtension.php
Executable file → Normal file
31
system/libs/Twig/Extension.php → system/libs/Twig/Extension/AbstractExtension.php
Executable file → Normal file
@ -9,51 +9,55 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
abstract class Twig_Extension implements Twig_ExtensionInterface
|
namespace Twig\Extension;
|
||||||
|
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
|
abstract class AbstractExtension implements ExtensionInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_InitRuntimeInterface instead
|
* @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_InitRuntimeInterface instead
|
||||||
*/
|
*/
|
||||||
public function initRuntime(Twig_Environment $environment)
|
public function initRuntime(Environment $environment)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTokenParsers()
|
public function getTokenParsers()
|
||||||
{
|
{
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNodeVisitors()
|
public function getNodeVisitors()
|
||||||
{
|
{
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTests()
|
public function getTests()
|
||||||
{
|
{
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOperators()
|
public function getOperators()
|
||||||
{
|
{
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_GlobalsInterface instead
|
* @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_GlobalsInterface instead
|
||||||
*/
|
*/
|
||||||
public function getGlobals()
|
public function getGlobals()
|
||||||
{
|
{
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,9 +65,8 @@ abstract class Twig_Extension implements Twig_ExtensionInterface
|
|||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return get_class($this);
|
return \get_class($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Extension', 'Twig\Extension\AbstractExtension', false);
|
class_alias('Twig\Extension\AbstractExtension', 'Twig_Extension');
|
||||||
class_exists('Twig_Environment');
|
|
File diff suppressed because it is too large
Load Diff
1728
system/libs/Twig/Extension/CoreExtension.php
Normal file
1728
system/libs/Twig/Extension/CoreExtension.php
Normal file
File diff suppressed because it is too large
Load Diff
39
system/libs/Twig/Extension/Debug.php → system/libs/Twig/Extension/DebugExtension.php
Executable file → Normal file
39
system/libs/Twig/Extension/Debug.php → system/libs/Twig/Extension/DebugExtension.php
Executable file → Normal file
@ -9,26 +9,29 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Extension {
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @final
|
* @final
|
||||||
*/
|
*/
|
||||||
class Twig_Extension_Debug extends Twig_Extension
|
class DebugExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
public function getFunctions()
|
public function getFunctions()
|
||||||
{
|
{
|
||||||
// dump is safe if var_dump is overridden by xdebug
|
// dump is safe if var_dump is overridden by xdebug
|
||||||
$isDumpOutputHtmlSafe = extension_loaded('xdebug')
|
$isDumpOutputHtmlSafe = \extension_loaded('xdebug')
|
||||||
// false means that it was not set (and the default is on) or it explicitly enabled
|
// false means that it was not set (and the default is on) or it explicitly enabled
|
||||||
&& (false === ini_get('xdebug.overload_var_dump') || ini_get('xdebug.overload_var_dump'))
|
&& (false === ini_get('xdebug.overload_var_dump') || ini_get('xdebug.overload_var_dump'))
|
||||||
// false means that it was not set (and the default is on) or it explicitly enabled
|
// false means that it was not set (and the default is on) or it explicitly enabled
|
||||||
// xdebug.overload_var_dump produces HTML only when html_errors is also enabled
|
// xdebug.overload_var_dump produces HTML only when html_errors is also enabled
|
||||||
&& (false === ini_get('html_errors') || ini_get('html_errors'))
|
&& (false === ini_get('html_errors') || ini_get('html_errors'))
|
||||||
|| 'cli' === PHP_SAPI
|
|| 'cli' === \PHP_SAPI
|
||||||
;
|
;
|
||||||
|
|
||||||
return array(
|
return [
|
||||||
new Twig_SimpleFunction('dump', 'twig_var_dump', array('is_safe' => $isDumpOutputHtmlSafe ? array('html') : array(), 'needs_context' => true, 'needs_environment' => true)),
|
new TwigFunction('dump', 'twig_var_dump', ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true, 'is_variadic' => true]),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
@ -37,7 +40,15 @@ class Twig_Extension_Debug extends Twig_Extension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function twig_var_dump(Twig_Environment $env, $context)
|
class_alias('Twig\Extension\DebugExtension', 'Twig_Extension_Debug');
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\Template;
|
||||||
|
use Twig\TemplateWrapper;
|
||||||
|
|
||||||
|
function twig_var_dump(Environment $env, $context, array $vars = [])
|
||||||
{
|
{
|
||||||
if (!$env->isDebug()) {
|
if (!$env->isDebug()) {
|
||||||
return;
|
return;
|
||||||
@ -45,23 +56,21 @@ function twig_var_dump(Twig_Environment $env, $context)
|
|||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
$count = func_num_args();
|
if (!$vars) {
|
||||||
if (2 === $count) {
|
$vars = [];
|
||||||
$vars = array();
|
|
||||||
foreach ($context as $key => $value) {
|
foreach ($context as $key => $value) {
|
||||||
if (!$value instanceof Twig_Template) {
|
if (!$value instanceof Template && !$value instanceof TemplateWrapper) {
|
||||||
$vars[$key] = $value;
|
$vars[$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var_dump($vars);
|
var_dump($vars);
|
||||||
} else {
|
} else {
|
||||||
for ($i = 2; $i < $count; ++$i) {
|
foreach ($vars as $var) {
|
||||||
var_dump(func_get_arg($i));
|
var_dump($var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
class_alias('Twig_Extension_Debug', 'Twig\Extension\DebugExtension', false);
|
|
30
system/libs/Twig/Extension/Escaper.php → system/libs/Twig/Extension/EscaperExtension.php
Executable file → Normal file
30
system/libs/Twig/Extension/Escaper.php → system/libs/Twig/Extension/EscaperExtension.php
Executable file → Normal file
@ -9,10 +9,15 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Extension {
|
||||||
|
use Twig\NodeVisitor\EscaperNodeVisitor;
|
||||||
|
use Twig\TokenParser\AutoEscapeTokenParser;
|
||||||
|
use Twig\TwigFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @final
|
* @final
|
||||||
*/
|
*/
|
||||||
class Twig_Extension_Escaper extends Twig_Extension
|
class EscaperExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
protected $defaultStrategy;
|
protected $defaultStrategy;
|
||||||
|
|
||||||
@ -28,19 +33,19 @@ class Twig_Extension_Escaper extends Twig_Extension
|
|||||||
|
|
||||||
public function getTokenParsers()
|
public function getTokenParsers()
|
||||||
{
|
{
|
||||||
return array(new Twig_TokenParser_AutoEscape());
|
return [new AutoEscapeTokenParser()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNodeVisitors()
|
public function getNodeVisitors()
|
||||||
{
|
{
|
||||||
return array(new Twig_NodeVisitor_Escaper());
|
return [new EscaperNodeVisitor()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
new Twig_SimpleFilter('raw', 'twig_raw_filter', array('is_safe' => array('all'))),
|
new TwigFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,7 +72,7 @@ class Twig_Extension_Escaper extends Twig_Extension
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('name' === $defaultStrategy) {
|
if ('name' === $defaultStrategy) {
|
||||||
$defaultStrategy = array('Twig_FileExtensionEscapingStrategy', 'guess');
|
$defaultStrategy = ['\Twig\FileExtensionEscapingStrategy', 'guess'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->defaultStrategy = $defaultStrategy;
|
$this->defaultStrategy = $defaultStrategy;
|
||||||
@ -84,8 +89,8 @@ class Twig_Extension_Escaper extends Twig_Extension
|
|||||||
{
|
{
|
||||||
// disable string callables to avoid calling a function named html or js,
|
// disable string callables to avoid calling a function named html or js,
|
||||||
// or any other upcoming escaping strategy
|
// or any other upcoming escaping strategy
|
||||||
if (!is_string($this->defaultStrategy) && false !== $this->defaultStrategy) {
|
if (!\is_string($this->defaultStrategy) && false !== $this->defaultStrategy) {
|
||||||
return call_user_func($this->defaultStrategy, $name);
|
return \call_user_func($this->defaultStrategy, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->defaultStrategy;
|
return $this->defaultStrategy;
|
||||||
@ -97,6 +102,10 @@ class Twig_Extension_Escaper extends Twig_Extension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class_alias('Twig\Extension\EscaperExtension', 'Twig_Extension_Escaper');
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
/**
|
/**
|
||||||
* Marks a variable as being safe.
|
* Marks a variable as being safe.
|
||||||
*
|
*
|
||||||
@ -108,5 +117,4 @@ function twig_raw_filter($string)
|
|||||||
{
|
{
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
class_alias('Twig_Extension_Escaper', 'Twig\Extension\EscaperExtension', false);
|
|
33
system/libs/Twig/ExtensionInterface.php → system/libs/Twig/Extension/ExtensionInterface.php
Executable file → Normal file
33
system/libs/Twig/ExtensionInterface.php → system/libs/Twig/Extension/ExtensionInterface.php
Executable file → Normal file
@ -9,54 +9,63 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Extension;
|
||||||
|
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\NodeVisitor\NodeVisitorInterface;
|
||||||
|
use Twig\TokenParser\TokenParserInterface;
|
||||||
|
use Twig\TwigFilter;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
use Twig\TwigTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface implemented by extension classes.
|
* Interface implemented by extension classes.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
interface Twig_ExtensionInterface
|
interface ExtensionInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Initializes the runtime environment.
|
* Initializes the runtime environment.
|
||||||
*
|
*
|
||||||
* This is where you can load some file that contains filter functions for instance.
|
* This is where you can load some file that contains filter functions for instance.
|
||||||
*
|
*
|
||||||
* @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_InitRuntimeInterface instead
|
* @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_InitRuntimeInterface instead
|
||||||
*/
|
*/
|
||||||
public function initRuntime(Twig_Environment $environment);
|
public function initRuntime(Environment $environment);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the token parser instances to add to the existing list.
|
* Returns the token parser instances to add to the existing list.
|
||||||
*
|
*
|
||||||
* @return Twig_TokenParserInterface[]
|
* @return TokenParserInterface[]
|
||||||
*/
|
*/
|
||||||
public function getTokenParsers();
|
public function getTokenParsers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the node visitor instances to add to the existing list.
|
* Returns the node visitor instances to add to the existing list.
|
||||||
*
|
*
|
||||||
* @return Twig_NodeVisitorInterface[]
|
* @return NodeVisitorInterface[]
|
||||||
*/
|
*/
|
||||||
public function getNodeVisitors();
|
public function getNodeVisitors();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of filters to add to the existing list.
|
* Returns a list of filters to add to the existing list.
|
||||||
*
|
*
|
||||||
* @return Twig_SimpleFilter[]
|
* @return TwigFilter[]
|
||||||
*/
|
*/
|
||||||
public function getFilters();
|
public function getFilters();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of tests to add to the existing list.
|
* Returns a list of tests to add to the existing list.
|
||||||
*
|
*
|
||||||
* @return Twig_SimpleTest[]
|
* @return TwigTest[]
|
||||||
*/
|
*/
|
||||||
public function getTests();
|
public function getTests();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of functions to add to the existing list.
|
* Returns a list of functions to add to the existing list.
|
||||||
*
|
*
|
||||||
* @return Twig_SimpleFunction[]
|
* @return TwigFunction[]
|
||||||
*/
|
*/
|
||||||
public function getFunctions();
|
public function getFunctions();
|
||||||
|
|
||||||
@ -72,7 +81,7 @@ interface Twig_ExtensionInterface
|
|||||||
*
|
*
|
||||||
* @return array An array of global variables
|
* @return array An array of global variables
|
||||||
*
|
*
|
||||||
* @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_GlobalsInterface instead
|
* @deprecated since 1.23 (to be removed in 2.0), implement \Twig_Extension_GlobalsInterface instead
|
||||||
*/
|
*/
|
||||||
public function getGlobals();
|
public function getGlobals();
|
||||||
|
|
||||||
@ -86,5 +95,7 @@ interface Twig_ExtensionInterface
|
|||||||
public function getName();
|
public function getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_ExtensionInterface', 'Twig\Extension\ExtensionInterface', false);
|
class_alias('Twig\Extension\ExtensionInterface', 'Twig_ExtensionInterface');
|
||||||
class_exists('Twig_Environment');
|
|
||||||
|
// Ensure that the aliased name is loaded to keep BC for classes implementing the typehint with the old aliased name.
|
||||||
|
class_exists('Twig\Environment');
|
@ -9,16 +9,18 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Extension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables usage of the deprecated Twig_Extension::getGlobals() method.
|
* Enables usage of the deprecated Twig\Extension\AbstractExtension::getGlobals() method.
|
||||||
*
|
*
|
||||||
* Explicitly implement this interface if you really need to implement the
|
* Explicitly implement this interface if you really need to implement the
|
||||||
* deprecated getGlobals() method in your extensions.
|
* deprecated getGlobals() method in your extensions.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
interface Twig_Extension_GlobalsInterface
|
interface GlobalsInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Extension_GlobalsInterface', 'Twig\Extension\GlobalsInterface', false);
|
class_alias('Twig\Extension\GlobalsInterface', 'Twig_Extension_GlobalsInterface');
|
||||||
|
@ -9,16 +9,18 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Extension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables usage of the deprecated Twig_Extension::initRuntime() method.
|
* Enables usage of the deprecated Twig\Extension\AbstractExtension::initRuntime() method.
|
||||||
*
|
*
|
||||||
* Explicitly implement this interface if you really need to implement the
|
* Explicitly implement this interface if you really need to implement the
|
||||||
* deprecated initRuntime() method in your extensions.
|
* deprecated initRuntime() method in your extensions.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
interface Twig_Extension_InitRuntimeInterface
|
interface InitRuntimeInterface
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Extension_InitRuntimeInterface', 'Twig\Extension\InitRuntimeInterface', false);
|
class_alias('Twig\Extension\InitRuntimeInterface', 'Twig_Extension_InitRuntimeInterface');
|
||||||
|
10
system/libs/Twig/Extension/Optimizer.php → system/libs/Twig/Extension/OptimizerExtension.php
Executable file → Normal file
10
system/libs/Twig/Extension/Optimizer.php → system/libs/Twig/Extension/OptimizerExtension.php
Executable file → Normal file
@ -9,10 +9,14 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Extension;
|
||||||
|
|
||||||
|
use Twig\NodeVisitor\OptimizerNodeVisitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @final
|
* @final
|
||||||
*/
|
*/
|
||||||
class Twig_Extension_Optimizer extends Twig_Extension
|
class OptimizerExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
protected $optimizers;
|
protected $optimizers;
|
||||||
|
|
||||||
@ -23,7 +27,7 @@ class Twig_Extension_Optimizer extends Twig_Extension
|
|||||||
|
|
||||||
public function getNodeVisitors()
|
public function getNodeVisitors()
|
||||||
{
|
{
|
||||||
return array(new Twig_NodeVisitor_Optimizer($this->optimizers));
|
return [new OptimizerNodeVisitor($this->optimizers)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
@ -32,4 +36,4 @@ class Twig_Extension_Optimizer extends Twig_Extension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Extension_Optimizer', 'Twig\Extension\OptimizerExtension', false);
|
class_alias('Twig\Extension\OptimizerExtension', 'Twig_Extension_Optimizer');
|
24
system/libs/Twig/Extension/Profiler.php → system/libs/Twig/Extension/ProfilerExtension.php
Executable file → Normal file
24
system/libs/Twig/Extension/Profiler.php → system/libs/Twig/Extension/ProfilerExtension.php
Executable file → Normal file
@ -9,34 +9,39 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Twig_Extension_Profiler extends Twig_Extension
|
namespace Twig\Extension;
|
||||||
{
|
|
||||||
private $actives = array();
|
|
||||||
|
|
||||||
public function __construct(Twig_Profiler_Profile $profile)
|
use Twig\Profiler\NodeVisitor\ProfilerNodeVisitor;
|
||||||
|
use Twig\Profiler\Profile;
|
||||||
|
|
||||||
|
class ProfilerExtension extends AbstractExtension
|
||||||
|
{
|
||||||
|
private $actives = [];
|
||||||
|
|
||||||
|
public function __construct(Profile $profile)
|
||||||
{
|
{
|
||||||
$this->actives[] = $profile;
|
$this->actives[] = $profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enter(Twig_Profiler_Profile $profile)
|
public function enter(Profile $profile)
|
||||||
{
|
{
|
||||||
$this->actives[0]->addProfile($profile);
|
$this->actives[0]->addProfile($profile);
|
||||||
array_unshift($this->actives, $profile);
|
array_unshift($this->actives, $profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function leave(Twig_Profiler_Profile $profile)
|
public function leave(Profile $profile)
|
||||||
{
|
{
|
||||||
$profile->leave();
|
$profile->leave();
|
||||||
array_shift($this->actives);
|
array_shift($this->actives);
|
||||||
|
|
||||||
if (1 === count($this->actives)) {
|
if (1 === \count($this->actives)) {
|
||||||
$this->actives[0]->leave();
|
$this->actives[0]->leave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNodeVisitors()
|
public function getNodeVisitors()
|
||||||
{
|
{
|
||||||
return array(new Twig_Profiler_NodeVisitor_Profiler(get_class($this)));
|
return [new ProfilerNodeVisitor(\get_class($this))];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
@ -45,5 +50,4 @@ class Twig_Extension_Profiler extends Twig_Extension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Extension_Profiler', 'Twig\Extension\ProfilerExtension', false);
|
class_alias('Twig\Extension\ProfilerExtension', 'Twig_Extension_Profiler');
|
||||||
class_exists('Twig_Profiler_Profile');
|
|
19
system/libs/Twig/Extension/RuntimeExtensionInterface.php
Normal file
19
system/libs/Twig/Extension/RuntimeExtensionInterface.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?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\Extension;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||||
|
*/
|
||||||
|
interface RuntimeExtensionInterface
|
||||||
|
{
|
||||||
|
}
|
20
system/libs/Twig/Extension/Sandbox.php → system/libs/Twig/Extension/SandboxExtension.php
Executable file → Normal file
20
system/libs/Twig/Extension/Sandbox.php → system/libs/Twig/Extension/SandboxExtension.php
Executable file → Normal file
@ -9,16 +9,22 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Extension;
|
||||||
|
|
||||||
|
use Twig\NodeVisitor\SandboxNodeVisitor;
|
||||||
|
use Twig\Sandbox\SecurityPolicyInterface;
|
||||||
|
use Twig\TokenParser\SandboxTokenParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @final
|
* @final
|
||||||
*/
|
*/
|
||||||
class Twig_Extension_Sandbox extends Twig_Extension
|
class SandboxExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
protected $sandboxedGlobally;
|
protected $sandboxedGlobally;
|
||||||
protected $sandboxed;
|
protected $sandboxed;
|
||||||
protected $policy;
|
protected $policy;
|
||||||
|
|
||||||
public function __construct(Twig_Sandbox_SecurityPolicyInterface $policy, $sandboxed = false)
|
public function __construct(SecurityPolicyInterface $policy, $sandboxed = false)
|
||||||
{
|
{
|
||||||
$this->policy = $policy;
|
$this->policy = $policy;
|
||||||
$this->sandboxedGlobally = $sandboxed;
|
$this->sandboxedGlobally = $sandboxed;
|
||||||
@ -26,12 +32,12 @@ class Twig_Extension_Sandbox extends Twig_Extension
|
|||||||
|
|
||||||
public function getTokenParsers()
|
public function getTokenParsers()
|
||||||
{
|
{
|
||||||
return array(new Twig_TokenParser_Sandbox());
|
return [new SandboxTokenParser()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNodeVisitors()
|
public function getNodeVisitors()
|
||||||
{
|
{
|
||||||
return array(new Twig_NodeVisitor_Sandbox());
|
return [new SandboxNodeVisitor()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enableSandbox()
|
public function enableSandbox()
|
||||||
@ -54,7 +60,7 @@ class Twig_Extension_Sandbox extends Twig_Extension
|
|||||||
return $this->sandboxedGlobally;
|
return $this->sandboxedGlobally;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSecurityPolicy(Twig_Sandbox_SecurityPolicyInterface $policy)
|
public function setSecurityPolicy(SecurityPolicyInterface $policy)
|
||||||
{
|
{
|
||||||
$this->policy = $policy;
|
$this->policy = $policy;
|
||||||
}
|
}
|
||||||
@ -87,7 +93,7 @@ class Twig_Extension_Sandbox extends Twig_Extension
|
|||||||
|
|
||||||
public function ensureToStringAllowed($obj)
|
public function ensureToStringAllowed($obj)
|
||||||
{
|
{
|
||||||
if ($this->isSandboxed() && is_object($obj)) {
|
if ($this->isSandboxed() && \is_object($obj) && method_exists($obj, '__toString')) {
|
||||||
$this->policy->checkMethodAllowed($obj, '__toString');
|
$this->policy->checkMethodAllowed($obj, '__toString');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,4 +106,4 @@ class Twig_Extension_Sandbox extends Twig_Extension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Extension_Sandbox', 'Twig\Extension\SandboxExtension', false);
|
class_alias('Twig\Extension\SandboxExtension', 'Twig_Extension_Sandbox');
|
27
system/libs/Twig/Extension/Staging.php → system/libs/Twig/Extension/StagingExtension.php
Executable file → Normal file
27
system/libs/Twig/Extension/Staging.php → system/libs/Twig/Extension/StagingExtension.php
Executable file → Normal file
@ -9,23 +9,28 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Extension;
|
||||||
|
|
||||||
|
use Twig\NodeVisitor\NodeVisitorInterface;
|
||||||
|
use Twig\TokenParser\TokenParserInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal class.
|
* Internal class.
|
||||||
*
|
*
|
||||||
* This class is used by Twig_Environment as a staging area and must not be used directly.
|
* This class is used by \Twig\Environment as a staging area and must not be used directly.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class Twig_Extension_Staging extends Twig_Extension
|
class StagingExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
protected $functions = array();
|
protected $functions = [];
|
||||||
protected $filters = array();
|
protected $filters = [];
|
||||||
protected $visitors = array();
|
protected $visitors = [];
|
||||||
protected $tokenParsers = array();
|
protected $tokenParsers = [];
|
||||||
protected $globals = array();
|
protected $globals = [];
|
||||||
protected $tests = array();
|
protected $tests = [];
|
||||||
|
|
||||||
public function addFunction($name, $function)
|
public function addFunction($name, $function)
|
||||||
{
|
{
|
||||||
@ -55,7 +60,7 @@ class Twig_Extension_Staging extends Twig_Extension
|
|||||||
return $this->filters;
|
return $this->filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addNodeVisitor(Twig_NodeVisitorInterface $visitor)
|
public function addNodeVisitor(NodeVisitorInterface $visitor)
|
||||||
{
|
{
|
||||||
$this->visitors[] = $visitor;
|
$this->visitors[] = $visitor;
|
||||||
}
|
}
|
||||||
@ -65,7 +70,7 @@ class Twig_Extension_Staging extends Twig_Extension
|
|||||||
return $this->visitors;
|
return $this->visitors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addTokenParser(Twig_TokenParserInterface $parser)
|
public function addTokenParser(TokenParserInterface $parser)
|
||||||
{
|
{
|
||||||
if (isset($this->tokenParsers[$parser->getTag()])) {
|
if (isset($this->tokenParsers[$parser->getTag()])) {
|
||||||
@trigger_error(sprintf('Overriding tag "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $parser->getTag()), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Overriding tag "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $parser->getTag()), E_USER_DEPRECATED);
|
||||||
@ -109,4 +114,4 @@ class Twig_Extension_Staging extends Twig_Extension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Extension_Staging', 'Twig\Extension\StagingExtension', false);
|
class_alias('Twig\Extension\StagingExtension', 'Twig_Extension_Staging');
|
@ -1,47 +0,0 @@
|
|||||||
<?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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @final
|
|
||||||
*/
|
|
||||||
class Twig_Extension_StringLoader extends Twig_Extension
|
|
||||||
{
|
|
||||||
public function getFunctions()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
new Twig_SimpleFunction('template_from_string', 'twig_template_from_string', array('needs_environment' => true)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return 'string_loader';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a template from a string.
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* {{ include(template_from_string("Hello {{ name }}")) }}
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @param Twig_Environment $env A Twig_Environment instance
|
|
||||||
* @param string $template A template as a string or object implementing __toString()
|
|
||||||
*
|
|
||||||
* @return Twig_Template
|
|
||||||
*/
|
|
||||||
function twig_template_from_string(Twig_Environment $env, $template)
|
|
||||||
{
|
|
||||||
return $env->createTemplate((string) $template);
|
|
||||||
}
|
|
||||||
|
|
||||||
class_alias('Twig_Extension_StringLoader', 'Twig\Extension\StringLoaderExtension', false);
|
|
54
system/libs/Twig/Extension/StringLoaderExtension.php
Normal file
54
system/libs/Twig/Extension/StringLoaderExtension.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?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\Extension {
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @final
|
||||||
|
*/
|
||||||
|
class StringLoaderExtension extends AbstractExtension
|
||||||
|
{
|
||||||
|
public function getFunctions()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new TwigFunction('template_from_string', 'twig_template_from_string', ['needs_environment' => true]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return 'string_loader';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class_alias('Twig\Extension\StringLoaderExtension', 'Twig_Extension_StringLoader');
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
use Twig\Environment;
|
||||||
|
use Twig\TemplateWrapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a template from a string.
|
||||||
|
*
|
||||||
|
* {{ include(template_from_string("Hello {{ name }}")) }}
|
||||||
|
*
|
||||||
|
* @param string $template A template as a string or object implementing __toString()
|
||||||
|
* @param string $name An optional name of the template to be used in error messages
|
||||||
|
*
|
||||||
|
* @return TemplateWrapper
|
||||||
|
*/
|
||||||
|
function twig_template_from_string(Environment $env, $template, $name = null)
|
||||||
|
{
|
||||||
|
return $env->createTemplate((string) $template, $name);
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,8 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default autoescaping strategy based on file names.
|
* Default autoescaping strategy based on file names.
|
||||||
*
|
*
|
||||||
@ -20,7 +22,7 @@
|
|||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_FileExtensionEscapingStrategy
|
class FileExtensionEscapingStrategy
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Guesses the best autoescaping strategy based on the file name.
|
* Guesses the best autoescaping strategy based on the file name.
|
||||||
@ -31,7 +33,7 @@ class Twig_FileExtensionEscapingStrategy
|
|||||||
*/
|
*/
|
||||||
public static function guess($name)
|
public static function guess($name)
|
||||||
{
|
{
|
||||||
if (in_array(substr($name, -1), array('/', '\\'))) {
|
if (\in_array(substr($name, -1), ['/', '\\'])) {
|
||||||
return 'html'; // return html for directories
|
return 'html'; // return html for directories
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,4 +59,4 @@ class Twig_FileExtensionEscapingStrategy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_FileExtensionEscapingStrategy', 'Twig\FileExtensionEscapingStrategy', false);
|
class_alias('Twig\FileExtensionEscapingStrategy', 'Twig_FileExtensionEscapingStrategy');
|
||||||
|
@ -10,12 +10,16 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig;
|
||||||
|
|
||||||
|
use Twig\Error\SyntaxError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lexes a template string.
|
* Lexes a template string.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Lexer implements Twig_LexerInterface
|
class Lexer implements \Twig_LexerInterface
|
||||||
{
|
{
|
||||||
protected $tokens;
|
protected $tokens;
|
||||||
protected $code;
|
protected $code;
|
||||||
@ -43,43 +47,124 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
const STATE_INTERPOLATION = 4;
|
const STATE_INTERPOLATION = 4;
|
||||||
|
|
||||||
const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A';
|
const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A';
|
||||||
const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?/A';
|
const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?([Ee][\+\-][0-9]+)?/A';
|
||||||
const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As';
|
const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As';
|
||||||
const REGEX_DQ_STRING_DELIM = '/"/A';
|
const REGEX_DQ_STRING_DELIM = '/"/A';
|
||||||
const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As';
|
const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As';
|
||||||
const PUNCTUATION = '()[]{}?:.,|';
|
const PUNCTUATION = '()[]{}?:.,|';
|
||||||
|
|
||||||
public function __construct(Twig_Environment $env, array $options = array())
|
public function __construct(Environment $env, array $options = [])
|
||||||
{
|
{
|
||||||
$this->env = $env;
|
$this->env = $env;
|
||||||
|
|
||||||
$this->options = array_merge(array(
|
$this->options = array_merge([
|
||||||
'tag_comment' => array('{#', '#}'),
|
'tag_comment' => ['{#', '#}'],
|
||||||
'tag_block' => array('{%', '%}'),
|
'tag_block' => ['{%', '%}'],
|
||||||
'tag_variable' => array('{{', '}}'),
|
'tag_variable' => ['{{', '}}'],
|
||||||
'whitespace_trim' => '-',
|
'whitespace_trim' => '-',
|
||||||
'interpolation' => array('#{', '}'),
|
'whitespace_line_trim' => '~',
|
||||||
), $options);
|
'whitespace_line_chars' => ' \t\0\x0B',
|
||||||
|
'interpolation' => ['#{', '}'],
|
||||||
|
], $options);
|
||||||
|
|
||||||
|
// when PHP 7.3 is the min version, we will be able to remove the '#' part in preg_quote as it's part of the default
|
||||||
|
$this->regexes = [
|
||||||
|
// }}
|
||||||
|
'lex_var' => '{
|
||||||
|
\s*
|
||||||
|
(?:'.
|
||||||
|
preg_quote($this->options['whitespace_trim'].$this->options['tag_variable'][1], '#').'\s*'. // -}}\s*
|
||||||
|
'|'.
|
||||||
|
preg_quote($this->options['whitespace_line_trim'].$this->options['tag_variable'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~}}[ \t\0\x0B]*
|
||||||
|
'|'.
|
||||||
|
preg_quote($this->options['tag_variable'][1], '#'). // }}
|
||||||
|
')
|
||||||
|
}Ax',
|
||||||
|
|
||||||
|
// %}
|
||||||
|
'lex_block' => '{
|
||||||
|
\s*
|
||||||
|
(?:'.
|
||||||
|
preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*\n?'. // -%}\s*\n?
|
||||||
|
'|'.
|
||||||
|
preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]*
|
||||||
|
'|'.
|
||||||
|
preg_quote($this->options['tag_block'][1], '#').'\n?'. // %}\n?
|
||||||
|
')
|
||||||
|
}Ax',
|
||||||
|
|
||||||
|
// {% endverbatim %}
|
||||||
|
'lex_raw_data' => '{'.
|
||||||
|
preg_quote($this->options['tag_block'][0], '#'). // {%
|
||||||
|
'('.
|
||||||
|
$this->options['whitespace_trim']. // -
|
||||||
|
'|'.
|
||||||
|
$this->options['whitespace_line_trim']. // ~
|
||||||
|
')?\s*'.
|
||||||
|
'(?:end%s)'. // endraw or endverbatim
|
||||||
|
'\s*'.
|
||||||
|
'(?:'.
|
||||||
|
preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*'. // -%}
|
||||||
|
'|'.
|
||||||
|
preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]*
|
||||||
|
'|'.
|
||||||
|
preg_quote($this->options['tag_block'][1], '#'). // %}
|
||||||
|
')
|
||||||
|
}sx',
|
||||||
|
|
||||||
$this->regexes = array(
|
|
||||||
'lex_var' => '/\s*'.preg_quote($this->options['whitespace_trim'].$this->options['tag_variable'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_variable'][1], '/').'/A',
|
|
||||||
'lex_block' => '/\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')\n?/A',
|
|
||||||
'lex_raw_data' => '/('.preg_quote($this->options['tag_block'][0].$this->options['whitespace_trim'], '/').'|'.preg_quote($this->options['tag_block'][0], '/').')\s*(?:end%s)\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/s',
|
|
||||||
'operator' => $this->getOperatorRegex(),
|
'operator' => $this->getOperatorRegex(),
|
||||||
'lex_comment' => '/(?:'.preg_quote($this->options['whitespace_trim'], '/').preg_quote($this->options['tag_comment'][1], '/').'\s*|'.preg_quote($this->options['tag_comment'][1], '/').')\n?/s',
|
|
||||||
'lex_block_raw' => '/\s*(raw|verbatim)\s*(?:'.preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '/').'\s*|\s*'.preg_quote($this->options['tag_block'][1], '/').')/As',
|
// #}
|
||||||
'lex_block_line' => '/\s*line\s+(\d+)\s*'.preg_quote($this->options['tag_block'][1], '/').'/As',
|
'lex_comment' => '{
|
||||||
'lex_tokens_start' => '/('.preg_quote($this->options['tag_variable'][0], '/').'|'.preg_quote($this->options['tag_block'][0], '/').'|'.preg_quote($this->options['tag_comment'][0], '/').')('.preg_quote($this->options['whitespace_trim'], '/').')?/s',
|
(?:'.
|
||||||
'interpolation_start' => '/'.preg_quote($this->options['interpolation'][0], '/').'\s*/A',
|
preg_quote($this->options['whitespace_trim']).preg_quote($this->options['tag_comment'][1], '#').'\s*\n?'. // -#}\s*\n?
|
||||||
'interpolation_end' => '/\s*'.preg_quote($this->options['interpolation'][1], '/').'/A',
|
'|'.
|
||||||
);
|
preg_quote($this->options['whitespace_line_trim'].$this->options['tag_comment'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~#}[ \t\0\x0B]*
|
||||||
|
'|'.
|
||||||
|
preg_quote($this->options['tag_comment'][1], '#').'\n?'. // #}\n?
|
||||||
|
')
|
||||||
|
}sx',
|
||||||
|
|
||||||
|
// verbatim %}
|
||||||
|
'lex_block_raw' => '{
|
||||||
|
\s*
|
||||||
|
(raw|verbatim)
|
||||||
|
\s*
|
||||||
|
(?:'.
|
||||||
|
preg_quote($this->options['whitespace_trim'].$this->options['tag_block'][1], '#').'\s*'. // -%}\s*
|
||||||
|
'|'.
|
||||||
|
preg_quote($this->options['whitespace_line_trim'].$this->options['tag_block'][1], '#').'['.$this->options['whitespace_line_chars'].']*'. // ~%}[ \t\0\x0B]*
|
||||||
|
'|'.
|
||||||
|
preg_quote($this->options['tag_block'][1], '#'). // %}
|
||||||
|
')
|
||||||
|
}Asx',
|
||||||
|
|
||||||
|
'lex_block_line' => '{\s*line\s+(\d+)\s*'.preg_quote($this->options['tag_block'][1], '#').'}As',
|
||||||
|
|
||||||
|
// {{ or {% or {#
|
||||||
|
'lex_tokens_start' => '{
|
||||||
|
('.
|
||||||
|
preg_quote($this->options['tag_variable'][0], '#'). // {{
|
||||||
|
'|'.
|
||||||
|
preg_quote($this->options['tag_block'][0], '#'). // {%
|
||||||
|
'|'.
|
||||||
|
preg_quote($this->options['tag_comment'][0], '#'). // {#
|
||||||
|
')('.
|
||||||
|
preg_quote($this->options['whitespace_trim'], '#'). // -
|
||||||
|
'|'.
|
||||||
|
preg_quote($this->options['whitespace_line_trim'], '#'). // ~
|
||||||
|
')?
|
||||||
|
}sx',
|
||||||
|
'interpolation_start' => '{'.preg_quote($this->options['interpolation'][0], '#').'\s*}A',
|
||||||
|
'interpolation_end' => '{\s*'.preg_quote($this->options['interpolation'][1], '#').'}A',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tokenize($code, $name = null)
|
public function tokenize($code, $name = null)
|
||||||
{
|
{
|
||||||
if (!$code instanceof Twig_Source) {
|
if (!$code instanceof Source) {
|
||||||
@trigger_error(sprintf('Passing a string as the $code argument of %s() is deprecated since version 1.27 and will be removed in 2.0. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Passing a string as the $code argument of %s() is deprecated since version 1.27 and will be removed in 2.0. Pass a \Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED);
|
||||||
$this->source = new Twig_Source($code, $name);
|
$this->source = new Source($code, $name);
|
||||||
} else {
|
} else {
|
||||||
$this->source = $code;
|
$this->source = $code;
|
||||||
}
|
}
|
||||||
@ -88,22 +173,22 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
@trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', E_USER_DEPRECATED);
|
@trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', E_USER_DEPRECATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
|
if (\function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
|
||||||
$mbEncoding = mb_internal_encoding();
|
$mbEncoding = mb_internal_encoding();
|
||||||
mb_internal_encoding('ASCII');
|
mb_internal_encoding('ASCII');
|
||||||
} else {
|
} else {
|
||||||
$mbEncoding = null;
|
$mbEncoding = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->code = str_replace(array("\r\n", "\r"), "\n", $this->source->getCode());
|
$this->code = str_replace(["\r\n", "\r"], "\n", $this->source->getCode());
|
||||||
$this->filename = $this->source->getName();
|
$this->filename = $this->source->getName();
|
||||||
$this->cursor = 0;
|
$this->cursor = 0;
|
||||||
$this->lineno = 1;
|
$this->lineno = 1;
|
||||||
$this->end = strlen($this->code);
|
$this->end = \strlen($this->code);
|
||||||
$this->tokens = array();
|
$this->tokens = [];
|
||||||
$this->state = self::STATE_DATA;
|
$this->state = self::STATE_DATA;
|
||||||
$this->states = array();
|
$this->states = [];
|
||||||
$this->brackets = array();
|
$this->brackets = [];
|
||||||
$this->position = -1;
|
$this->position = -1;
|
||||||
|
|
||||||
// find all token starts in one go
|
// find all token starts in one go
|
||||||
@ -136,25 +221,25 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pushToken(Twig_Token::EOF_TYPE);
|
$this->pushToken(Token::EOF_TYPE);
|
||||||
|
|
||||||
if (!empty($this->brackets)) {
|
if (!empty($this->brackets)) {
|
||||||
list($expect, $lineno) = array_pop($this->brackets);
|
list($expect, $lineno) = array_pop($this->brackets);
|
||||||
throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
|
throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mbEncoding) {
|
if ($mbEncoding) {
|
||||||
mb_internal_encoding($mbEncoding);
|
mb_internal_encoding($mbEncoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Twig_TokenStream($this->tokens, $this->source);
|
return new TokenStream($this->tokens, $this->source);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function lexData()
|
protected function lexData()
|
||||||
{
|
{
|
||||||
// if no matches are left we return the rest of the template as simple text token
|
// if no matches are left we return the rest of the template as simple text token
|
||||||
if ($this->position == count($this->positions[0]) - 1) {
|
if ($this->position == \count($this->positions[0]) - 1) {
|
||||||
$this->pushToken(Twig_Token::TEXT_TYPE, substr($this->code, $this->cursor));
|
$this->pushToken(Token::TEXT_TYPE, substr($this->code, $this->cursor));
|
||||||
$this->cursor = $this->end;
|
$this->cursor = $this->end;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -163,7 +248,7 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
// Find the first token after the current cursor
|
// Find the first token after the current cursor
|
||||||
$position = $this->positions[0][++$this->position];
|
$position = $this->positions[0][++$this->position];
|
||||||
while ($position[1] < $this->cursor) {
|
while ($position[1] < $this->cursor) {
|
||||||
if ($this->position == count($this->positions[0]) - 1) {
|
if ($this->position == \count($this->positions[0]) - 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$position = $this->positions[0][++$this->position];
|
$position = $this->positions[0][++$this->position];
|
||||||
@ -171,10 +256,19 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
|
|
||||||
// push the template text first
|
// push the template text first
|
||||||
$text = $textContent = substr($this->code, $this->cursor, $position[1] - $this->cursor);
|
$text = $textContent = substr($this->code, $this->cursor, $position[1] - $this->cursor);
|
||||||
|
|
||||||
|
// trim?
|
||||||
if (isset($this->positions[2][$this->position][0])) {
|
if (isset($this->positions[2][$this->position][0])) {
|
||||||
$text = rtrim($text);
|
if ($this->options['whitespace_trim'] === $this->positions[2][$this->position][0]) {
|
||||||
|
// whitespace_trim detected ({%-, {{- or {#-)
|
||||||
|
$text = rtrim($text);
|
||||||
|
} elseif ($this->options['whitespace_line_trim'] === $this->positions[2][$this->position][0]) {
|
||||||
|
// whitespace_line_trim detected ({%~, {{~ or {#~)
|
||||||
|
// don't trim \r and \n
|
||||||
|
$text = rtrim($text, " \t\0\x0B");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->pushToken(Twig_Token::TEXT_TYPE, $text);
|
$this->pushToken(Token::TEXT_TYPE, $text);
|
||||||
$this->moveCursor($textContent.$position[0]);
|
$this->moveCursor($textContent.$position[0]);
|
||||||
|
|
||||||
switch ($this->positions[1][$this->position][0]) {
|
switch ($this->positions[1][$this->position][0]) {
|
||||||
@ -184,22 +278,22 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
|
|
||||||
case $this->options['tag_block'][0]:
|
case $this->options['tag_block'][0]:
|
||||||
// raw data?
|
// raw data?
|
||||||
if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, null, $this->cursor)) {
|
if (preg_match($this->regexes['lex_block_raw'], $this->code, $match, 0, $this->cursor)) {
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
$this->lexRawData($match[1]);
|
$this->lexRawData($match[1]);
|
||||||
// {% line \d+ %}
|
// {% line \d+ %}
|
||||||
} elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, null, $this->cursor)) {
|
} elseif (preg_match($this->regexes['lex_block_line'], $this->code, $match, 0, $this->cursor)) {
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
$this->lineno = (int) $match[1];
|
$this->lineno = (int) $match[1];
|
||||||
} else {
|
} else {
|
||||||
$this->pushToken(Twig_Token::BLOCK_START_TYPE);
|
$this->pushToken(Token::BLOCK_START_TYPE);
|
||||||
$this->pushState(self::STATE_BLOCK);
|
$this->pushState(self::STATE_BLOCK);
|
||||||
$this->currentVarBlockLine = $this->lineno;
|
$this->currentVarBlockLine = $this->lineno;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case $this->options['tag_variable'][0]:
|
case $this->options['tag_variable'][0]:
|
||||||
$this->pushToken(Twig_Token::VAR_START_TYPE);
|
$this->pushToken(Token::VAR_START_TYPE);
|
||||||
$this->pushState(self::STATE_VAR);
|
$this->pushState(self::STATE_VAR);
|
||||||
$this->currentVarBlockLine = $this->lineno;
|
$this->currentVarBlockLine = $this->lineno;
|
||||||
break;
|
break;
|
||||||
@ -208,8 +302,8 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
|
|
||||||
protected function lexBlock()
|
protected function lexBlock()
|
||||||
{
|
{
|
||||||
if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, null, $this->cursor)) {
|
if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, 0, $this->cursor)) {
|
||||||
$this->pushToken(Twig_Token::BLOCK_END_TYPE);
|
$this->pushToken(Token::BLOCK_END_TYPE);
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
$this->popState();
|
$this->popState();
|
||||||
} else {
|
} else {
|
||||||
@ -219,8 +313,8 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
|
|
||||||
protected function lexVar()
|
protected function lexVar()
|
||||||
{
|
{
|
||||||
if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, null, $this->cursor)) {
|
if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, 0, $this->cursor)) {
|
||||||
$this->pushToken(Twig_Token::VAR_END_TYPE);
|
$this->pushToken(Token::VAR_END_TYPE);
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
$this->popState();
|
$this->popState();
|
||||||
} else {
|
} else {
|
||||||
@ -231,68 +325,73 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
protected function lexExpression()
|
protected function lexExpression()
|
||||||
{
|
{
|
||||||
// whitespace
|
// whitespace
|
||||||
if (preg_match('/\s+/A', $this->code, $match, null, $this->cursor)) {
|
if (preg_match('/\s+/A', $this->code, $match, 0, $this->cursor)) {
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
|
|
||||||
if ($this->cursor >= $this->end) {
|
if ($this->cursor >= $this->end) {
|
||||||
throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $this->state === self::STATE_BLOCK ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source);
|
throw new SyntaxError(sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// arrow function
|
||||||
|
if ('=' === $this->code[$this->cursor] && '>' === $this->code[$this->cursor + 1]) {
|
||||||
|
$this->pushToken(Token::ARROW_TYPE, '=>');
|
||||||
|
$this->moveCursor('=>');
|
||||||
|
}
|
||||||
// operators
|
// operators
|
||||||
if (preg_match($this->regexes['operator'], $this->code, $match, null, $this->cursor)) {
|
elseif (preg_match($this->regexes['operator'], $this->code, $match, 0, $this->cursor)) {
|
||||||
$this->pushToken(Twig_Token::OPERATOR_TYPE, preg_replace('/\s+/', ' ', $match[0]));
|
$this->pushToken(Token::OPERATOR_TYPE, preg_replace('/\s+/', ' ', $match[0]));
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
}
|
}
|
||||||
// names
|
// names
|
||||||
elseif (preg_match(self::REGEX_NAME, $this->code, $match, null, $this->cursor)) {
|
elseif (preg_match(self::REGEX_NAME, $this->code, $match, 0, $this->cursor)) {
|
||||||
$this->pushToken(Twig_Token::NAME_TYPE, $match[0]);
|
$this->pushToken(Token::NAME_TYPE, $match[0]);
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
}
|
}
|
||||||
// numbers
|
// numbers
|
||||||
elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, null, $this->cursor)) {
|
elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, 0, $this->cursor)) {
|
||||||
$number = (float) $match[0]; // floats
|
$number = (float) $match[0]; // floats
|
||||||
if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) {
|
if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) {
|
||||||
$number = (int) $match[0]; // integers lower than the maximum
|
$number = (int) $match[0]; // integers lower than the maximum
|
||||||
}
|
}
|
||||||
$this->pushToken(Twig_Token::NUMBER_TYPE, $number);
|
$this->pushToken(Token::NUMBER_TYPE, $number);
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
}
|
}
|
||||||
// punctuation
|
// punctuation
|
||||||
elseif (false !== strpos(self::PUNCTUATION, $this->code[$this->cursor])) {
|
elseif (false !== strpos(self::PUNCTUATION, $this->code[$this->cursor])) {
|
||||||
// opening bracket
|
// opening bracket
|
||||||
if (false !== strpos('([{', $this->code[$this->cursor])) {
|
if (false !== strpos('([{', $this->code[$this->cursor])) {
|
||||||
$this->brackets[] = array($this->code[$this->cursor], $this->lineno);
|
$this->brackets[] = [$this->code[$this->cursor], $this->lineno];
|
||||||
}
|
}
|
||||||
// closing bracket
|
// closing bracket
|
||||||
elseif (false !== strpos(')]}', $this->code[$this->cursor])) {
|
elseif (false !== strpos(')]}', $this->code[$this->cursor])) {
|
||||||
if (empty($this->brackets)) {
|
if (empty($this->brackets)) {
|
||||||
throw new Twig_Error_Syntax(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
|
throw new SyntaxError(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
|
||||||
}
|
}
|
||||||
|
|
||||||
list($expect, $lineno) = array_pop($this->brackets);
|
list($expect, $lineno) = array_pop($this->brackets);
|
||||||
if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) {
|
if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) {
|
||||||
throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
|
throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pushToken(Twig_Token::PUNCTUATION_TYPE, $this->code[$this->cursor]);
|
$this->pushToken(Token::PUNCTUATION_TYPE, $this->code[$this->cursor]);
|
||||||
++$this->cursor;
|
++$this->cursor;
|
||||||
}
|
}
|
||||||
// strings
|
// strings
|
||||||
elseif (preg_match(self::REGEX_STRING, $this->code, $match, null, $this->cursor)) {
|
elseif (preg_match(self::REGEX_STRING, $this->code, $match, 0, $this->cursor)) {
|
||||||
$this->pushToken(Twig_Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1)));
|
$this->pushToken(Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1)));
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
}
|
}
|
||||||
// opening double quoted string
|
// opening double quoted string
|
||||||
elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
|
elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
|
||||||
$this->brackets[] = array('"', $this->lineno);
|
$this->brackets[] = ['"', $this->lineno];
|
||||||
$this->pushState(self::STATE_STRING);
|
$this->pushState(self::STATE_STRING);
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
}
|
}
|
||||||
// unlexable
|
// unlexable
|
||||||
else {
|
else {
|
||||||
throw new Twig_Error_Syntax(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
|
throw new SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,23 +402,31 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) {
|
if (!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) {
|
||||||
throw new Twig_Error_Syntax(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source);
|
throw new SyntaxError(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source);
|
||||||
}
|
}
|
||||||
|
|
||||||
$text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor);
|
$text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor);
|
||||||
$this->moveCursor($text.$match[0][0]);
|
$this->moveCursor($text.$match[0][0]);
|
||||||
|
|
||||||
if (false !== strpos($match[1][0], $this->options['whitespace_trim'])) {
|
// trim?
|
||||||
$text = rtrim($text);
|
if (isset($match[1][0])) {
|
||||||
|
if ($this->options['whitespace_trim'] === $match[1][0]) {
|
||||||
|
// whitespace_trim detected ({%-, {{- or {#-)
|
||||||
|
$text = rtrim($text);
|
||||||
|
} else {
|
||||||
|
// whitespace_line_trim detected ({%~, {{~ or {#~)
|
||||||
|
// don't trim \r and \n
|
||||||
|
$text = rtrim($text, " \t\0\x0B");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pushToken(Twig_Token::TEXT_TYPE, $text);
|
$this->pushToken(Token::TEXT_TYPE, $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function lexComment()
|
protected function lexComment()
|
||||||
{
|
{
|
||||||
if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) {
|
if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) {
|
||||||
throw new Twig_Error_Syntax('Unclosed comment.', $this->lineno, $this->source);
|
throw new SyntaxError('Unclosed comment.', $this->lineno, $this->source);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]);
|
$this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]);
|
||||||
@ -327,31 +434,34 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
|
|
||||||
protected function lexString()
|
protected function lexString()
|
||||||
{
|
{
|
||||||
if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) {
|
if (preg_match($this->regexes['interpolation_start'], $this->code, $match, 0, $this->cursor)) {
|
||||||
$this->brackets[] = array($this->options['interpolation'][0], $this->lineno);
|
$this->brackets[] = [$this->options['interpolation'][0], $this->lineno];
|
||||||
$this->pushToken(Twig_Token::INTERPOLATION_START_TYPE);
|
$this->pushToken(Token::INTERPOLATION_START_TYPE);
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
$this->pushState(self::STATE_INTERPOLATION);
|
$this->pushState(self::STATE_INTERPOLATION);
|
||||||
} elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, null, $this->cursor) && strlen($match[0]) > 0) {
|
} elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && \strlen($match[0]) > 0) {
|
||||||
$this->pushToken(Twig_Token::STRING_TYPE, stripcslashes($match[0]));
|
$this->pushToken(Token::STRING_TYPE, stripcslashes($match[0]));
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
} elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
|
} elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
|
||||||
list($expect, $lineno) = array_pop($this->brackets);
|
list($expect, $lineno) = array_pop($this->brackets);
|
||||||
if ($this->code[$this->cursor] != '"') {
|
if ('"' != $this->code[$this->cursor]) {
|
||||||
throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
|
throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->popState();
|
$this->popState();
|
||||||
++$this->cursor;
|
++$this->cursor;
|
||||||
|
} else {
|
||||||
|
// unlexable
|
||||||
|
throw new SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function lexInterpolation()
|
protected function lexInterpolation()
|
||||||
{
|
{
|
||||||
$bracket = end($this->brackets);
|
$bracket = end($this->brackets);
|
||||||
if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, null, $this->cursor)) {
|
if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, 0, $this->cursor)) {
|
||||||
array_pop($this->brackets);
|
array_pop($this->brackets);
|
||||||
$this->pushToken(Twig_Token::INTERPOLATION_END_TYPE);
|
$this->pushToken(Token::INTERPOLATION_END_TYPE);
|
||||||
$this->moveCursor($match[0]);
|
$this->moveCursor($match[0]);
|
||||||
$this->popState();
|
$this->popState();
|
||||||
} else {
|
} else {
|
||||||
@ -362,23 +472,23 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
protected function pushToken($type, $value = '')
|
protected function pushToken($type, $value = '')
|
||||||
{
|
{
|
||||||
// do not push empty text tokens
|
// do not push empty text tokens
|
||||||
if (Twig_Token::TEXT_TYPE === $type && '' === $value) {
|
if (Token::TEXT_TYPE === $type && '' === $value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->tokens[] = new Twig_Token($type, $value, $this->lineno);
|
$this->tokens[] = new Token($type, $value, $this->lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function moveCursor($text)
|
protected function moveCursor($text)
|
||||||
{
|
{
|
||||||
$this->cursor += strlen($text);
|
$this->cursor += \strlen($text);
|
||||||
$this->lineno += substr_count($text, "\n");
|
$this->lineno += substr_count($text, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOperatorRegex()
|
protected function getOperatorRegex()
|
||||||
{
|
{
|
||||||
$operators = array_merge(
|
$operators = array_merge(
|
||||||
array('='),
|
['='],
|
||||||
array_keys($this->env->getUnaryOperators()),
|
array_keys($this->env->getUnaryOperators()),
|
||||||
array_keys($this->env->getBinaryOperators())
|
array_keys($this->env->getBinaryOperators())
|
||||||
);
|
);
|
||||||
@ -386,7 +496,7 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
$operators = array_combine($operators, array_map('strlen', $operators));
|
$operators = array_combine($operators, array_map('strlen', $operators));
|
||||||
arsort($operators);
|
arsort($operators);
|
||||||
|
|
||||||
$regex = array();
|
$regex = [];
|
||||||
foreach ($operators as $operator => $length) {
|
foreach ($operators as $operator => $length) {
|
||||||
// an operator that ends with a character must be followed by
|
// an operator that ends with a character must be followed by
|
||||||
// a whitespace or a parenthesis
|
// a whitespace or a parenthesis
|
||||||
@ -413,12 +523,12 @@ class Twig_Lexer implements Twig_LexerInterface
|
|||||||
|
|
||||||
protected function popState()
|
protected function popState()
|
||||||
{
|
{
|
||||||
if (0 === count($this->states)) {
|
if (0 === \count($this->states)) {
|
||||||
throw new Exception('Cannot pop state without a previous state.');
|
throw new \LogicException('Cannot pop state without a previous state.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->state = array_pop($this->states);
|
$this->state = array_pop($this->states);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Lexer', 'Twig\Lexer', false);
|
class_alias('Twig\Lexer', 'Twig_Lexer');
|
||||||
|
25
system/libs/Twig/Loader/Array.php → system/libs/Twig/Loader/ArrayLoader.php
Executable file → Normal file
25
system/libs/Twig/Loader/Array.php → system/libs/Twig/Loader/ArrayLoader.php
Executable file → Normal file
@ -9,6 +9,11 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Loader;
|
||||||
|
|
||||||
|
use Twig\Error\LoaderError;
|
||||||
|
use Twig\Source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a template from an array.
|
* Loads a template from an array.
|
||||||
*
|
*
|
||||||
@ -23,14 +28,14 @@
|
|||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
|
class ArrayLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
|
||||||
{
|
{
|
||||||
protected $templates = array();
|
protected $templates = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $templates An array of templates (keys are the names, and values are the source code)
|
* @param array $templates An array of templates (keys are the names, and values are the source code)
|
||||||
*/
|
*/
|
||||||
public function __construct(array $templates = array())
|
public function __construct(array $templates = [])
|
||||||
{
|
{
|
||||||
$this->templates = $templates;
|
$this->templates = $templates;
|
||||||
}
|
}
|
||||||
@ -48,11 +53,11 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
|||||||
|
|
||||||
public function getSource($name)
|
public function getSource($name)
|
||||||
{
|
{
|
||||||
@trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED);
|
||||||
|
|
||||||
$name = (string) $name;
|
$name = (string) $name;
|
||||||
if (!isset($this->templates[$name])) {
|
if (!isset($this->templates[$name])) {
|
||||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
|
throw new LoaderError(sprintf('Template "%s" is not defined.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->templates[$name];
|
return $this->templates[$name];
|
||||||
@ -62,10 +67,10 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
|||||||
{
|
{
|
||||||
$name = (string) $name;
|
$name = (string) $name;
|
||||||
if (!isset($this->templates[$name])) {
|
if (!isset($this->templates[$name])) {
|
||||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
|
throw new LoaderError(sprintf('Template "%s" is not defined.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Twig_Source($this->templates[$name], $name);
|
return new Source($this->templates[$name], $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function exists($name)
|
public function exists($name)
|
||||||
@ -77,7 +82,7 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
|||||||
{
|
{
|
||||||
$name = (string) $name;
|
$name = (string) $name;
|
||||||
if (!isset($this->templates[$name])) {
|
if (!isset($this->templates[$name])) {
|
||||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
|
throw new LoaderError(sprintf('Template "%s" is not defined.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $name.':'.$this->templates[$name];
|
return $name.':'.$this->templates[$name];
|
||||||
@ -87,11 +92,11 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
|||||||
{
|
{
|
||||||
$name = (string) $name;
|
$name = (string) $name;
|
||||||
if (!isset($this->templates[$name])) {
|
if (!isset($this->templates[$name])) {
|
||||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
|
throw new LoaderError(sprintf('Template "%s" is not defined.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Loader_Array', 'Twig\Loader\ArrayLoader', false);
|
class_alias('Twig\Loader\ArrayLoader', 'Twig_Loader_Array');
|
77
system/libs/Twig/Loader/Chain.php → system/libs/Twig/Loader/ChainLoader.php
Executable file → Normal file
77
system/libs/Twig/Loader/Chain.php → system/libs/Twig/Loader/ChainLoader.php
Executable file → Normal file
@ -9,6 +9,11 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Loader;
|
||||||
|
|
||||||
|
use Twig\Error\LoaderError;
|
||||||
|
use Twig\Source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads templates from other loaders.
|
* Loads templates from other loaders.
|
||||||
*
|
*
|
||||||
@ -16,67 +21,75 @@
|
|||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
|
class ChainLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
|
||||||
{
|
{
|
||||||
private $hasSourceCache = array();
|
private $hasSourceCache = [];
|
||||||
protected $loaders = array();
|
protected $loaders = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Twig_LoaderInterface[] $loaders
|
* @param LoaderInterface[] $loaders
|
||||||
*/
|
*/
|
||||||
public function __construct(array $loaders = array())
|
public function __construct(array $loaders = [])
|
||||||
{
|
{
|
||||||
foreach ($loaders as $loader) {
|
foreach ($loaders as $loader) {
|
||||||
$this->addLoader($loader);
|
$this->addLoader($loader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addLoader(Twig_LoaderInterface $loader)
|
public function addLoader(LoaderInterface $loader)
|
||||||
{
|
{
|
||||||
$this->loaders[] = $loader;
|
$this->loaders[] = $loader;
|
||||||
$this->hasSourceCache = array();
|
$this->hasSourceCache = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return LoaderInterface[]
|
||||||
|
*/
|
||||||
|
public function getLoaders()
|
||||||
|
{
|
||||||
|
return $this->loaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSource($name)
|
public function getSource($name)
|
||||||
{
|
{
|
||||||
@trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED);
|
||||||
|
|
||||||
$exceptions = array();
|
$exceptions = [];
|
||||||
foreach ($this->loaders as $loader) {
|
foreach ($this->loaders as $loader) {
|
||||||
if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
|
if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $loader->getSource($name);
|
return $loader->getSource($name);
|
||||||
} catch (Twig_Error_Loader $e) {
|
} catch (LoaderError $e) {
|
||||||
$exceptions[] = $e->getMessage();
|
$exceptions[] = $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
|
throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSourceContext($name)
|
public function getSourceContext($name)
|
||||||
{
|
{
|
||||||
$exceptions = array();
|
$exceptions = [];
|
||||||
foreach ($this->loaders as $loader) {
|
foreach ($this->loaders as $loader) {
|
||||||
if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
|
if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($loader instanceof Twig_SourceContextLoaderInterface) {
|
if ($loader instanceof SourceContextLoaderInterface) {
|
||||||
return $loader->getSourceContext($name);
|
return $loader->getSourceContext($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Twig_Source($loader->getSource($name), $name);
|
return new Source($loader->getSource($name), $name);
|
||||||
} catch (Twig_Error_Loader $e) {
|
} catch (LoaderError $e) {
|
||||||
$exceptions[] = $e->getMessage();
|
$exceptions[] = $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
|
throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function exists($name)
|
public function exists($name)
|
||||||
@ -88,7 +101,7 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->loaders as $loader) {
|
foreach ($this->loaders as $loader) {
|
||||||
if ($loader instanceof Twig_ExistsLoaderInterface) {
|
if ($loader instanceof ExistsLoaderInterface) {
|
||||||
if ($loader->exists($name)) {
|
if ($loader->exists($name)) {
|
||||||
return $this->hasSourceCache[$name] = true;
|
return $this->hasSourceCache[$name] = true;
|
||||||
}
|
}
|
||||||
@ -97,14 +110,14 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($loader instanceof Twig_SourceContextLoaderInterface) {
|
if ($loader instanceof SourceContextLoaderInterface) {
|
||||||
$loader->getSourceContext($name);
|
$loader->getSourceContext($name);
|
||||||
} else {
|
} else {
|
||||||
$loader->getSource($name);
|
$loader->getSource($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->hasSourceCache[$name] = true;
|
return $this->hasSourceCache[$name] = true;
|
||||||
} catch (Twig_Error_Loader $e) {
|
} catch (LoaderError $e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,39 +126,39 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
|||||||
|
|
||||||
public function getCacheKey($name)
|
public function getCacheKey($name)
|
||||||
{
|
{
|
||||||
$exceptions = array();
|
$exceptions = [];
|
||||||
foreach ($this->loaders as $loader) {
|
foreach ($this->loaders as $loader) {
|
||||||
if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
|
if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $loader->getCacheKey($name);
|
return $loader->getCacheKey($name);
|
||||||
} catch (Twig_Error_Loader $e) {
|
} catch (LoaderError $e) {
|
||||||
$exceptions[] = get_class($loader).': '.$e->getMessage();
|
$exceptions[] = \get_class($loader).': '.$e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
|
throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isFresh($name, $time)
|
public function isFresh($name, $time)
|
||||||
{
|
{
|
||||||
$exceptions = array();
|
$exceptions = [];
|
||||||
foreach ($this->loaders as $loader) {
|
foreach ($this->loaders as $loader) {
|
||||||
if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
|
if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return $loader->isFresh($name, $time);
|
return $loader->isFresh($name, $time);
|
||||||
} catch (Twig_Error_Loader $e) {
|
} catch (LoaderError $e) {
|
||||||
$exceptions[] = get_class($loader).': '.$e->getMessage();
|
$exceptions[] = \get_class($loader).': '.$e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
|
throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Loader_Chain', 'Twig\Loader\ChainLoader', false);
|
class_alias('Twig\Loader\ChainLoader', 'Twig_Loader_Chain');
|
6
system/libs/Twig/ExistsLoaderInterface.php → system/libs/Twig/Loader/ExistsLoaderInterface.php
Executable file → Normal file
6
system/libs/Twig/ExistsLoaderInterface.php → system/libs/Twig/Loader/ExistsLoaderInterface.php
Executable file → Normal file
@ -9,6 +9,8 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Loader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an exists() method for loaders.
|
* Adds an exists() method for loaders.
|
||||||
*
|
*
|
||||||
@ -16,7 +18,7 @@
|
|||||||
*
|
*
|
||||||
* @deprecated since 1.12 (to be removed in 3.0)
|
* @deprecated since 1.12 (to be removed in 3.0)
|
||||||
*/
|
*/
|
||||||
interface Twig_ExistsLoaderInterface
|
interface ExistsLoaderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Check if we have the source code of a template, given its name.
|
* Check if we have the source code of a template, given its name.
|
||||||
@ -28,4 +30,4 @@ interface Twig_ExistsLoaderInterface
|
|||||||
public function exists($name);
|
public function exists($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_ExistsLoaderInterface', 'Twig\Loader\ExistsLoaderInterface', false);
|
class_alias('Twig\Loader\ExistsLoaderInterface', 'Twig_ExistsLoaderInterface');
|
117
system/libs/Twig/Loader/Filesystem.php → system/libs/Twig/Loader/FilesystemLoader.php
Executable file → Normal file
117
system/libs/Twig/Loader/Filesystem.php → system/libs/Twig/Loader/FilesystemLoader.php
Executable file → Normal file
@ -9,19 +9,24 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Loader;
|
||||||
|
|
||||||
|
use Twig\Error\LoaderError;
|
||||||
|
use Twig\Source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads template from the filesystem.
|
* Loads template from the filesystem.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
|
class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface
|
||||||
{
|
{
|
||||||
/** Identifier of the main namespace. */
|
/** Identifier of the main namespace. */
|
||||||
const MAIN_NAMESPACE = '__main__';
|
const MAIN_NAMESPACE = '__main__';
|
||||||
|
|
||||||
protected $paths = array();
|
protected $paths = [];
|
||||||
protected $cache = array();
|
protected $cache = [];
|
||||||
protected $errorCache = array();
|
protected $errorCache = [];
|
||||||
|
|
||||||
private $rootPath;
|
private $rootPath;
|
||||||
|
|
||||||
@ -29,11 +34,11 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
* @param string|array $paths A path or an array of paths where to look for templates
|
* @param string|array $paths A path or an array of paths where to look for templates
|
||||||
* @param string|null $rootPath The root path common to all relative paths (null for getcwd())
|
* @param string|null $rootPath The root path common to all relative paths (null for getcwd())
|
||||||
*/
|
*/
|
||||||
public function __construct($paths = array(), $rootPath = null)
|
public function __construct($paths = [], $rootPath = null)
|
||||||
{
|
{
|
||||||
$this->rootPath = (null === $rootPath ? getcwd() : $rootPath).DIRECTORY_SEPARATOR;
|
$this->rootPath = (null === $rootPath ? getcwd() : $rootPath).\DIRECTORY_SEPARATOR;
|
||||||
if (false !== $realPath = realpath($rootPath)) {
|
if (false !== $realPath = realpath($rootPath)) {
|
||||||
$this->rootPath = $realPath.DIRECTORY_SEPARATOR;
|
$this->rootPath = $realPath.\DIRECTORY_SEPARATOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($paths) {
|
if ($paths) {
|
||||||
@ -50,7 +55,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
*/
|
*/
|
||||||
public function getPaths($namespace = self::MAIN_NAMESPACE)
|
public function getPaths($namespace = self::MAIN_NAMESPACE)
|
||||||
{
|
{
|
||||||
return isset($this->paths[$namespace]) ? $this->paths[$namespace] : array();
|
return isset($this->paths[$namespace]) ? $this->paths[$namespace] : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,11 +78,11 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
*/
|
*/
|
||||||
public function setPaths($paths, $namespace = self::MAIN_NAMESPACE)
|
public function setPaths($paths, $namespace = self::MAIN_NAMESPACE)
|
||||||
{
|
{
|
||||||
if (!is_array($paths)) {
|
if (!\is_array($paths)) {
|
||||||
$paths = array($paths);
|
$paths = [$paths];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->paths[$namespace] = array();
|
$this->paths[$namespace] = [];
|
||||||
foreach ($paths as $path) {
|
foreach ($paths as $path) {
|
||||||
$this->addPath($path, $namespace);
|
$this->addPath($path, $namespace);
|
||||||
}
|
}
|
||||||
@ -89,16 +94,16 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
* @param string $path A path where to look for templates
|
* @param string $path A path where to look for templates
|
||||||
* @param string $namespace A path namespace
|
* @param string $namespace A path namespace
|
||||||
*
|
*
|
||||||
* @throws Twig_Error_Loader
|
* @throws LoaderError
|
||||||
*/
|
*/
|
||||||
public function addPath($path, $namespace = self::MAIN_NAMESPACE)
|
public function addPath($path, $namespace = self::MAIN_NAMESPACE)
|
||||||
{
|
{
|
||||||
// invalidate the cache
|
// invalidate the cache
|
||||||
$this->cache = $this->errorCache = array();
|
$this->cache = $this->errorCache = [];
|
||||||
|
|
||||||
$checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path;
|
$checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path;
|
||||||
if (!is_dir($checkPath)) {
|
if (!is_dir($checkPath)) {
|
||||||
throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath));
|
throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->paths[$namespace][] = rtrim($path, '/\\');
|
$this->paths[$namespace][] = rtrim($path, '/\\');
|
||||||
@ -110,16 +115,16 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
* @param string $path A path where to look for templates
|
* @param string $path A path where to look for templates
|
||||||
* @param string $namespace A path namespace
|
* @param string $namespace A path namespace
|
||||||
*
|
*
|
||||||
* @throws Twig_Error_Loader
|
* @throws LoaderError
|
||||||
*/
|
*/
|
||||||
public function prependPath($path, $namespace = self::MAIN_NAMESPACE)
|
public function prependPath($path, $namespace = self::MAIN_NAMESPACE)
|
||||||
{
|
{
|
||||||
// invalidate the cache
|
// invalidate the cache
|
||||||
$this->cache = $this->errorCache = array();
|
$this->cache = $this->errorCache = [];
|
||||||
|
|
||||||
$checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path;
|
$checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path;
|
||||||
if (!is_dir($checkPath)) {
|
if (!is_dir($checkPath)) {
|
||||||
throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath));
|
throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = rtrim($path, '/\\');
|
$path = rtrim($path, '/\\');
|
||||||
@ -133,22 +138,30 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
|
|
||||||
public function getSource($name)
|
public function getSource($name)
|
||||||
{
|
{
|
||||||
@trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED);
|
||||||
|
|
||||||
return file_get_contents($this->findTemplate($name));
|
if (null === ($path = $this->findTemplate($name)) || false === $path) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return file_get_contents($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSourceContext($name)
|
public function getSourceContext($name)
|
||||||
{
|
{
|
||||||
$path = $this->findTemplate($name);
|
if (null === ($path = $this->findTemplate($name)) || false === $path) {
|
||||||
|
return new Source('', $name, '');
|
||||||
|
}
|
||||||
|
|
||||||
return new Twig_Source(file_get_contents($path), $name, $path);
|
return new Source(file_get_contents($path), $name, $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCacheKey($name)
|
public function getCacheKey($name)
|
||||||
{
|
{
|
||||||
$path = $this->findTemplate($name);
|
if (null === ($path = $this->findTemplate($name)) || false === $path) {
|
||||||
$len = strlen($this->rootPath);
|
return '';
|
||||||
|
}
|
||||||
|
$len = \strlen($this->rootPath);
|
||||||
if (0 === strncmp($this->rootPath, $path, $len)) {
|
if (0 === strncmp($this->rootPath, $path, $len)) {
|
||||||
return substr($path, $len);
|
return substr($path, $len);
|
||||||
}
|
}
|
||||||
@ -165,9 +178,9 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return false !== $this->findTemplate($name, false);
|
return null !== ($path = $this->findTemplate($name, false)) && false !== $path;
|
||||||
} catch (Twig_Error_Loader $exception) {
|
} catch (LoaderError $e) {
|
||||||
@trigger_error(sprintf('In %s::findTemplate(), you must accept a second argument that when set to "false" returns "false" instead of throwing an exception. Not supporting this argument is deprecated since version 1.27.', get_class($this)), E_USER_DEPRECATED);
|
@trigger_error(sprintf('In %s::findTemplate(), you must accept a second argument that when set to "false" returns "false" instead of throwing an exception. Not supporting this argument is deprecated since version 1.27.', \get_class($this)), E_USER_DEPRECATED);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -175,12 +188,24 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
|
|
||||||
public function isFresh($name, $time)
|
public function isFresh($name, $time)
|
||||||
{
|
{
|
||||||
return filemtime($this->findTemplate($name)) <= $time;
|
// false support to be removed in 3.0
|
||||||
|
if (null === ($path = $this->findTemplate($name)) || false === $path) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return filemtime($path) < $time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the template can be found.
|
||||||
|
*
|
||||||
|
* @param string $name The template name
|
||||||
|
*
|
||||||
|
* @return string|false|null The template name or false/null
|
||||||
|
*/
|
||||||
protected function findTemplate($name)
|
protected function findTemplate($name)
|
||||||
{
|
{
|
||||||
$throw = func_num_args() > 1 ? func_get_arg(1) : true;
|
$throw = \func_num_args() > 1 ? func_get_arg(1) : true;
|
||||||
$name = $this->normalizeName($name);
|
$name = $this->normalizeName($name);
|
||||||
|
|
||||||
if (isset($this->cache[$name])) {
|
if (isset($this->cache[$name])) {
|
||||||
@ -192,12 +217,20 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Twig_Error_Loader($this->errorCache[$name]);
|
throw new LoaderError($this->errorCache[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->validateName($name);
|
try {
|
||||||
|
$this->validateName($name);
|
||||||
|
|
||||||
list($namespace, $shortname) = $this->parseName($name);
|
list($namespace, $shortname) = $this->parseName($name);
|
||||||
|
} catch (LoaderError $e) {
|
||||||
|
if (!$throw) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isset($this->paths[$namespace])) {
|
if (!isset($this->paths[$namespace])) {
|
||||||
$this->errorCache[$name] = sprintf('There are no registered paths for namespace "%s".', $namespace);
|
$this->errorCache[$name] = sprintf('There are no registered paths for namespace "%s".', $namespace);
|
||||||
@ -206,12 +239,12 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Twig_Error_Loader($this->errorCache[$name]);
|
throw new LoaderError($this->errorCache[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->paths[$namespace] as $path) {
|
foreach ($this->paths[$namespace] as $path) {
|
||||||
if (!$this->isAbsolutePath($path)) {
|
if (!$this->isAbsolutePath($path)) {
|
||||||
$path = $this->rootPath.'/'.$path;
|
$path = $this->rootPath.$path;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_file($path.'/'.$shortname)) {
|
if (is_file($path.'/'.$shortname)) {
|
||||||
@ -229,23 +262,23 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Twig_Error_Loader($this->errorCache[$name]);
|
throw new LoaderError($this->errorCache[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function parseName($name, $default = self::MAIN_NAMESPACE)
|
protected function parseName($name, $default = self::MAIN_NAMESPACE)
|
||||||
{
|
{
|
||||||
if (isset($name[0]) && '@' == $name[0]) {
|
if (isset($name[0]) && '@' == $name[0]) {
|
||||||
if (false === $pos = strpos($name, '/')) {
|
if (false === $pos = strpos($name, '/')) {
|
||||||
throw new Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name));
|
throw new LoaderError(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
$namespace = substr($name, 1, $pos - 1);
|
$namespace = substr($name, 1, $pos - 1);
|
||||||
$shortname = substr($name, $pos + 1);
|
$shortname = substr($name, $pos + 1);
|
||||||
|
|
||||||
return array($namespace, $shortname);
|
return [$namespace, $shortname];
|
||||||
}
|
}
|
||||||
|
|
||||||
return array($default, $name);
|
return [$default, $name];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function normalizeName($name)
|
protected function normalizeName($name)
|
||||||
@ -256,7 +289,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
protected function validateName($name)
|
protected function validateName($name)
|
||||||
{
|
{
|
||||||
if (false !== strpos($name, "\0")) {
|
if (false !== strpos($name, "\0")) {
|
||||||
throw new Twig_Error_Loader('A template name cannot contain NUL bytes.');
|
throw new LoaderError('A template name cannot contain NUL bytes.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$name = ltrim($name, '/');
|
$name = ltrim($name, '/');
|
||||||
@ -270,7 +303,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($level < 0) {
|
if ($level < 0) {
|
||||||
throw new Twig_Error_Loader(sprintf('Looks like you try to load a template outside configured directories (%s).', $name));
|
throw new LoaderError(sprintf('Looks like you try to load a template outside configured directories (%s).', $name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -278,8 +311,8 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
private function isAbsolutePath($file)
|
private function isAbsolutePath($file)
|
||||||
{
|
{
|
||||||
return strspn($file, '/\\', 0, 1)
|
return strspn($file, '/\\', 0, 1)
|
||||||
|| (strlen($file) > 3 && ctype_alpha($file[0])
|
|| (\strlen($file) > 3 && ctype_alpha($file[0])
|
||||||
&& substr($file, 1, 1) === ':'
|
&& ':' === substr($file, 1, 1)
|
||||||
&& strspn($file, '/\\', 2, 1)
|
&& strspn($file, '/\\', 2, 1)
|
||||||
)
|
)
|
||||||
|| null !== parse_url($file, PHP_URL_SCHEME)
|
|| null !== parse_url($file, PHP_URL_SCHEME)
|
||||||
@ -287,4 +320,4 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Loader_Filesystem', 'Twig\Loader\FilesystemLoader', false);
|
class_alias('Twig\Loader\FilesystemLoader', 'Twig_Loader_Filesystem');
|
16
system/libs/Twig/LoaderInterface.php → system/libs/Twig/Loader/LoaderInterface.php
Executable file → Normal file
16
system/libs/Twig/LoaderInterface.php → system/libs/Twig/Loader/LoaderInterface.php
Executable file → Normal file
@ -9,12 +9,16 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Loader;
|
||||||
|
|
||||||
|
use Twig\Error\LoaderError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface all loaders must implement.
|
* Interface all loaders must implement.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
interface Twig_LoaderInterface
|
interface LoaderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Gets the source code of a template, given its name.
|
* Gets the source code of a template, given its name.
|
||||||
@ -23,9 +27,9 @@ interface Twig_LoaderInterface
|
|||||||
*
|
*
|
||||||
* @return string The template source code
|
* @return string The template source code
|
||||||
*
|
*
|
||||||
* @throws Twig_Error_Loader When $name is not found
|
* @throws LoaderError When $name is not found
|
||||||
*
|
*
|
||||||
* @deprecated since 1.27 (to be removed in 2.0), implement Twig_SourceContextLoaderInterface
|
* @deprecated since 1.27 (to be removed in 2.0), implement Twig\Loader\SourceContextLoaderInterface
|
||||||
*/
|
*/
|
||||||
public function getSource($name);
|
public function getSource($name);
|
||||||
|
|
||||||
@ -36,7 +40,7 @@ interface Twig_LoaderInterface
|
|||||||
*
|
*
|
||||||
* @return string The cache key
|
* @return string The cache key
|
||||||
*
|
*
|
||||||
* @throws Twig_Error_Loader When $name is not found
|
* @throws LoaderError When $name is not found
|
||||||
*/
|
*/
|
||||||
public function getCacheKey($name);
|
public function getCacheKey($name);
|
||||||
|
|
||||||
@ -49,9 +53,9 @@ interface Twig_LoaderInterface
|
|||||||
*
|
*
|
||||||
* @return bool true if the template is fresh, false otherwise
|
* @return bool true if the template is fresh, false otherwise
|
||||||
*
|
*
|
||||||
* @throws Twig_Error_Loader When $name is not found
|
* @throws LoaderError When $name is not found
|
||||||
*/
|
*/
|
||||||
public function isFresh($name, $time);
|
public function isFresh($name, $time);
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_LoaderInterface', 'Twig\Loader\LoaderInterface', false);
|
class_alias('Twig\Loader\LoaderInterface', 'Twig_LoaderInterface');
|
@ -9,6 +9,11 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Loader;
|
||||||
|
|
||||||
|
use Twig\Error\LoaderError;
|
||||||
|
use Twig\Source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a getSourceContext() method for loaders.
|
* Adds a getSourceContext() method for loaders.
|
||||||
*
|
*
|
||||||
@ -16,18 +21,18 @@
|
|||||||
*
|
*
|
||||||
* @deprecated since 1.27 (to be removed in 3.0)
|
* @deprecated since 1.27 (to be removed in 3.0)
|
||||||
*/
|
*/
|
||||||
interface Twig_SourceContextLoaderInterface
|
interface SourceContextLoaderInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Returns the source context for a given template logical name.
|
* Returns the source context for a given template logical name.
|
||||||
*
|
*
|
||||||
* @param string $name The template logical name
|
* @param string $name The template logical name
|
||||||
*
|
*
|
||||||
* @return Twig_Source
|
* @return Source
|
||||||
*
|
*
|
||||||
* @throws Twig_Error_Loader When $name is not found
|
* @throws LoaderError When $name is not found
|
||||||
*/
|
*/
|
||||||
public function getSourceContext($name);
|
public function getSourceContext($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_SourceContextLoaderInterface', 'Twig\Loader\SourceContextLoaderInterface', false);
|
class_alias('Twig\Loader\SourceContextLoaderInterface', 'Twig_SourceContextLoaderInterface');
|
@ -9,12 +9,14 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks a content as safe.
|
* Marks a content as safe.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Markup implements Countable
|
class Markup implements \Countable
|
||||||
{
|
{
|
||||||
protected $content;
|
protected $content;
|
||||||
protected $charset;
|
protected $charset;
|
||||||
@ -32,8 +34,8 @@ class Twig_Markup implements Countable
|
|||||||
|
|
||||||
public function count()
|
public function count()
|
||||||
{
|
{
|
||||||
return function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : strlen($this->content);
|
return \function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : \strlen($this->content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Markup', 'Twig\Markup', false);
|
class_alias('Twig\Markup', 'Twig_Markup');
|
||||||
|
14
system/libs/Twig/Node/AutoEscape.php → system/libs/Twig/Node/AutoEscapeNode.php
Executable file → Normal file
14
system/libs/Twig/Node/AutoEscape.php → system/libs/Twig/Node/AutoEscapeNode.php
Executable file → Normal file
@ -9,6 +9,10 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Node;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an autoescape node.
|
* Represents an autoescape node.
|
||||||
*
|
*
|
||||||
@ -20,17 +24,17 @@
|
|||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Node_AutoEscape extends Twig_Node
|
class AutoEscapeNode extends Node
|
||||||
{
|
{
|
||||||
public function __construct($value, Twig_NodeInterface $body, $lineno, $tag = 'autoescape')
|
public function __construct($value, \Twig_NodeInterface $body, $lineno, $tag = 'autoescape')
|
||||||
{
|
{
|
||||||
parent::__construct(array('body' => $body), array('value' => $value), $lineno, $tag);
|
parent::__construct(['body' => $body], ['value' => $value], $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler->subcompile($this->getNode('body'));
|
$compiler->subcompile($this->getNode('body'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_AutoEscape', 'Twig\Node\AutoEscapeNode', false);
|
class_alias('Twig\Node\AutoEscapeNode', 'Twig_Node_AutoEscape');
|
16
system/libs/Twig/Node/Block.php → system/libs/Twig/Node/BlockNode.php
Executable file → Normal file
16
system/libs/Twig/Node/Block.php → system/libs/Twig/Node/BlockNode.php
Executable file → Normal file
@ -10,23 +10,27 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Node;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a block node.
|
* Represents a block node.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Block extends Twig_Node
|
class BlockNode extends Node
|
||||||
{
|
{
|
||||||
public function __construct($name, Twig_NodeInterface $body, $lineno, $tag = null)
|
public function __construct($name, \Twig_NodeInterface $body, $lineno, $tag = null)
|
||||||
{
|
{
|
||||||
parent::__construct(array('body' => $body), array('name' => $name), $lineno, $tag);
|
parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->addDebugInfo($this)
|
->addDebugInfo($this)
|
||||||
->write(sprintf("public function block_%s(\$context, array \$blocks = array())\n", $this->getAttribute('name')), "{\n")
|
->write(sprintf("public function block_%s(\$context, array \$blocks = [])\n", $this->getAttribute('name')), "{\n")
|
||||||
->indent()
|
->indent()
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -38,4 +42,4 @@ class Twig_Node_Block extends Twig_Node
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Block', 'Twig\Node\BlockNode', false);
|
class_alias('Twig\Node\BlockNode', 'Twig_Node_Block');
|
12
system/libs/Twig/Node/BlockReference.php → system/libs/Twig/Node/BlockReferenceNode.php
Executable file → Normal file
12
system/libs/Twig/Node/BlockReference.php → system/libs/Twig/Node/BlockReferenceNode.php
Executable file → Normal file
@ -10,19 +10,23 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Node;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a block call node.
|
* Represents a block call node.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInterface
|
class BlockReferenceNode extends Node implements NodeOutputInterface
|
||||||
{
|
{
|
||||||
public function __construct($name, $lineno, $tag = null)
|
public function __construct($name, $lineno, $tag = null)
|
||||||
{
|
{
|
||||||
parent::__construct(array(), array('name' => $name), $lineno, $tag);
|
parent::__construct([], ['name' => $name], $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->addDebugInfo($this)
|
->addDebugInfo($this)
|
||||||
@ -31,4 +35,4 @@ class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_BlockReference', 'Twig\Node\BlockReferenceNode', false);
|
class_alias('Twig\Node\BlockReferenceNode', 'Twig_Node_BlockReference');
|
6
system/libs/Twig/Node/Body.php → system/libs/Twig/Node/BodyNode.php
Executable file → Normal file
6
system/libs/Twig/Node/Body.php → system/libs/Twig/Node/BodyNode.php
Executable file → Normal file
@ -9,13 +9,15 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a body node.
|
* Represents a body node.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Body extends Twig_Node
|
class BodyNode extends Node
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Body', 'Twig\Node\BodyNode', false);
|
class_alias('Twig\Node\BodyNode', 'Twig_Node_Body');
|
33
system/libs/Twig/Node/CheckSecurity.php → system/libs/Twig/Node/CheckSecurityNode.php
Executable file → Normal file
33
system/libs/Twig/Node/CheckSecurity.php → system/libs/Twig/Node/CheckSecurityNode.php
Executable file → Normal file
@ -9,10 +9,14 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Node;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Node_CheckSecurity extends Twig_Node
|
class CheckSecurityNode extends Node
|
||||||
{
|
{
|
||||||
protected $usedFilters;
|
protected $usedFilters;
|
||||||
protected $usedTags;
|
protected $usedTags;
|
||||||
@ -27,12 +31,12 @@ class Twig_Node_CheckSecurity extends Twig_Node
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$tags = $filters = $functions = array();
|
$tags = $filters = $functions = [];
|
||||||
foreach (array('tags', 'filters', 'functions') as $type) {
|
foreach (['tags', 'filters', 'functions'] as $type) {
|
||||||
foreach ($this->{'used'.ucfirst($type)} as $name => $node) {
|
foreach ($this->{'used'.ucfirst($type)} as $name => $node) {
|
||||||
if ($node instanceof Twig_Node) {
|
if ($node instanceof Node) {
|
||||||
${$type}[$name] = $node->getTemplateLine();
|
${$type}[$name] = $node->getTemplateLine();
|
||||||
} else {
|
} else {
|
||||||
${$type}[$node] = null;
|
${$type}[$node] = null;
|
||||||
@ -41,31 +45,32 @@ class Twig_Node_CheckSecurity extends Twig_Node
|
|||||||
}
|
}
|
||||||
|
|
||||||
$compiler
|
$compiler
|
||||||
|
->write("\$this->sandbox = \$this->env->getExtension('\Twig\Extension\SandboxExtension');\n")
|
||||||
->write('$tags = ')->repr(array_filter($tags))->raw(";\n")
|
->write('$tags = ')->repr(array_filter($tags))->raw(";\n")
|
||||||
->write('$filters = ')->repr(array_filter($filters))->raw(";\n")
|
->write('$filters = ')->repr(array_filter($filters))->raw(";\n")
|
||||||
->write('$functions = ')->repr(array_filter($functions))->raw(";\n\n")
|
->write('$functions = ')->repr(array_filter($functions))->raw(";\n\n")
|
||||||
->write("try {\n")
|
->write("try {\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write("\$this->env->getExtension('Twig_Extension_Sandbox')->checkSecurity(\n")
|
->write("\$this->sandbox->checkSecurity(\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write(!$tags ? "array(),\n" : "array('".implode("', '", array_keys($tags))."'),\n")
|
->write(!$tags ? "[],\n" : "['".implode("', '", array_keys($tags))."'],\n")
|
||||||
->write(!$filters ? "array(),\n" : "array('".implode("', '", array_keys($filters))."'),\n")
|
->write(!$filters ? "[],\n" : "['".implode("', '", array_keys($filters))."'],\n")
|
||||||
->write(!$functions ? "array()\n" : "array('".implode("', '", array_keys($functions))."')\n")
|
->write(!$functions ? "[]\n" : "['".implode("', '", array_keys($functions))."']\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
->write(");\n")
|
->write(");\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
->write("} catch (Twig_Sandbox_SecurityError \$e) {\n")
|
->write("} catch (SecurityError \$e) {\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write("\$e->setSourceContext(\$this->getSourceContext());\n\n")
|
->write("\$e->setSourceContext(\$this->getSourceContext());\n\n")
|
||||||
->write("if (\$e instanceof Twig_Sandbox_SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n")
|
->write("if (\$e instanceof SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write("\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n")
|
->write("\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
->write("} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n")
|
->write("} elseif (\$e instanceof SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write("\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n")
|
->write("\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
->write("} elseif (\$e instanceof Twig_Sandbox_SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n")
|
->write("} elseif (\$e instanceof SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n")
|
||||||
->indent()
|
->indent()
|
||||||
->write("\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n")
|
->write("\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n")
|
||||||
->outdent()
|
->outdent()
|
||||||
@ -77,4 +82,4 @@ class Twig_Node_CheckSecurity extends Twig_Node
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_CheckSecurity', 'Twig\Node\CheckSecurityNode', false);
|
class_alias('Twig\Node\CheckSecurityNode', 'Twig_Node_CheckSecurity');
|
42
system/libs/Twig/Node/CheckToStringNode.php
Normal file
42
system/libs/Twig/Node/CheckToStringNode.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Expression\AbstractExpression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if casting an expression to __toString() is allowed by the sandbox.
|
||||||
|
*
|
||||||
|
* For instance, when there is a simple Print statement, like {{ article }},
|
||||||
|
* and if the sandbox is enabled, we need to check that the __toString()
|
||||||
|
* method is allowed if 'article' is an object. The same goes for {{ article|upper }}
|
||||||
|
* or {{ random(article) }}
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*/
|
||||||
|
class CheckToStringNode extends AbstractExpression
|
||||||
|
{
|
||||||
|
public function __construct(AbstractExpression $expr)
|
||||||
|
{
|
||||||
|
parent::__construct(['expr' => $expr], [], $expr->getTemplateLine(), $expr->getNodeTag());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function compile(Compiler $compiler)
|
||||||
|
{
|
||||||
|
$compiler
|
||||||
|
->raw('$this->sandbox->ensureToStringAllowed(')
|
||||||
|
->subcompile($this->getNode('expr'))
|
||||||
|
->raw(')')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
55
system/libs/Twig/Node/DeprecatedNode.php
Normal file
55
system/libs/Twig/Node/DeprecatedNode.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Expression\AbstractExpression;
|
||||||
|
use Twig\Node\Expression\ConstantExpression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a deprecated node.
|
||||||
|
*
|
||||||
|
* @author Yonel Ceruto <yonelceruto@gmail.com>
|
||||||
|
*/
|
||||||
|
class DeprecatedNode extends Node
|
||||||
|
{
|
||||||
|
public function __construct(AbstractExpression $expr, $lineno, $tag = null)
|
||||||
|
{
|
||||||
|
parent::__construct(['expr' => $expr], [], $lineno, $tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function compile(Compiler $compiler)
|
||||||
|
{
|
||||||
|
$compiler->addDebugInfo($this);
|
||||||
|
|
||||||
|
$expr = $this->getNode('expr');
|
||||||
|
|
||||||
|
if ($expr instanceof ConstantExpression) {
|
||||||
|
$compiler->write('@trigger_error(')
|
||||||
|
->subcompile($expr);
|
||||||
|
} else {
|
||||||
|
$varName = $compiler->getVarName();
|
||||||
|
$compiler->write(sprintf('$%s = ', $varName))
|
||||||
|
->subcompile($expr)
|
||||||
|
->raw(";\n")
|
||||||
|
->write(sprintf('@trigger_error($%s', $varName));
|
||||||
|
}
|
||||||
|
|
||||||
|
$compiler
|
||||||
|
->raw('.')
|
||||||
|
->string(sprintf(' ("%s" at line %d).', $this->getTemplateName(), $this->getTemplateLine()))
|
||||||
|
->raw(", E_USER_DEPRECATED);\n")
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class_alias('Twig\Node\DeprecatedNode', 'Twig_Node_Deprecated');
|
15
system/libs/Twig/Node/Do.php → system/libs/Twig/Node/DoNode.php
Executable file → Normal file
15
system/libs/Twig/Node/Do.php → system/libs/Twig/Node/DoNode.php
Executable file → Normal file
@ -9,19 +9,24 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Node;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Expression\AbstractExpression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a do node.
|
* Represents a do node.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Do extends Twig_Node
|
class DoNode extends Node
|
||||||
{
|
{
|
||||||
public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null)
|
public function __construct(AbstractExpression $expr, $lineno, $tag = null)
|
||||||
{
|
{
|
||||||
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
|
parent::__construct(['expr' => $expr], [], $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->addDebugInfo($this)
|
->addDebugInfo($this)
|
||||||
@ -32,4 +37,4 @@ class Twig_Node_Do extends Twig_Node
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Do', 'Twig\Node\DoNode', false);
|
class_alias('Twig\Node\DoNode', 'Twig_Node_Do');
|
16
system/libs/Twig/Node/Embed.php → system/libs/Twig/Node/EmbedNode.php
Executable file → Normal file
16
system/libs/Twig/Node/Embed.php → system/libs/Twig/Node/EmbedNode.php
Executable file → Normal file
@ -9,17 +9,23 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Node;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Expression\AbstractExpression;
|
||||||
|
use Twig\Node\Expression\ConstantExpression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an embed node.
|
* Represents an embed node.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Embed extends Twig_Node_Include
|
class EmbedNode extends IncludeNode
|
||||||
{
|
{
|
||||||
// we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module)
|
// we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module)
|
||||||
public function __construct($name, $index, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
|
public function __construct($name, $index, AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
|
||||||
{
|
{
|
||||||
parent::__construct(new Twig_Node_Expression_Constant('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag);
|
parent::__construct(new ConstantExpression('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag);
|
||||||
|
|
||||||
$this->setAttribute('name', $name);
|
$this->setAttribute('name', $name);
|
||||||
// to be removed in 2.0, used name instead
|
// to be removed in 2.0, used name instead
|
||||||
@ -27,7 +33,7 @@ class Twig_Node_Embed extends Twig_Node_Include
|
|||||||
$this->setAttribute('index', $index);
|
$this->setAttribute('index', $index);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function addGetTemplate(Twig_Compiler $compiler)
|
protected function addGetTemplate(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->write('$this->loadTemplate(')
|
->write('$this->loadTemplate(')
|
||||||
@ -43,4 +49,4 @@ class Twig_Node_Embed extends Twig_Node_Include
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Embed', 'Twig\Node\EmbedNode', false);
|
class_alias('Twig\Node\EmbedNode', 'Twig_Node_Embed');
|
8
system/libs/Twig/Node/Expression.php → system/libs/Twig/Node/Expression/AbstractExpression.php
Executable file → Normal file
8
system/libs/Twig/Node/Expression.php → system/libs/Twig/Node/Expression/AbstractExpression.php
Executable file → Normal file
@ -10,13 +10,17 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class for all nodes that represents an expression.
|
* Abstract class for all nodes that represents an expression.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
abstract class Twig_Node_Expression extends Twig_Node
|
abstract class AbstractExpression extends Node
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression', 'Twig\Node\Expression\AbstractExpression', false);
|
class_alias('Twig\Node\Expression\AbstractExpression', 'Twig_Node_Expression');
|
31
system/libs/Twig/Node/Expression/Array.php → system/libs/Twig/Node/Expression/ArrayExpression.php
Executable file → Normal file
31
system/libs/Twig/Node/Expression/Array.php → system/libs/Twig/Node/Expression/ArrayExpression.php
Executable file → Normal file
@ -8,17 +8,22 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Array extends Twig_Node_Expression
|
|
||||||
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class ArrayExpression extends AbstractExpression
|
||||||
{
|
{
|
||||||
protected $index;
|
protected $index;
|
||||||
|
|
||||||
public function __construct(array $elements, $lineno)
|
public function __construct(array $elements, $lineno)
|
||||||
{
|
{
|
||||||
parent::__construct($elements, array(), $lineno);
|
parent::__construct($elements, [], $lineno);
|
||||||
|
|
||||||
$this->index = -1;
|
$this->index = -1;
|
||||||
foreach ($this->getKeyValuePairs() as $pair) {
|
foreach ($this->getKeyValuePairs() as $pair) {
|
||||||
if ($pair['key'] instanceof Twig_Node_Expression_Constant && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) {
|
if ($pair['key'] instanceof ConstantExpression && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) {
|
||||||
$this->index = $pair['key']->getAttribute('value');
|
$this->index = $pair['key']->getAttribute('value');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26,19 +31,19 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
|
|||||||
|
|
||||||
public function getKeyValuePairs()
|
public function getKeyValuePairs()
|
||||||
{
|
{
|
||||||
$pairs = array();
|
$pairs = [];
|
||||||
|
|
||||||
foreach (array_chunk($this->nodes, 2) as $pair) {
|
foreach (array_chunk($this->nodes, 2) as $pair) {
|
||||||
$pairs[] = array(
|
$pairs[] = [
|
||||||
'key' => $pair[0],
|
'key' => $pair[0],
|
||||||
'value' => $pair[1],
|
'value' => $pair[1],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $pairs;
|
return $pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasElement(Twig_Node_Expression $key)
|
public function hasElement(AbstractExpression $key)
|
||||||
{
|
{
|
||||||
foreach ($this->getKeyValuePairs() as $pair) {
|
foreach ($this->getKeyValuePairs() as $pair) {
|
||||||
// we compare the string representation of the keys
|
// we compare the string representation of the keys
|
||||||
@ -51,18 +56,18 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addElement(Twig_Node_Expression $value, Twig_Node_Expression $key = null)
|
public function addElement(AbstractExpression $value, AbstractExpression $key = null)
|
||||||
{
|
{
|
||||||
if (null === $key) {
|
if (null === $key) {
|
||||||
$key = new Twig_Node_Expression_Constant(++$this->index, $value->getTemplateLine());
|
$key = new ConstantExpression(++$this->index, $value->getTemplateLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
array_push($this->nodes, $key, $value);
|
array_push($this->nodes, $key, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler->raw('array(');
|
$compiler->raw('[');
|
||||||
$first = true;
|
$first = true;
|
||||||
foreach ($this->getKeyValuePairs() as $pair) {
|
foreach ($this->getKeyValuePairs() as $pair) {
|
||||||
if (!$first) {
|
if (!$first) {
|
||||||
@ -76,8 +81,8 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
|
|||||||
->subcompile($pair['value'])
|
->subcompile($pair['value'])
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
$compiler->raw(')');
|
$compiler->raw(']');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Array', 'Twig\Node\Expression\ArrayExpression', false);
|
class_alias('Twig\Node\Expression\ArrayExpression', 'Twig_Node_Expression_Array');
|
64
system/libs/Twig/Node/Expression/ArrowFunctionExpression.php
Normal file
64
system/libs/Twig/Node/Expression/ArrowFunctionExpression.php
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an arrow function.
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*/
|
||||||
|
class ArrowFunctionExpression extends AbstractExpression
|
||||||
|
{
|
||||||
|
public function __construct(AbstractExpression $expr, Node $names, $lineno, $tag = null)
|
||||||
|
{
|
||||||
|
parent::__construct(['expr' => $expr, 'names' => $names], [], $lineno, $tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function compile(Compiler $compiler)
|
||||||
|
{
|
||||||
|
$compiler
|
||||||
|
->addDebugInfo($this)
|
||||||
|
->raw('function (')
|
||||||
|
;
|
||||||
|
foreach ($this->getNode('names') as $i => $name) {
|
||||||
|
if ($i) {
|
||||||
|
$compiler->raw(', ');
|
||||||
|
}
|
||||||
|
|
||||||
|
$compiler
|
||||||
|
->raw('$__')
|
||||||
|
->raw($name->getAttribute('name'))
|
||||||
|
->raw('__')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
$compiler
|
||||||
|
->raw(') use ($context) { ')
|
||||||
|
;
|
||||||
|
foreach ($this->getNode('names') as $name) {
|
||||||
|
$compiler
|
||||||
|
->raw('$context["')
|
||||||
|
->raw($name->getAttribute('name'))
|
||||||
|
->raw('"] = $__')
|
||||||
|
->raw($name->getAttribute('name'))
|
||||||
|
->raw('__; ')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
$compiler
|
||||||
|
->raw('return ')
|
||||||
|
->subcompile($this->getNode('expr'))
|
||||||
|
->raw('; }')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
10
system/libs/Twig/Node/Expression/AssignName.php → system/libs/Twig/Node/Expression/AssignNameExpression.php
Executable file → Normal file
10
system/libs/Twig/Node/Expression/AssignName.php → system/libs/Twig/Node/Expression/AssignNameExpression.php
Executable file → Normal file
@ -10,9 +10,13 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Twig_Node_Expression_AssignName extends Twig_Node_Expression_Name
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class AssignNameExpression extends NameExpression
|
||||||
{
|
{
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->raw('$context[')
|
->raw('$context[')
|
||||||
@ -22,4 +26,4 @@ class Twig_Node_Expression_AssignName extends Twig_Node_Expression_Name
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_AssignName', 'Twig\Node\Expression\AssignNameExpression', false);
|
class_alias('Twig\Node\Expression\AssignNameExpression', 'Twig_Node_Expression_AssignName');
|
18
system/libs/Twig/Node/Expression/Binary.php → system/libs/Twig/Node/Expression/Binary/AbstractBinary.php
Executable file → Normal file
18
system/libs/Twig/Node/Expression/Binary.php → system/libs/Twig/Node/Expression/Binary/AbstractBinary.php
Executable file → Normal file
@ -9,14 +9,20 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
abstract class Twig_Node_Expression_Binary extends Twig_Node_Expression
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Expression\AbstractExpression;
|
||||||
|
|
||||||
|
abstract class AbstractBinary extends AbstractExpression
|
||||||
{
|
{
|
||||||
public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno)
|
public function __construct(\Twig_NodeInterface $left, \Twig_NodeInterface $right, $lineno)
|
||||||
{
|
{
|
||||||
parent::__construct(array('left' => $left, 'right' => $right), array(), $lineno);
|
parent::__construct(['left' => $left, 'right' => $right], [], $lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->raw('(')
|
->raw('(')
|
||||||
@ -31,7 +37,7 @@ abstract class Twig_Node_Expression_Binary extends Twig_Node_Expression
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public function operator(Twig_Compiler $compiler);
|
abstract public function operator(Compiler $compiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary', 'Twig\Node\Expression\Binary\AbstractBinary', false);
|
class_alias('Twig\Node\Expression\Binary\AbstractBinary', 'Twig_Node_Expression_Binary');
|
11
system/libs/Twig/Node/Expression/Binary/Add.php → system/libs/Twig/Node/Expression/Binary/AddBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/Add.php → system/libs/Twig/Node/Expression/Binary/AddBinary.php
Executable file → Normal file
@ -9,12 +9,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Add extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class AddBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('+');
|
return $compiler->raw('+');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Add', 'Twig\Node\Expression\Binary\AddBinary', false);
|
class_alias('Twig\Node\Expression\Binary\AddBinary', 'Twig_Node_Expression_Binary_Add');
|
11
system/libs/Twig/Node/Expression/Binary/And.php → system/libs/Twig/Node/Expression/Binary/AndBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/And.php → system/libs/Twig/Node/Expression/Binary/AndBinary.php
Executable file → Normal file
@ -9,12 +9,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_And extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class AndBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('&&');
|
return $compiler->raw('&&');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_And', 'Twig\Node\Expression\Binary\AndBinary', false);
|
class_alias('Twig\Node\Expression\Binary\AndBinary', 'Twig_Node_Expression_Binary_And');
|
11
system/libs/Twig/Node/Expression/Binary/BitwiseAnd.php → system/libs/Twig/Node/Expression/Binary/BitwiseAndBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/BitwiseAnd.php → system/libs/Twig/Node/Expression/Binary/BitwiseAndBinary.php
Executable file → Normal file
@ -9,12 +9,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_BitwiseAnd extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class BitwiseAndBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('&');
|
return $compiler->raw('&');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_BitwiseAnd', 'Twig\Node\Expression\Binary\BitwiseAndBinary', false);
|
class_alias('Twig\Node\Expression\Binary\BitwiseAndBinary', 'Twig_Node_Expression_Binary_BitwiseAnd');
|
11
system/libs/Twig/Node/Expression/Binary/BitwiseOr.php → system/libs/Twig/Node/Expression/Binary/BitwiseOrBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/BitwiseOr.php → system/libs/Twig/Node/Expression/Binary/BitwiseOrBinary.php
Executable file → Normal file
@ -9,12 +9,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_BitwiseOr extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class BitwiseOrBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('|');
|
return $compiler->raw('|');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_BitwiseOr', 'Twig\Node\Expression\Binary\BitwiseOrBinary', false);
|
class_alias('Twig\Node\Expression\Binary\BitwiseOrBinary', 'Twig_Node_Expression_Binary_BitwiseOr');
|
11
system/libs/Twig/Node/Expression/Binary/BitwiseXor.php → system/libs/Twig/Node/Expression/Binary/BitwiseXorBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/BitwiseXor.php → system/libs/Twig/Node/Expression/Binary/BitwiseXorBinary.php
Executable file → Normal file
@ -9,12 +9,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_BitwiseXor extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class BitwiseXorBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('^');
|
return $compiler->raw('^');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_BitwiseXor', 'Twig\Node\Expression\Binary\BitwiseXorBinary', false);
|
class_alias('Twig\Node\Expression\Binary\BitwiseXorBinary', 'Twig_Node_Expression_Binary_BitwiseXor');
|
11
system/libs/Twig/Node/Expression/Binary/Concat.php → system/libs/Twig/Node/Expression/Binary/ConcatBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/Concat.php → system/libs/Twig/Node/Expression/Binary/ConcatBinary.php
Executable file → Normal file
@ -9,12 +9,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Concat extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class ConcatBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('.');
|
return $compiler->raw('.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Concat', 'Twig\Node\Expression\Binary\ConcatBinary', false);
|
class_alias('Twig\Node\Expression\Binary\ConcatBinary', 'Twig_Node_Expression_Binary_Concat');
|
11
system/libs/Twig/Node/Expression/Binary/Div.php → system/libs/Twig/Node/Expression/Binary/DivBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/Div.php → system/libs/Twig/Node/Expression/Binary/DivBinary.php
Executable file → Normal file
@ -9,12 +9,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Div extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class DivBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('/');
|
return $compiler->raw('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Div', 'Twig\Node\Expression\Binary\DivBinary', false);
|
class_alias('Twig\Node\Expression\Binary\DivBinary', 'Twig_Node_Expression_Binary_Div');
|
13
system/libs/Twig/Node/Expression/Binary/EndsWith.php → system/libs/Twig/Node/Expression/Binary/EndsWithBinary.php
Executable file → Normal file
13
system/libs/Twig/Node/Expression/Binary/EndsWith.php → system/libs/Twig/Node/Expression/Binary/EndsWithBinary.php
Executable file → Normal file
@ -8,9 +8,14 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_EndsWith extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class EndsWithBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$left = $compiler->getVarName();
|
$left = $compiler->getVarName();
|
||||||
$right = $compiler->getVarName();
|
$right = $compiler->getVarName();
|
||||||
@ -23,10 +28,10 @@ class Twig_Node_Expression_Binary_EndsWith extends Twig_Node_Expression_Binary
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('');
|
return $compiler->raw('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_EndsWith', 'Twig\Node\Expression\Binary\EndsWithBinary', false);
|
class_alias('Twig\Node\Expression\Binary\EndsWithBinary', 'Twig_Node_Expression_Binary_EndsWith');
|
11
system/libs/Twig/Node/Expression/Binary/Equal.php → system/libs/Twig/Node/Expression/Binary/EqualBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/Equal.php → system/libs/Twig/Node/Expression/Binary/EqualBinary.php
Executable file → Normal file
@ -8,12 +8,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Equal extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class EqualBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('==');
|
return $compiler->raw('==');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Equal', 'Twig\Node\Expression\Binary\EqualBinary', false);
|
class_alias('Twig\Node\Expression\Binary\EqualBinary', 'Twig_Node_Expression_Binary_Equal');
|
13
system/libs/Twig/Node/Expression/Binary/FloorDiv.php → system/libs/Twig/Node/Expression/Binary/FloorDivBinary.php
Executable file → Normal file
13
system/libs/Twig/Node/Expression/Binary/FloorDiv.php → system/libs/Twig/Node/Expression/Binary/FloorDivBinary.php
Executable file → Normal file
@ -8,19 +8,24 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_FloorDiv extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class FloorDivBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler->raw('(int) floor(');
|
$compiler->raw('(int) floor(');
|
||||||
parent::compile($compiler);
|
parent::compile($compiler);
|
||||||
$compiler->raw(')');
|
$compiler->raw(')');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('/');
|
return $compiler->raw('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_FloorDiv', 'Twig\Node\Expression\Binary\FloorDivBinary', false);
|
class_alias('Twig\Node\Expression\Binary\FloorDivBinary', 'Twig_Node_Expression_Binary_FloorDiv');
|
11
system/libs/Twig/Node/Expression/Binary/Greater.php → system/libs/Twig/Node/Expression/Binary/GreaterBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/Greater.php → system/libs/Twig/Node/Expression/Binary/GreaterBinary.php
Executable file → Normal file
@ -8,12 +8,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Greater extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class GreaterBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('>');
|
return $compiler->raw('>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Greater', 'Twig\Node\Expression\Binary\GreaterBinary', false);
|
class_alias('Twig\Node\Expression\Binary\GreaterBinary', 'Twig_Node_Expression_Binary_Greater');
|
@ -1,19 +0,0 @@
|
|||||||
<?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.
|
|
||||||
*/
|
|
||||||
class Twig_Node_Expression_Binary_GreaterEqual extends Twig_Node_Expression_Binary
|
|
||||||
{
|
|
||||||
public function operator(Twig_Compiler $compiler)
|
|
||||||
{
|
|
||||||
return $compiler->raw('>=');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_GreaterEqual', 'Twig\Node\Expression\Binary\GreaterEqualBinary', false);
|
|
@ -0,0 +1,24 @@
|
|||||||
|
<?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 GreaterEqualBinary extends AbstractBinary
|
||||||
|
{
|
||||||
|
public function operator(Compiler $compiler)
|
||||||
|
{
|
||||||
|
return $compiler->raw('>=');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class_alias('Twig\Node\Expression\Binary\GreaterEqualBinary', 'Twig_Node_Expression_Binary_GreaterEqual');
|
13
system/libs/Twig/Node/Expression/Binary/In.php → system/libs/Twig/Node/Expression/Binary/InBinary.php
Executable file → Normal file
13
system/libs/Twig/Node/Expression/Binary/In.php → system/libs/Twig/Node/Expression/Binary/InBinary.php
Executable file → Normal file
@ -8,9 +8,14 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_In extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class InBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->raw('twig_in_filter(')
|
->raw('twig_in_filter(')
|
||||||
@ -21,10 +26,10 @@ class Twig_Node_Expression_Binary_In extends Twig_Node_Expression_Binary
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('in');
|
return $compiler->raw('in');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_In', 'Twig\Node\Expression\Binary\InBinary', false);
|
class_alias('Twig\Node\Expression\Binary\InBinary', 'Twig_Node_Expression_Binary_In');
|
11
system/libs/Twig/Node/Expression/Binary/Less.php → system/libs/Twig/Node/Expression/Binary/LessBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/Less.php → system/libs/Twig/Node/Expression/Binary/LessBinary.php
Executable file → Normal file
@ -8,12 +8,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Less extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class LessBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('<');
|
return $compiler->raw('<');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Less', 'Twig\Node\Expression\Binary\LessBinary', false);
|
class_alias('Twig\Node\Expression\Binary\LessBinary', 'Twig_Node_Expression_Binary_Less');
|
@ -1,19 +0,0 @@
|
|||||||
<?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.
|
|
||||||
*/
|
|
||||||
class Twig_Node_Expression_Binary_LessEqual extends Twig_Node_Expression_Binary
|
|
||||||
{
|
|
||||||
public function operator(Twig_Compiler $compiler)
|
|
||||||
{
|
|
||||||
return $compiler->raw('<=');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_LessEqual', 'Twig\Node\Expression\Binary\LessEqualBinary', false);
|
|
24
system/libs/Twig/Node/Expression/Binary/LessEqualBinary.php
Normal file
24
system/libs/Twig/Node/Expression/Binary/LessEqualBinary.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?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 LessEqualBinary extends AbstractBinary
|
||||||
|
{
|
||||||
|
public function operator(Compiler $compiler)
|
||||||
|
{
|
||||||
|
return $compiler->raw('<=');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class_alias('Twig\Node\Expression\Binary\LessEqualBinary', 'Twig_Node_Expression_Binary_LessEqual');
|
13
system/libs/Twig/Node/Expression/Binary/Matches.php → system/libs/Twig/Node/Expression/Binary/MatchesBinary.php
Executable file → Normal file
13
system/libs/Twig/Node/Expression/Binary/Matches.php → system/libs/Twig/Node/Expression/Binary/MatchesBinary.php
Executable file → Normal file
@ -8,9 +8,14 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Matches extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class MatchesBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->raw('preg_match(')
|
->raw('preg_match(')
|
||||||
@ -21,10 +26,10 @@ class Twig_Node_Expression_Binary_Matches extends Twig_Node_Expression_Binary
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('');
|
return $compiler->raw('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Matches', 'Twig\Node\Expression\Binary\MatchesBinary', false);
|
class_alias('Twig\Node\Expression\Binary\MatchesBinary', 'Twig_Node_Expression_Binary_Matches');
|
11
system/libs/Twig/Node/Expression/Binary/Mod.php → system/libs/Twig/Node/Expression/Binary/ModBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/Mod.php → system/libs/Twig/Node/Expression/Binary/ModBinary.php
Executable file → Normal file
@ -9,12 +9,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Mod extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class ModBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('%');
|
return $compiler->raw('%');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Mod', 'Twig\Node\Expression\Binary\ModBinary', false);
|
class_alias('Twig\Node\Expression\Binary\ModBinary', 'Twig_Node_Expression_Binary_Mod');
|
11
system/libs/Twig/Node/Expression/Binary/Mul.php → system/libs/Twig/Node/Expression/Binary/MulBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/Mul.php → system/libs/Twig/Node/Expression/Binary/MulBinary.php
Executable file → Normal file
@ -9,12 +9,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Mul extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class MulBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('*');
|
return $compiler->raw('*');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Mul', 'Twig\Node\Expression\Binary\MulBinary', false);
|
class_alias('Twig\Node\Expression\Binary\MulBinary', 'Twig_Node_Expression_Binary_Mul');
|
11
system/libs/Twig/Node/Expression/Binary/NotEqual.php → system/libs/Twig/Node/Expression/Binary/NotEqualBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/NotEqual.php → system/libs/Twig/Node/Expression/Binary/NotEqualBinary.php
Executable file → Normal file
@ -8,12 +8,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_NotEqual extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class NotEqualBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('!=');
|
return $compiler->raw('!=');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_NotEqual', 'Twig\Node\Expression\Binary\NotEqualBinary', false);
|
class_alias('Twig\Node\Expression\Binary\NotEqualBinary', 'Twig_Node_Expression_Binary_NotEqual');
|
13
system/libs/Twig/Node/Expression/Binary/NotIn.php → system/libs/Twig/Node/Expression/Binary/NotInBinary.php
Executable file → Normal file
13
system/libs/Twig/Node/Expression/Binary/NotIn.php → system/libs/Twig/Node/Expression/Binary/NotInBinary.php
Executable file → Normal file
@ -8,9 +8,14 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_NotIn extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class NotInBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->raw('!twig_in_filter(')
|
->raw('!twig_in_filter(')
|
||||||
@ -21,10 +26,10 @@ class Twig_Node_Expression_Binary_NotIn extends Twig_Node_Expression_Binary
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('not in');
|
return $compiler->raw('not in');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_NotIn', 'Twig\Node\Expression\Binary\NotInBinary', false);
|
class_alias('Twig\Node\Expression\Binary\NotInBinary', 'Twig_Node_Expression_Binary_NotIn');
|
11
system/libs/Twig/Node/Expression/Binary/Or.php → system/libs/Twig/Node/Expression/Binary/OrBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/Or.php → system/libs/Twig/Node/Expression/Binary/OrBinary.php
Executable file → Normal file
@ -9,12 +9,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Or extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class OrBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('||');
|
return $compiler->raw('||');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Or', 'Twig\Node\Expression\Binary\OrBinary', false);
|
class_alias('Twig\Node\Expression\Binary\OrBinary', 'Twig_Node_Expression_Binary_Or');
|
15
system/libs/Twig/Node/Expression/Binary/Power.php → system/libs/Twig/Node/Expression/Binary/PowerBinary.php
Executable file → Normal file
15
system/libs/Twig/Node/Expression/Binary/Power.php → system/libs/Twig/Node/Expression/Binary/PowerBinary.php
Executable file → Normal file
@ -8,11 +8,16 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Power extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class PowerBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
if (PHP_VERSION_ID >= 50600) {
|
if (\PHP_VERSION_ID >= 50600) {
|
||||||
return parent::compile($compiler);
|
return parent::compile($compiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,10 +30,10 @@ class Twig_Node_Expression_Binary_Power extends Twig_Node_Expression_Binary
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('**');
|
return $compiler->raw('**');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Power', 'Twig\Node\Expression\Binary\PowerBinary', false);
|
class_alias('Twig\Node\Expression\Binary\PowerBinary', 'Twig_Node_Expression_Binary_Power');
|
13
system/libs/Twig/Node/Expression/Binary/Range.php → system/libs/Twig/Node/Expression/Binary/RangeBinary.php
Executable file → Normal file
13
system/libs/Twig/Node/Expression/Binary/Range.php → system/libs/Twig/Node/Expression/Binary/RangeBinary.php
Executable file → Normal file
@ -8,9 +8,14 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Range extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class RangeBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->raw('range(')
|
->raw('range(')
|
||||||
@ -21,10 +26,10 @@ class Twig_Node_Expression_Binary_Range extends Twig_Node_Expression_Binary
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('..');
|
return $compiler->raw('..');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Range', 'Twig\Node\Expression\Binary\RangeBinary', false);
|
class_alias('Twig\Node\Expression\Binary\RangeBinary', 'Twig_Node_Expression_Binary_Range');
|
13
system/libs/Twig/Node/Expression/Binary/StartsWith.php → system/libs/Twig/Node/Expression/Binary/StartsWithBinary.php
Executable file → Normal file
13
system/libs/Twig/Node/Expression/Binary/StartsWith.php → system/libs/Twig/Node/Expression/Binary/StartsWithBinary.php
Executable file → Normal file
@ -8,9 +8,14 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_StartsWith extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class StartsWithBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$left = $compiler->getVarName();
|
$left = $compiler->getVarName();
|
||||||
$right = $compiler->getVarName();
|
$right = $compiler->getVarName();
|
||||||
@ -23,10 +28,10 @@ class Twig_Node_Expression_Binary_StartsWith extends Twig_Node_Expression_Binary
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('');
|
return $compiler->raw('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_StartsWith', 'Twig\Node\Expression\Binary\StartsWithBinary', false);
|
class_alias('Twig\Node\Expression\Binary\StartsWithBinary', 'Twig_Node_Expression_Binary_StartsWith');
|
11
system/libs/Twig/Node/Expression/Binary/Sub.php → system/libs/Twig/Node/Expression/Binary/SubBinary.php
Executable file → Normal file
11
system/libs/Twig/Node/Expression/Binary/Sub.php → system/libs/Twig/Node/Expression/Binary/SubBinary.php
Executable file → Normal file
@ -9,12 +9,17 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Binary_Sub extends Twig_Node_Expression_Binary
|
|
||||||
|
namespace Twig\Node\Expression\Binary;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class SubBinary extends AbstractBinary
|
||||||
{
|
{
|
||||||
public function operator(Twig_Compiler $compiler)
|
public function operator(Compiler $compiler)
|
||||||
{
|
{
|
||||||
return $compiler->raw('-');
|
return $compiler->raw('-');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Binary_Sub', 'Twig\Node\Expression\Binary\SubBinary', false);
|
class_alias('Twig\Node\Expression\Binary\SubBinary', 'Twig_Node_Expression_Binary_Sub');
|
25
system/libs/Twig/Node/Expression/BlockReference.php → system/libs/Twig/Node/Expression/BlockReferenceExpression.php
Executable file → Normal file
25
system/libs/Twig/Node/Expression/BlockReference.php → system/libs/Twig/Node/Expression/BlockReferenceExpression.php
Executable file → Normal file
@ -10,33 +10,38 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a block call node.
|
* Represents a block call node.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
|
class BlockReferenceExpression extends AbstractExpression
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param Twig_Node|null $template
|
* @param Node|null $template
|
||||||
*/
|
*/
|
||||||
public function __construct(Twig_NodeInterface $name, $template = null, $lineno, $tag = null)
|
public function __construct(\Twig_NodeInterface $name, $template = null, $lineno, $tag = null)
|
||||||
{
|
{
|
||||||
if (is_bool($template)) {
|
if (\is_bool($template)) {
|
||||||
@trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);
|
@trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);
|
||||||
|
|
||||||
$template = null;
|
$template = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$nodes = array('name' => $name);
|
$nodes = ['name' => $name];
|
||||||
if (null !== $template) {
|
if (null !== $template) {
|
||||||
$nodes['template'] = $template;
|
$nodes['template'] = $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($nodes, array('is_defined_test' => false, 'output' => false), $lineno, $tag);
|
parent::__construct($nodes, ['is_defined_test' => false, 'output' => false], $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
if ($this->getAttribute('is_defined_test')) {
|
if ($this->getAttribute('is_defined_test')) {
|
||||||
$this->compileTemplateCall($compiler, 'hasBlock');
|
$this->compileTemplateCall($compiler, 'hasBlock');
|
||||||
@ -53,7 +58,7 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function compileTemplateCall(Twig_Compiler $compiler, $method)
|
private function compileTemplateCall(Compiler $compiler, $method)
|
||||||
{
|
{
|
||||||
if (!$this->hasNode('template')) {
|
if (!$this->hasNode('template')) {
|
||||||
$compiler->write('$this');
|
$compiler->write('$this');
|
||||||
@ -75,7 +80,7 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
|
|||||||
return $compiler;
|
return $compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function compileBlockArguments(Twig_Compiler $compiler)
|
private function compileBlockArguments(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->raw('(')
|
->raw('(')
|
||||||
@ -90,4 +95,4 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_BlockReference', 'Twig\Node\Expression\BlockReferenceExpression', false);
|
class_alias('Twig\Node\Expression\BlockReferenceExpression', 'Twig_Node_Expression_BlockReference');
|
128
system/libs/Twig/Node/Expression/Call.php → system/libs/Twig/Node/Expression/CallExpression.php
Executable file → Normal file
128
system/libs/Twig/Node/Expression/Call.php → system/libs/Twig/Node/Expression/CallExpression.php
Executable file → Normal file
@ -8,46 +8,56 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
|
||||||
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Error\SyntaxError;
|
||||||
|
use Twig\Extension\ExtensionInterface;
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
|
abstract class CallExpression extends AbstractExpression
|
||||||
{
|
{
|
||||||
private $reflector;
|
private $reflector;
|
||||||
|
|
||||||
protected function compileCallable(Twig_Compiler $compiler)
|
protected function compileCallable(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$closingParenthesis = false;
|
$closingParenthesis = false;
|
||||||
|
$isArray = false;
|
||||||
if ($this->hasAttribute('callable') && $callable = $this->getAttribute('callable')) {
|
if ($this->hasAttribute('callable') && $callable = $this->getAttribute('callable')) {
|
||||||
if (is_string($callable) && false === strpos($callable, '::')) {
|
if (\is_string($callable) && false === strpos($callable, '::')) {
|
||||||
$compiler->raw($callable);
|
$compiler->raw($callable);
|
||||||
} else {
|
} else {
|
||||||
list($r, $callable) = $this->reflectCallable($callable);
|
list($r, $callable) = $this->reflectCallable($callable);
|
||||||
if ($r instanceof ReflectionMethod && is_string($callable[0])) {
|
if ($r instanceof \ReflectionMethod && \is_string($callable[0])) {
|
||||||
if ($r->isStatic()) {
|
if ($r->isStatic()) {
|
||||||
$compiler->raw(sprintf('%s::%s', $callable[0], $callable[1]));
|
$compiler->raw(sprintf('%s::%s', $callable[0], $callable[1]));
|
||||||
} else {
|
} else {
|
||||||
$compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1]));
|
$compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1]));
|
||||||
}
|
}
|
||||||
} elseif ($r instanceof ReflectionMethod && $callable[0] instanceof Twig_ExtensionInterface) {
|
} elseif ($r instanceof \ReflectionMethod && $callable[0] instanceof ExtensionInterface) {
|
||||||
$compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', get_class($callable[0]), $callable[1]));
|
$compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', \get_class($callable[0]), $callable[1]));
|
||||||
} else {
|
} else {
|
||||||
$type = ucfirst($this->getAttribute('type'));
|
$type = ucfirst($this->getAttribute('type'));
|
||||||
$compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), array', $type, $this->getAttribute('name')));
|
$compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), ', $type, $this->getAttribute('name')));
|
||||||
$closingParenthesis = true;
|
$closingParenthesis = true;
|
||||||
|
$isArray = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$compiler->raw($this->getAttribute('thing')->compile());
|
$compiler->raw($this->getAttribute('thing')->compile());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->compileArguments($compiler);
|
$this->compileArguments($compiler, $isArray);
|
||||||
|
|
||||||
if ($closingParenthesis) {
|
if ($closingParenthesis) {
|
||||||
$compiler->raw(')');
|
$compiler->raw(')');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function compileArguments(Twig_Compiler $compiler)
|
protected function compileArguments(Compiler $compiler, $isArray = false)
|
||||||
{
|
{
|
||||||
$compiler->raw('(');
|
$compiler->raw($isArray ? '[' : '(');
|
||||||
|
|
||||||
$first = true;
|
$first = true;
|
||||||
|
|
||||||
@ -96,7 +106,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$compiler->raw(')');
|
$compiler->raw($isArray ? ']' : ')');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getArguments($callable, $arguments)
|
protected function getArguments($callable, $arguments)
|
||||||
@ -104,14 +114,14 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
|||||||
$callType = $this->getAttribute('type');
|
$callType = $this->getAttribute('type');
|
||||||
$callName = $this->getAttribute('name');
|
$callName = $this->getAttribute('name');
|
||||||
|
|
||||||
$parameters = array();
|
$parameters = [];
|
||||||
$named = false;
|
$named = false;
|
||||||
foreach ($arguments as $name => $node) {
|
foreach ($arguments as $name => $node) {
|
||||||
if (!is_int($name)) {
|
if (!\is_int($name)) {
|
||||||
$named = true;
|
$named = true;
|
||||||
$name = $this->normalizeName($name);
|
$name = $this->normalizeName($name);
|
||||||
} elseif ($named) {
|
} elseif ($named) {
|
||||||
throw new Twig_Error_Syntax(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName));
|
throw new SyntaxError(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine(), $this->getSourceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
$parameters[$name] = $node;
|
$parameters[$name] = $node;
|
||||||
@ -129,42 +139,42 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
|||||||
$message = sprintf('Arbitrary positional arguments are not supported for %s "%s".', $callType, $callName);
|
$message = sprintf('Arbitrary positional arguments are not supported for %s "%s".', $callType, $callName);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new LogicException($message);
|
throw new \LogicException($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
$callableParameters = $this->getCallableParameters($callable, $isVariadic);
|
$callableParameters = $this->getCallableParameters($callable, $isVariadic);
|
||||||
$arguments = array();
|
$arguments = [];
|
||||||
$names = array();
|
$names = [];
|
||||||
$missingArguments = array();
|
$missingArguments = [];
|
||||||
$optionalArguments = array();
|
$optionalArguments = [];
|
||||||
$pos = 0;
|
$pos = 0;
|
||||||
foreach ($callableParameters as $callableParameter) {
|
foreach ($callableParameters as $callableParameter) {
|
||||||
$names[] = $name = $this->normalizeName($callableParameter->name);
|
$names[] = $name = $this->normalizeName($callableParameter->name);
|
||||||
|
|
||||||
if (array_key_exists($name, $parameters)) {
|
if (\array_key_exists($name, $parameters)) {
|
||||||
if (array_key_exists($pos, $parameters)) {
|
if (\array_key_exists($pos, $parameters)) {
|
||||||
throw new Twig_Error_Syntax(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName));
|
throw new SyntaxError(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($missingArguments)) {
|
if (\count($missingArguments)) {
|
||||||
throw new Twig_Error_Syntax(sprintf(
|
throw new SyntaxError(sprintf(
|
||||||
'Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".',
|
'Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".',
|
||||||
$name, $callType, $callName, implode(', ', $names), count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments))
|
$name, $callType, $callName, implode(', ', $names), \count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments)
|
||||||
);
|
), $this->getTemplateLine(), $this->getSourceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
$arguments = array_merge($arguments, $optionalArguments);
|
$arguments = array_merge($arguments, $optionalArguments);
|
||||||
$arguments[] = $parameters[$name];
|
$arguments[] = $parameters[$name];
|
||||||
unset($parameters[$name]);
|
unset($parameters[$name]);
|
||||||
$optionalArguments = array();
|
$optionalArguments = [];
|
||||||
} elseif (array_key_exists($pos, $parameters)) {
|
} elseif (\array_key_exists($pos, $parameters)) {
|
||||||
$arguments = array_merge($arguments, $optionalArguments);
|
$arguments = array_merge($arguments, $optionalArguments);
|
||||||
$arguments[] = $parameters[$pos];
|
$arguments[] = $parameters[$pos];
|
||||||
unset($parameters[$pos]);
|
unset($parameters[$pos]);
|
||||||
$optionalArguments = array();
|
$optionalArguments = [];
|
||||||
++$pos;
|
++$pos;
|
||||||
} elseif ($callableParameter->isDefaultValueAvailable()) {
|
} elseif ($callableParameter->isDefaultValueAvailable()) {
|
||||||
$optionalArguments[] = new Twig_Node_Expression_Constant($callableParameter->getDefaultValue(), -1);
|
$optionalArguments[] = new ConstantExpression($callableParameter->getDefaultValue(), -1);
|
||||||
} elseif ($callableParameter->isOptional()) {
|
} elseif ($callableParameter->isOptional()) {
|
||||||
if (empty($parameters)) {
|
if (empty($parameters)) {
|
||||||
break;
|
break;
|
||||||
@ -172,17 +182,17 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
|||||||
$missingArguments[] = $name;
|
$missingArguments[] = $name;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Twig_Error_Syntax(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName));
|
throw new SyntaxError(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine(), $this->getSourceContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($isVariadic) {
|
if ($isVariadic) {
|
||||||
$arbitraryArguments = new Twig_Node_Expression_Array(array(), -1);
|
$arbitraryArguments = new ArrayExpression([], -1);
|
||||||
foreach ($parameters as $key => $value) {
|
foreach ($parameters as $key => $value) {
|
||||||
if (is_int($key)) {
|
if (\is_int($key)) {
|
||||||
$arbitraryArguments->addElement($value);
|
$arbitraryArguments->addElement($value);
|
||||||
} else {
|
} else {
|
||||||
$arbitraryArguments->addElement($value, new Twig_Node_Expression_Constant($key, -1));
|
$arbitraryArguments->addElement($value, new ConstantExpression($key, -1));
|
||||||
}
|
}
|
||||||
unset($parameters[$key]);
|
unset($parameters[$key]);
|
||||||
}
|
}
|
||||||
@ -196,16 +206,20 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
|||||||
if (!empty($parameters)) {
|
if (!empty($parameters)) {
|
||||||
$unknownParameter = null;
|
$unknownParameter = null;
|
||||||
foreach ($parameters as $parameter) {
|
foreach ($parameters as $parameter) {
|
||||||
if ($parameter instanceof Twig_Node) {
|
if ($parameter instanceof Node) {
|
||||||
$unknownParameter = $parameter;
|
$unknownParameter = $parameter;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Twig_Error_Syntax(sprintf(
|
throw new SyntaxError(
|
||||||
'Unknown argument%s "%s" for %s "%s(%s)".',
|
sprintf(
|
||||||
count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names)
|
'Unknown argument%s "%s" for %s "%s(%s)".',
|
||||||
), $unknownParameter ? $unknownParameter->getTemplateLine() : -1);
|
\count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names)
|
||||||
|
),
|
||||||
|
$unknownParameter ? $unknownParameter->getTemplateLine() : $this->getTemplateLine(),
|
||||||
|
$unknownParameter ? $unknownParameter->getSourceContext() : $this->getSourceContext()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $arguments;
|
return $arguments;
|
||||||
@ -213,14 +227,14 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
|||||||
|
|
||||||
protected function normalizeName($name)
|
protected function normalizeName($name)
|
||||||
{
|
{
|
||||||
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), $name));
|
return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCallableParameters($callable, $isVariadic)
|
private function getCallableParameters($callable, $isVariadic)
|
||||||
{
|
{
|
||||||
list($r) = $this->reflectCallable($callable);
|
list($r) = $this->reflectCallable($callable);
|
||||||
if (null === $r) {
|
if (null === $r) {
|
||||||
return array();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$parameters = $r->getParameters();
|
$parameters = $r->getParameters();
|
||||||
@ -240,15 +254,15 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
|||||||
}
|
}
|
||||||
if ($isVariadic) {
|
if ($isVariadic) {
|
||||||
$argument = end($parameters);
|
$argument = end($parameters);
|
||||||
if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && array() === $argument->getDefaultValue()) {
|
if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) {
|
||||||
array_pop($parameters);
|
array_pop($parameters);
|
||||||
} else {
|
} else {
|
||||||
$callableName = $r->name;
|
$callableName = $r->name;
|
||||||
if ($r instanceof ReflectionMethod) {
|
if ($r instanceof \ReflectionMethod) {
|
||||||
$callableName = $r->getDeclaringClass()->name.'::'.$callableName;
|
$callableName = $r->getDeclaringClass()->name.'::'.$callableName;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = array()".', $callableName, $this->getAttribute('type'), $this->getAttribute('name')));
|
throw new \LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = []".', $callableName, $this->getAttribute('type'), $this->getAttribute('name')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,31 +275,31 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
|||||||
return $this->reflector;
|
return $this->reflector;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($callable)) {
|
if (\is_array($callable)) {
|
||||||
if (!method_exists($callable[0], $callable[1])) {
|
if (!method_exists($callable[0], $callable[1])) {
|
||||||
// __call()
|
// __call()
|
||||||
return array(null, array());
|
return [null, []];
|
||||||
}
|
}
|
||||||
$r = new ReflectionMethod($callable[0], $callable[1]);
|
$r = new \ReflectionMethod($callable[0], $callable[1]);
|
||||||
} elseif (is_object($callable) && !$callable instanceof Closure) {
|
} elseif (\is_object($callable) && !$callable instanceof \Closure) {
|
||||||
$r = new ReflectionObject($callable);
|
$r = new \ReflectionObject($callable);
|
||||||
$r = $r->getMethod('__invoke');
|
$r = $r->getMethod('__invoke');
|
||||||
$callable = array($callable, '__invoke');
|
$callable = [$callable, '__invoke'];
|
||||||
} elseif (is_string($callable) && false !== $pos = strpos($callable, '::')) {
|
} elseif (\is_string($callable) && false !== $pos = strpos($callable, '::')) {
|
||||||
$class = substr($callable, 0, $pos);
|
$class = substr($callable, 0, $pos);
|
||||||
$method = substr($callable, $pos + 2);
|
$method = substr($callable, $pos + 2);
|
||||||
if (!method_exists($class, $method)) {
|
if (!method_exists($class, $method)) {
|
||||||
// __staticCall()
|
// __staticCall()
|
||||||
return array(null, array());
|
return [null, []];
|
||||||
}
|
}
|
||||||
$r = new ReflectionMethod($callable);
|
$r = new \ReflectionMethod($callable);
|
||||||
$callable = array($class, $method);
|
$callable = [$class, $method];
|
||||||
} else {
|
} else {
|
||||||
$r = new ReflectionFunction($callable);
|
$r = new \ReflectionFunction($callable);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->reflector = array($r, $callable);
|
return $this->reflector = [$r, $callable];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Call', 'Twig\Node\Expression\CallExpression', false);
|
class_alias('Twig\Node\Expression\CallExpression', 'Twig_Node_Expression_Call');
|
15
system/libs/Twig/Node/Expression/Conditional.php → system/libs/Twig/Node/Expression/ConditionalExpression.php
Executable file → Normal file
15
system/libs/Twig/Node/Expression/Conditional.php → system/libs/Twig/Node/Expression/ConditionalExpression.php
Executable file → Normal file
@ -9,14 +9,19 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Conditional extends Twig_Node_Expression
|
|
||||||
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class ConditionalExpression extends AbstractExpression
|
||||||
{
|
{
|
||||||
public function __construct(Twig_Node_Expression $expr1, Twig_Node_Expression $expr2, Twig_Node_Expression $expr3, $lineno)
|
public function __construct(AbstractExpression $expr1, AbstractExpression $expr2, AbstractExpression $expr3, $lineno)
|
||||||
{
|
{
|
||||||
parent::__construct(array('expr1' => $expr1, 'expr2' => $expr2, 'expr3' => $expr3), array(), $lineno);
|
parent::__construct(['expr1' => $expr1, 'expr2' => $expr2, 'expr3' => $expr3], [], $lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->raw('((')
|
->raw('((')
|
||||||
@ -30,4 +35,4 @@ class Twig_Node_Expression_Conditional extends Twig_Node_Expression
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Conditional', 'Twig\Node\Expression\ConditionalExpression', false);
|
class_alias('Twig\Node\Expression\ConditionalExpression', 'Twig_Node_Expression_Conditional');
|
13
system/libs/Twig/Node/Expression/Constant.php → system/libs/Twig/Node/Expression/ConstantExpression.php
Executable file → Normal file
13
system/libs/Twig/Node/Expression/Constant.php → system/libs/Twig/Node/Expression/ConstantExpression.php
Executable file → Normal file
@ -9,17 +9,22 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Constant extends Twig_Node_Expression
|
|
||||||
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class ConstantExpression extends AbstractExpression
|
||||||
{
|
{
|
||||||
public function __construct($value, $lineno)
|
public function __construct($value, $lineno)
|
||||||
{
|
{
|
||||||
parent::__construct(array(), array('value' => $value), $lineno);
|
parent::__construct([], ['value' => $value], $lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler->repr($this->getAttribute('value'));
|
$compiler->repr($this->getAttribute('value'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Constant', 'Twig\Node\Expression\ConstantExpression', false);
|
class_alias('Twig\Node\Expression\ConstantExpression', 'Twig_Node_Expression_Constant');
|
@ -1,45 +0,0 @@
|
|||||||
<?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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the value or the default value when it is undefined or empty.
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* {{ var.foo|default('foo item on var is not defined') }}
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
|
||||||
*/
|
|
||||||
class Twig_Node_Expression_Filter_Default extends Twig_Node_Expression_Filter
|
|
||||||
{
|
|
||||||
public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null)
|
|
||||||
{
|
|
||||||
$default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine());
|
|
||||||
|
|
||||||
if ('default' === $filterName->getAttribute('value') && ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr)) {
|
|
||||||
$test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node->getTemplateLine());
|
|
||||||
$false = count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getTemplateLine());
|
|
||||||
|
|
||||||
$node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getTemplateLine());
|
|
||||||
} else {
|
|
||||||
$node = $default;
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::__construct($node, $filterName, $arguments, $lineno, $tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
|
||||||
{
|
|
||||||
$compiler->subcompile($this->getNode('node'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Filter_Default', 'Twig\Node\Expression\Filter\DefaultFilter', false);
|
|
54
system/libs/Twig/Node/Expression/Filter/DefaultFilter.php
Normal file
54
system/libs/Twig/Node/Expression/Filter/DefaultFilter.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?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\Filter;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Expression\ConditionalExpression;
|
||||||
|
use Twig\Node\Expression\ConstantExpression;
|
||||||
|
use Twig\Node\Expression\FilterExpression;
|
||||||
|
use Twig\Node\Expression\GetAttrExpression;
|
||||||
|
use Twig\Node\Expression\NameExpression;
|
||||||
|
use Twig\Node\Expression\Test\DefinedTest;
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value or the default value when it is undefined or empty.
|
||||||
|
*
|
||||||
|
* {{ var.foo|default('foo item on var is not defined') }}
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*/
|
||||||
|
class DefaultFilter extends FilterExpression
|
||||||
|
{
|
||||||
|
public function __construct(\Twig_NodeInterface $node, ConstantExpression $filterName, \Twig_NodeInterface $arguments, $lineno, $tag = null)
|
||||||
|
{
|
||||||
|
$default = new FilterExpression($node, new ConstantExpression('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine());
|
||||||
|
|
||||||
|
if ('default' === $filterName->getAttribute('value') && ($node instanceof NameExpression || $node instanceof GetAttrExpression)) {
|
||||||
|
$test = new DefinedTest(clone $node, 'defined', new Node(), $node->getTemplateLine());
|
||||||
|
$false = \count($arguments) ? $arguments->getNode(0) : new ConstantExpression('', $node->getTemplateLine());
|
||||||
|
|
||||||
|
$node = new ConditionalExpression($test, $default, $false, $node->getTemplateLine());
|
||||||
|
} else {
|
||||||
|
$node = $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::__construct($node, $filterName, $arguments, $lineno, $tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function compile(Compiler $compiler)
|
||||||
|
{
|
||||||
|
$compiler->subcompile($this->getNode('node'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class_alias('Twig\Node\Expression\Filter\DefaultFilter', 'Twig_Node_Expression_Filter_Default');
|
20
system/libs/Twig/Node/Expression/Filter.php → system/libs/Twig/Node/Expression/FilterExpression.php
Executable file → Normal file
20
system/libs/Twig/Node/Expression/Filter.php → system/libs/Twig/Node/Expression/FilterExpression.php
Executable file → Normal file
@ -9,14 +9,20 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Filter extends Twig_Node_Expression_Call
|
|
||||||
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\TwigFilter;
|
||||||
|
|
||||||
|
class FilterExpression extends CallExpression
|
||||||
{
|
{
|
||||||
public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null)
|
public function __construct(\Twig_NodeInterface $node, ConstantExpression $filterName, \Twig_NodeInterface $arguments, $lineno, $tag = null)
|
||||||
{
|
{
|
||||||
parent::__construct(array('node' => $node, 'filter' => $filterName, 'arguments' => $arguments), array(), $lineno, $tag);
|
parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$name = $this->getNode('filter')->getAttribute('value');
|
$name = $this->getNode('filter')->getAttribute('value');
|
||||||
$filter = $compiler->getEnvironment()->getFilter($name);
|
$filter = $compiler->getEnvironment()->getFilter($name);
|
||||||
@ -27,10 +33,10 @@ class Twig_Node_Expression_Filter extends Twig_Node_Expression_Call
|
|||||||
$this->setAttribute('needs_environment', $filter->needsEnvironment());
|
$this->setAttribute('needs_environment', $filter->needsEnvironment());
|
||||||
$this->setAttribute('needs_context', $filter->needsContext());
|
$this->setAttribute('needs_context', $filter->needsContext());
|
||||||
$this->setAttribute('arguments', $filter->getArguments());
|
$this->setAttribute('arguments', $filter->getArguments());
|
||||||
if ($filter instanceof Twig_FilterCallableInterface || $filter instanceof Twig_SimpleFilter) {
|
if ($filter instanceof \Twig_FilterCallableInterface || $filter instanceof TwigFilter) {
|
||||||
$this->setAttribute('callable', $filter->getCallable());
|
$this->setAttribute('callable', $filter->getCallable());
|
||||||
}
|
}
|
||||||
if ($filter instanceof Twig_SimpleFilter) {
|
if ($filter instanceof TwigFilter) {
|
||||||
$this->setAttribute('is_variadic', $filter->isVariadic());
|
$this->setAttribute('is_variadic', $filter->isVariadic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,4 +44,4 @@ class Twig_Node_Expression_Filter extends Twig_Node_Expression_Call
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Filter', 'Twig\Node\Expression\FilterExpression', false);
|
class_alias('Twig\Node\Expression\FilterExpression', 'Twig_Node_Expression_Filter');
|
20
system/libs/Twig/Node/Expression/Function.php → system/libs/Twig/Node/Expression/FunctionExpression.php
Executable file → Normal file
20
system/libs/Twig/Node/Expression/Function.php → system/libs/Twig/Node/Expression/FunctionExpression.php
Executable file → Normal file
@ -8,14 +8,20 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Function extends Twig_Node_Expression_Call
|
|
||||||
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
|
class FunctionExpression extends CallExpression
|
||||||
{
|
{
|
||||||
public function __construct($name, Twig_NodeInterface $arguments, $lineno)
|
public function __construct($name, \Twig_NodeInterface $arguments, $lineno)
|
||||||
{
|
{
|
||||||
parent::__construct(array('arguments' => $arguments), array('name' => $name, 'is_defined_test' => false), $lineno);
|
parent::__construct(['arguments' => $arguments], ['name' => $name, 'is_defined_test' => false], $lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$name = $this->getAttribute('name');
|
$name = $this->getAttribute('name');
|
||||||
$function = $compiler->getEnvironment()->getFunction($name);
|
$function = $compiler->getEnvironment()->getFunction($name);
|
||||||
@ -26,7 +32,7 @@ class Twig_Node_Expression_Function extends Twig_Node_Expression_Call
|
|||||||
$this->setAttribute('needs_environment', $function->needsEnvironment());
|
$this->setAttribute('needs_environment', $function->needsEnvironment());
|
||||||
$this->setAttribute('needs_context', $function->needsContext());
|
$this->setAttribute('needs_context', $function->needsContext());
|
||||||
$this->setAttribute('arguments', $function->getArguments());
|
$this->setAttribute('arguments', $function->getArguments());
|
||||||
if ($function instanceof Twig_FunctionCallableInterface || $function instanceof Twig_SimpleFunction) {
|
if ($function instanceof \Twig_FunctionCallableInterface || $function instanceof TwigFunction) {
|
||||||
$callable = $function->getCallable();
|
$callable = $function->getCallable();
|
||||||
if ('constant' === $name && $this->getAttribute('is_defined_test')) {
|
if ('constant' === $name && $this->getAttribute('is_defined_test')) {
|
||||||
$callable = 'twig_constant_is_defined';
|
$callable = 'twig_constant_is_defined';
|
||||||
@ -34,7 +40,7 @@ class Twig_Node_Expression_Function extends Twig_Node_Expression_Call
|
|||||||
|
|
||||||
$this->setAttribute('callable', $callable);
|
$this->setAttribute('callable', $callable);
|
||||||
}
|
}
|
||||||
if ($function instanceof Twig_SimpleFunction) {
|
if ($function instanceof TwigFunction) {
|
||||||
$this->setAttribute('is_variadic', $function->isVariadic());
|
$this->setAttribute('is_variadic', $function->isVariadic());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,4 +48,4 @@ class Twig_Node_Expression_Function extends Twig_Node_Expression_Call
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Function', 'Twig\Node\Expression\FunctionExpression', false);
|
class_alias('Twig\Node\Expression\FunctionExpression', 'Twig_Node_Expression_Function');
|
24
system/libs/Twig/Node/Expression/GetAttr.php → system/libs/Twig/Node/Expression/GetAttrExpression.php
Executable file → Normal file
24
system/libs/Twig/Node/Expression/GetAttr.php → system/libs/Twig/Node/Expression/GetAttrExpression.php
Executable file → Normal file
@ -9,25 +9,31 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
|
|
||||||
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Template;
|
||||||
|
|
||||||
|
class GetAttrExpression extends AbstractExpression
|
||||||
{
|
{
|
||||||
public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_Node_Expression $arguments = null, $type, $lineno)
|
public function __construct(AbstractExpression $node, AbstractExpression $attribute, AbstractExpression $arguments = null, $type, $lineno)
|
||||||
{
|
{
|
||||||
$nodes = array('node' => $node, 'attribute' => $attribute);
|
$nodes = ['node' => $node, 'attribute' => $attribute];
|
||||||
if (null !== $arguments) {
|
if (null !== $arguments) {
|
||||||
$nodes['arguments'] = $arguments;
|
$nodes['arguments'] = $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($nodes, array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false), $lineno);
|
parent::__construct($nodes, ['type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false], $lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
if ($this->getAttribute('disable_c_ext')) {
|
if ($this->getAttribute('disable_c_ext')) {
|
||||||
@trigger_error(sprintf('Using the "disable_c_ext" attribute on %s is deprecated since version 1.30 and will be removed in 2.0.', __CLASS__), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Using the "disable_c_ext" attribute on %s is deprecated since version 1.30 and will be removed in 2.0.', __CLASS__), E_USER_DEPRECATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) {
|
if (\function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) {
|
||||||
$compiler->raw('twig_template_get_attributes($this, ');
|
$compiler->raw('twig_template_get_attributes($this, ');
|
||||||
} else {
|
} else {
|
||||||
$compiler->raw('$this->getAttribute(');
|
$compiler->raw('$this->getAttribute(');
|
||||||
@ -44,14 +50,14 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
|
|||||||
// only generate optional arguments when needed (to make generated code more readable)
|
// only generate optional arguments when needed (to make generated code more readable)
|
||||||
$needFourth = $this->getAttribute('ignore_strict_check');
|
$needFourth = $this->getAttribute('ignore_strict_check');
|
||||||
$needThird = $needFourth || $this->getAttribute('is_defined_test');
|
$needThird = $needFourth || $this->getAttribute('is_defined_test');
|
||||||
$needSecond = $needThird || Twig_Template::ANY_CALL !== $this->getAttribute('type');
|
$needSecond = $needThird || Template::ANY_CALL !== $this->getAttribute('type');
|
||||||
$needFirst = $needSecond || $this->hasNode('arguments');
|
$needFirst = $needSecond || $this->hasNode('arguments');
|
||||||
|
|
||||||
if ($needFirst) {
|
if ($needFirst) {
|
||||||
if ($this->hasNode('arguments')) {
|
if ($this->hasNode('arguments')) {
|
||||||
$compiler->raw(', ')->subcompile($this->getNode('arguments'));
|
$compiler->raw(', ')->subcompile($this->getNode('arguments'));
|
||||||
} else {
|
} else {
|
||||||
$compiler->raw(', array()');
|
$compiler->raw(', []');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,4 +77,4 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_GetAttr', 'Twig\Node\Expression\GetAttrExpression', false);
|
class_alias('Twig\Node\Expression\GetAttrExpression', 'Twig_Node_Expression_GetAttr');
|
35
system/libs/Twig/Node/Expression/InlinePrint.php
Normal file
35
system/libs/Twig/Node/Expression/InlinePrint.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class InlinePrint extends AbstractExpression
|
||||||
|
{
|
||||||
|
public function __construct(Node $node, $lineno)
|
||||||
|
{
|
||||||
|
parent::__construct(['node' => $node], [], $lineno);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function compile(Compiler $compiler)
|
||||||
|
{
|
||||||
|
$compiler
|
||||||
|
->raw('print (')
|
||||||
|
->subcompile($this->getNode('node'))
|
||||||
|
->raw(')')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
21
system/libs/Twig/Node/Expression/MethodCall.php → system/libs/Twig/Node/Expression/MethodCallExpression.php
Executable file → Normal file
21
system/libs/Twig/Node/Expression/MethodCall.php → system/libs/Twig/Node/Expression/MethodCallExpression.php
Executable file → Normal file
@ -8,18 +8,23 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_MethodCall extends Twig_Node_Expression
|
|
||||||
{
|
|
||||||
public function __construct(Twig_Node_Expression $node, $method, Twig_Node_Expression_Array $arguments, $lineno)
|
|
||||||
{
|
|
||||||
parent::__construct(array('node' => $node, 'arguments' => $arguments), array('method' => $method, 'safe' => false), $lineno);
|
|
||||||
|
|
||||||
if ($node instanceof Twig_Node_Expression_Name) {
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class MethodCallExpression extends AbstractExpression
|
||||||
|
{
|
||||||
|
public function __construct(AbstractExpression $node, $method, ArrayExpression $arguments, $lineno)
|
||||||
|
{
|
||||||
|
parent::__construct(['node' => $node, 'arguments' => $arguments], ['method' => $method, 'safe' => false], $lineno);
|
||||||
|
|
||||||
|
if ($node instanceof NameExpression) {
|
||||||
$node->setAttribute('always_defined', true);
|
$node->setAttribute('always_defined', true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->subcompile($this->getNode('node'))
|
->subcompile($this->getNode('node'))
|
||||||
@ -40,4 +45,4 @@ class Twig_Node_Expression_MethodCall extends Twig_Node_Expression
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_MethodCall', 'Twig\Node\Expression\MethodCallExpression', false);
|
class_alias('Twig\Node\Expression\MethodCallExpression', 'Twig_Node_Expression_MethodCall');
|
35
system/libs/Twig/Node/Expression/Name.php → system/libs/Twig/Node/Expression/NameExpression.php
Executable file → Normal file
35
system/libs/Twig/Node/Expression/Name.php → system/libs/Twig/Node/Expression/NameExpression.php
Executable file → Normal file
@ -9,20 +9,25 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Name extends Twig_Node_Expression
|
|
||||||
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class NameExpression extends AbstractExpression
|
||||||
{
|
{
|
||||||
protected $specialVars = array(
|
protected $specialVars = [
|
||||||
'_self' => '$this',
|
'_self' => '$this',
|
||||||
'_context' => '$context',
|
'_context' => '$context',
|
||||||
'_charset' => '$this->env->getCharset()',
|
'_charset' => '$this->env->getCharset()',
|
||||||
);
|
];
|
||||||
|
|
||||||
public function __construct($name, $lineno)
|
public function __construct($name, $lineno)
|
||||||
{
|
{
|
||||||
parent::__construct(array(), array('name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false), $lineno);
|
parent::__construct([], ['name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false], $lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$name = $this->getAttribute('name');
|
$name = $this->getAttribute('name');
|
||||||
|
|
||||||
@ -31,8 +36,20 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
|
|||||||
if ($this->getAttribute('is_defined_test')) {
|
if ($this->getAttribute('is_defined_test')) {
|
||||||
if ($this->isSpecial()) {
|
if ($this->isSpecial()) {
|
||||||
$compiler->repr(true);
|
$compiler->repr(true);
|
||||||
|
} elseif (\PHP_VERSION_ID >= 700400) {
|
||||||
|
$compiler
|
||||||
|
->raw('array_key_exists(')
|
||||||
|
->string($name)
|
||||||
|
->raw(', $context)')
|
||||||
|
;
|
||||||
} else {
|
} else {
|
||||||
$compiler->raw('array_key_exists(')->repr($name)->raw(', $context)');
|
$compiler
|
||||||
|
->raw('(isset($context[')
|
||||||
|
->string($name)
|
||||||
|
->raw(']) || array_key_exists(')
|
||||||
|
->string($name)
|
||||||
|
->raw(', $context))')
|
||||||
|
;
|
||||||
}
|
}
|
||||||
} elseif ($this->isSpecial()) {
|
} elseif ($this->isSpecial()) {
|
||||||
$compiler->raw($this->specialVars[$name]);
|
$compiler->raw($this->specialVars[$name]);
|
||||||
@ -43,7 +60,7 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
|
|||||||
->raw(']')
|
->raw(']')
|
||||||
;
|
;
|
||||||
} else {
|
} else {
|
||||||
if (PHP_VERSION_ID >= 70000) {
|
if (\PHP_VERSION_ID >= 70000) {
|
||||||
// use PHP 7 null coalescing operator
|
// use PHP 7 null coalescing operator
|
||||||
$compiler
|
$compiler
|
||||||
->raw('($context[')
|
->raw('($context[')
|
||||||
@ -56,7 +73,7 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
|
|||||||
} else {
|
} else {
|
||||||
$compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
|
$compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
|
||||||
}
|
}
|
||||||
} elseif (PHP_VERSION_ID >= 50400) {
|
} elseif (\PHP_VERSION_ID >= 50400) {
|
||||||
// PHP 5.4 ternary operator performance was optimized
|
// PHP 5.4 ternary operator performance was optimized
|
||||||
$compiler
|
$compiler
|
||||||
->raw('(isset($context[')
|
->raw('(isset($context[')
|
||||||
@ -99,4 +116,4 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Name', 'Twig\Node\Expression\NameExpression', false);
|
class_alias('Twig\Node\Expression\NameExpression', 'Twig_Node_Expression_Name');
|
@ -1,48 +0,0 @@
|
|||||||
<?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.
|
|
||||||
*/
|
|
||||||
class Twig_Node_Expression_NullCoalesce extends Twig_Node_Expression_Conditional
|
|
||||||
{
|
|
||||||
public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno)
|
|
||||||
{
|
|
||||||
$test = new Twig_Node_Expression_Binary_And(
|
|
||||||
new Twig_Node_Expression_Test_Defined(clone $left, 'defined', new Twig_Node(), $left->getTemplateLine()),
|
|
||||||
new Twig_Node_Expression_Unary_Not(new Twig_Node_Expression_Test_Null($left, 'null', new Twig_Node(), $left->getTemplateLine()), $left->getTemplateLine()),
|
|
||||||
$left->getTemplateLine()
|
|
||||||
);
|
|
||||||
|
|
||||||
parent::__construct($test, $left, $right, $lineno);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* This optimizes only one case. PHP 7 also supports more complex expressions
|
|
||||||
* that can return null. So, for instance, if log is defined, log("foo") ?? "..." works,
|
|
||||||
* but log($a["foo"]) ?? "..." does not if $a["foo"] is not defined. More advanced
|
|
||||||
* cases might be implemented as an optimizer node visitor, but has not been done
|
|
||||||
* as benefits are probably not worth the added complexity.
|
|
||||||
*/
|
|
||||||
if (PHP_VERSION_ID >= 70000 && $this->getNode('expr2') instanceof Twig_Node_Expression_Name) {
|
|
||||||
$this->getNode('expr2')->setAttribute('always_defined', true);
|
|
||||||
$compiler
|
|
||||||
->raw('((')
|
|
||||||
->subcompile($this->getNode('expr2'))
|
|
||||||
->raw(') ?? (')
|
|
||||||
->subcompile($this->getNode('expr3'))
|
|
||||||
->raw('))')
|
|
||||||
;
|
|
||||||
} else {
|
|
||||||
parent::compile($compiler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_NullCoalesce', 'Twig\Node\Expression\NullCoalesceExpression', false);
|
|
62
system/libs/Twig/Node/Expression/NullCoalesceExpression.php
Normal file
62
system/libs/Twig/Node/Expression/NullCoalesceExpression.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Expression\Binary\AndBinary;
|
||||||
|
use Twig\Node\Expression\Test\DefinedTest;
|
||||||
|
use Twig\Node\Expression\Test\NullTest;
|
||||||
|
use Twig\Node\Expression\Unary\NotUnary;
|
||||||
|
use Twig\Node\Node;
|
||||||
|
|
||||||
|
class NullCoalesceExpression extends ConditionalExpression
|
||||||
|
{
|
||||||
|
public function __construct(\Twig_NodeInterface $left, \Twig_NodeInterface $right, $lineno)
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function compile(Compiler $compiler)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* This optimizes only one case. PHP 7 also supports more complex expressions
|
||||||
|
* that can return null. So, for instance, if log is defined, log("foo") ?? "..." works,
|
||||||
|
* but log($a["foo"]) ?? "..." does not if $a["foo"] is not defined. More advanced
|
||||||
|
* cases might be implemented as an optimizer node visitor, but has not been done
|
||||||
|
* as benefits are probably not worth the added complexity.
|
||||||
|
*/
|
||||||
|
if (\PHP_VERSION_ID >= 70000 && $this->getNode('expr2') instanceof NameExpression) {
|
||||||
|
$this->getNode('expr2')->setAttribute('always_defined', true);
|
||||||
|
$compiler
|
||||||
|
->raw('((')
|
||||||
|
->subcompile($this->getNode('expr2'))
|
||||||
|
->raw(') ?? (')
|
||||||
|
->subcompile($this->getNode('expr3'))
|
||||||
|
->raw('))')
|
||||||
|
;
|
||||||
|
} else {
|
||||||
|
parent::compile($compiler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class_alias('Twig\Node\Expression\NullCoalesceExpression', 'Twig_Node_Expression_NullCoalesce');
|
12
system/libs/Twig/Node/Expression/Parent.php → system/libs/Twig/Node/Expression/ParentExpression.php
Executable file → Normal file
12
system/libs/Twig/Node/Expression/Parent.php → system/libs/Twig/Node/Expression/ParentExpression.php
Executable file → Normal file
@ -10,19 +10,23 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a parent node.
|
* Represents a parent node.
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Parent extends Twig_Node_Expression
|
class ParentExpression extends AbstractExpression
|
||||||
{
|
{
|
||||||
public function __construct($name, $lineno, $tag = null)
|
public function __construct($name, $lineno, $tag = null)
|
||||||
{
|
{
|
||||||
parent::__construct(array(), array('output' => false, 'name' => $name), $lineno, $tag);
|
parent::__construct([], ['output' => false, 'name' => $name], $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
if ($this->getAttribute('output')) {
|
if ($this->getAttribute('output')) {
|
||||||
$compiler
|
$compiler
|
||||||
@ -41,4 +45,4 @@ class Twig_Node_Expression_Parent extends Twig_Node_Expression
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Parent', 'Twig\Node\Expression\ParentExpression', false);
|
class_alias('Twig\Node\Expression\ParentExpression', 'Twig_Node_Expression_Parent');
|
13
system/libs/Twig/Node/Expression/TempName.php → system/libs/Twig/Node/Expression/TempNameExpression.php
Executable file → Normal file
13
system/libs/Twig/Node/Expression/TempName.php → system/libs/Twig/Node/Expression/TempNameExpression.php
Executable file → Normal file
@ -8,14 +8,19 @@
|
|||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_TempName extends Twig_Node_Expression
|
|
||||||
|
namespace Twig\Node\Expression;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
|
||||||
|
class TempNameExpression extends AbstractExpression
|
||||||
{
|
{
|
||||||
public function __construct($name, $lineno)
|
public function __construct($name, $lineno)
|
||||||
{
|
{
|
||||||
parent::__construct(array(), array('name' => $name), $lineno);
|
parent::__construct([], ['name' => $name], $lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->raw('$_')
|
->raw('$_')
|
||||||
@ -25,4 +30,4 @@ class Twig_Node_Expression_TempName extends Twig_Node_Expression
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_TempName', 'Twig\Node\Expression\TempNameExpression', false);
|
class_alias('Twig\Node\Expression\TempNameExpression', 'Twig_Node_Expression_TempName');
|
19
system/libs/Twig/Node/Expression/Test/Constant.php → system/libs/Twig/Node/Expression/Test/ConstantTest.php
Executable file → Normal file
19
system/libs/Twig/Node/Expression/Test/Constant.php → system/libs/Twig/Node/Expression/Test/ConstantTest.php
Executable file → Normal file
@ -9,20 +9,23 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Node\Expression\Test;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Expression\TestExpression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a variable is the exact same value as a constant.
|
* Checks if a variable is the exact same value as a constant.
|
||||||
*
|
*
|
||||||
* <pre>
|
* {% if post.status is constant('Post::PUBLISHED') %}
|
||||||
* {% if post.status is constant('Post::PUBLISHED') %}
|
* the status attribute is exactly the same as Post::PUBLISHED
|
||||||
* the status attribute is exactly the same as Post::PUBLISHED
|
* {% endif %}
|
||||||
* {% endif %}
|
|
||||||
* </pre>
|
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Test_Constant extends Twig_Node_Expression_Test
|
class ConstantTest extends TestExpression
|
||||||
{
|
{
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->raw('(')
|
->raw('(')
|
||||||
@ -45,4 +48,4 @@ class Twig_Node_Expression_Test_Constant extends Twig_Node_Expression_Test
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Test_Constant', 'Twig\Node\Expression\Test\ConstantTest', false);
|
class_alias('Twig\Node\Expression\Test\ConstantTest', 'Twig_Node_Expression_Test_Constant');
|
@ -1,61 +0,0 @@
|
|||||||
<?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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a variable is defined in the current context.
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
* {# defined works with variable names and variable attributes #}
|
|
||||||
* {% if foo is defined %}
|
|
||||||
* {# ... #}
|
|
||||||
* {% endif %}
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
|
||||||
*/
|
|
||||||
class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test
|
|
||||||
{
|
|
||||||
public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno)
|
|
||||||
{
|
|
||||||
if ($node instanceof Twig_Node_Expression_Name) {
|
|
||||||
$node->setAttribute('is_defined_test', true);
|
|
||||||
} elseif ($node instanceof Twig_Node_Expression_GetAttr) {
|
|
||||||
$node->setAttribute('is_defined_test', true);
|
|
||||||
$this->changeIgnoreStrictCheck($node);
|
|
||||||
} elseif ($node instanceof Twig_Node_Expression_BlockReference) {
|
|
||||||
$node->setAttribute('is_defined_test', true);
|
|
||||||
} elseif ($node instanceof Twig_Node_Expression_Function && 'constant' === $node->getAttribute('name')) {
|
|
||||||
$node->setAttribute('is_defined_test', true);
|
|
||||||
} elseif ($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array) {
|
|
||||||
$node = new Twig_Node_Expression_Constant(true, $node->getTemplateLine());
|
|
||||||
} else {
|
|
||||||
throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getTemplateLine());
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::__construct($node, $name, $arguments, $lineno);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node)
|
|
||||||
{
|
|
||||||
$node->setAttribute('ignore_strict_check', true);
|
|
||||||
|
|
||||||
if ($node->getNode('node') instanceof Twig_Node_Expression_GetAttr) {
|
|
||||||
$this->changeIgnoreStrictCheck($node->getNode('node'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function compile(Twig_Compiler $compiler)
|
|
||||||
{
|
|
||||||
$compiler->subcompile($this->getNode('node'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Test_Defined', 'Twig\Node\Expression\Test\DefinedTest', false);
|
|
71
system/libs/Twig/Node/Expression/Test/DefinedTest.php
Normal file
71
system/libs/Twig/Node/Expression/Test/DefinedTest.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?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\Test;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Error\SyntaxError;
|
||||||
|
use Twig\Node\Expression\ArrayExpression;
|
||||||
|
use Twig\Node\Expression\BlockReferenceExpression;
|
||||||
|
use Twig\Node\Expression\ConstantExpression;
|
||||||
|
use Twig\Node\Expression\FunctionExpression;
|
||||||
|
use Twig\Node\Expression\GetAttrExpression;
|
||||||
|
use Twig\Node\Expression\NameExpression;
|
||||||
|
use Twig\Node\Expression\TestExpression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a variable is defined in the current context.
|
||||||
|
*
|
||||||
|
* {# defined works with variable names and variable attributes #}
|
||||||
|
* {% if foo is defined %}
|
||||||
|
* {# ... #}
|
||||||
|
* {% endif %}
|
||||||
|
*
|
||||||
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
|
*/
|
||||||
|
class DefinedTest extends TestExpression
|
||||||
|
{
|
||||||
|
public function __construct(\Twig_NodeInterface $node, $name, \Twig_NodeInterface $arguments = null, $lineno)
|
||||||
|
{
|
||||||
|
if ($node instanceof NameExpression) {
|
||||||
|
$node->setAttribute('is_defined_test', true);
|
||||||
|
} elseif ($node instanceof GetAttrExpression) {
|
||||||
|
$node->setAttribute('is_defined_test', true);
|
||||||
|
$this->changeIgnoreStrictCheck($node);
|
||||||
|
} elseif ($node instanceof BlockReferenceExpression) {
|
||||||
|
$node->setAttribute('is_defined_test', true);
|
||||||
|
} elseif ($node instanceof FunctionExpression && 'constant' === $node->getAttribute('name')) {
|
||||||
|
$node->setAttribute('is_defined_test', true);
|
||||||
|
} elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) {
|
||||||
|
$node = new ConstantExpression(true, $node->getTemplateLine());
|
||||||
|
} else {
|
||||||
|
throw new SyntaxError('The "defined" test only works with simple variables.', $lineno);
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::__construct($node, $name, $arguments, $lineno);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function changeIgnoreStrictCheck(GetAttrExpression $node)
|
||||||
|
{
|
||||||
|
$node->setAttribute('ignore_strict_check', true);
|
||||||
|
|
||||||
|
if ($node->getNode('node') instanceof GetAttrExpression) {
|
||||||
|
$this->changeIgnoreStrictCheck($node->getNode('node'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function compile(Compiler $compiler)
|
||||||
|
{
|
||||||
|
$compiler->subcompile($this->getNode('node'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class_alias('Twig\Node\Expression\Test\DefinedTest', 'Twig_Node_Expression_Test_Defined');
|
13
system/libs/Twig/Node/Expression/Test/Divisibleby.php → system/libs/Twig/Node/Expression/Test/DivisiblebyTest.php
Executable file → Normal file
13
system/libs/Twig/Node/Expression/Test/Divisibleby.php → system/libs/Twig/Node/Expression/Test/DivisiblebyTest.php
Executable file → Normal file
@ -9,18 +9,21 @@
|
|||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Twig\Node\Expression\Test;
|
||||||
|
|
||||||
|
use Twig\Compiler;
|
||||||
|
use Twig\Node\Expression\TestExpression;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a variable is divisible by a number.
|
* Checks if a variable is divisible by a number.
|
||||||
*
|
*
|
||||||
* <pre>
|
|
||||||
* {% if loop.index is divisible by(3) %}
|
* {% if loop.index is divisible by(3) %}
|
||||||
* </pre>
|
|
||||||
*
|
*
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
* @author Fabien Potencier <fabien@symfony.com>
|
||||||
*/
|
*/
|
||||||
class Twig_Node_Expression_Test_Divisibleby extends Twig_Node_Expression_Test
|
class DivisiblebyTest extends TestExpression
|
||||||
{
|
{
|
||||||
public function compile(Twig_Compiler $compiler)
|
public function compile(Compiler $compiler)
|
||||||
{
|
{
|
||||||
$compiler
|
$compiler
|
||||||
->raw('(0 == ')
|
->raw('(0 == ')
|
||||||
@ -32,4 +35,4 @@ class Twig_Node_Expression_Test_Divisibleby extends Twig_Node_Expression_Test
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class_alias('Twig_Node_Expression_Test_Divisibleby', 'Twig\Node\Expression\Test\DivisiblebyTest', false);
|
class_alias('Twig\Node\Expression\Test\DivisiblebyTest', 'Twig_Node_Expression_Test_Divisibleby');
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user