mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-01-29 19:37:30 +01:00
upgrade twig library
This commit is contained in:
parent
63727f342d
commit
f817c0c960
0
inc/lib/Twig/Autoloader.php
Normal file → Executable file
0
inc/lib/Twig/Autoloader.php
Normal file → Executable file
5
inc/lib/Twig/Compiler.php
Normal file → Executable file
5
inc/lib/Twig/Compiler.php
Normal file → Executable file
@ -180,11 +180,12 @@ class Twig_Compiler implements Twig_CompilerInterface
|
||||
$this->raw($value ? 'true' : 'false');
|
||||
} elseif (is_array($value)) {
|
||||
$this->raw('array(');
|
||||
$i = 0;
|
||||
$first = true;
|
||||
foreach ($value as $key => $value) {
|
||||
if ($i++) {
|
||||
if (!$first) {
|
||||
$this->raw(', ');
|
||||
}
|
||||
$first = false;
|
||||
$this->repr($key);
|
||||
$this->raw(' => ');
|
||||
$this->repr($value);
|
||||
|
0
inc/lib/Twig/CompilerInterface.php
Normal file → Executable file
0
inc/lib/Twig/CompilerInterface.php
Normal file → Executable file
14
inc/lib/Twig/Environment.php
Normal file → Executable file
14
inc/lib/Twig/Environment.php
Normal file → Executable file
@ -16,7 +16,7 @@
|
||||
*/
|
||||
class Twig_Environment
|
||||
{
|
||||
const VERSION = '1.13.1';
|
||||
const VERSION = '1.14.0-DEV';
|
||||
|
||||
protected $charset;
|
||||
protected $loader;
|
||||
@ -44,6 +44,7 @@ class Twig_Environment
|
||||
protected $functionCallbacks;
|
||||
protected $filterCallbacks;
|
||||
protected $staging;
|
||||
protected $templateClasses;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -107,6 +108,7 @@ class Twig_Environment
|
||||
$this->setCache($options['cache']);
|
||||
$this->functionCallbacks = array();
|
||||
$this->filterCallbacks = array();
|
||||
$this->templateClasses = array();
|
||||
|
||||
$this->addExtension(new Twig_Extension_Core());
|
||||
$this->addExtension(new Twig_Extension_Escaper($options['autoescape']));
|
||||
@ -262,7 +264,13 @@ class Twig_Environment
|
||||
*/
|
||||
public function getTemplateClass($name, $index = null)
|
||||
{
|
||||
return $this->templateClassPrefix.md5($this->getLoader()->getCacheKey($name)).(null === $index ? '' : '_'.$index);
|
||||
$suffix = null === $index ? '' : '_'.$index;
|
||||
$cls = $name.$suffix;
|
||||
if (isset($this->templateClasses[$cls])) {
|
||||
return $this->templateClasses[$cls];
|
||||
}
|
||||
|
||||
return $this->templateClasses[$cls] = $this->templateClassPrefix.hash('sha256', $this->getLoader()->getCacheKey($name)).$suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -728,7 +736,7 @@ class Twig_Environment
|
||||
public function addNodeVisitor(Twig_NodeVisitorInterface $visitor)
|
||||
{
|
||||
if ($this->extensionInitialized) {
|
||||
throw new LogicException('Unable to add a node visitor as extensions have already been initialized.', $extension->getName());
|
||||
throw new LogicException('Unable to add a node visitor as extensions have already been initialized.');
|
||||
}
|
||||
|
||||
$this->staging->addNodeVisitor($visitor);
|
||||
|
6
inc/lib/Twig/Error.php
Normal file → Executable file
6
inc/lib/Twig/Error.php
Normal file → Executable file
@ -186,6 +186,7 @@ class Twig_Error extends Exception
|
||||
protected function guessTemplateInfo()
|
||||
{
|
||||
$template = null;
|
||||
$templateClass = null;
|
||||
|
||||
if (version_compare(phpversion(), '5.3.6', '>=')) {
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
|
||||
@ -195,8 +196,11 @@ class Twig_Error extends Exception
|
||||
|
||||
foreach ($backtrace as $trace) {
|
||||
if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) {
|
||||
if (null === $this->filename || $this->filename == $trace['object']->getTemplateName()) {
|
||||
$currentClass = get_class($trace['object']);
|
||||
$isEmbedContainer = 0 === strpos($templateClass, $currentClass);
|
||||
if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) {
|
||||
$template = $trace['object'];
|
||||
$templateClass = get_class($trace['object']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
0
inc/lib/Twig/Error/Loader.php
Normal file → Executable file
0
inc/lib/Twig/Error/Loader.php
Normal file → Executable file
0
inc/lib/Twig/Error/Runtime.php
Normal file → Executable file
0
inc/lib/Twig/Error/Runtime.php
Normal file → Executable file
0
inc/lib/Twig/Error/Syntax.php
Normal file → Executable file
0
inc/lib/Twig/Error/Syntax.php
Normal file → Executable file
0
inc/lib/Twig/ExistsLoaderInterface.php
Normal file → Executable file
0
inc/lib/Twig/ExistsLoaderInterface.php
Normal file → Executable file
83
inc/lib/Twig/ExpressionParser.php
Normal file → Executable file
83
inc/lib/Twig/ExpressionParser.php
Normal file → Executable file
@ -316,22 +316,22 @@ class Twig_ExpressionParser
|
||||
throw new Twig_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attributes)', $line, $this->parser->getFilename());
|
||||
}
|
||||
|
||||
return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : new Twig_Node_Expression_Array(array(), $line), Twig_TemplateInterface::ANY_CALL, $line);
|
||||
return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : new Twig_Node_Expression_Array(array(), $line), Twig_Template::ANY_CALL, $line);
|
||||
default:
|
||||
if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) {
|
||||
$arguments = new Twig_Node_Expression_Array(array(), $line);
|
||||
foreach ($this->parseArguments() as $n) {
|
||||
$arguments->addElement($n);
|
||||
}
|
||||
|
||||
$node = new Twig_Node_Expression_MethodCall($alias['node'], $alias['name'], $arguments, $line);
|
||||
$node->setAttribute('safe', true);
|
||||
|
||||
return $node;
|
||||
$args = $this->parseArguments(true);
|
||||
if (null !== $alias = $this->parser->getImportedSymbol('macro', $name)) {
|
||||
return new Twig_Node_Expression_MacroCall($alias['node'], $alias['name'], $this->createArrayFromArguments($args), $line);
|
||||
}
|
||||
|
||||
$args = $this->parseArguments(true);
|
||||
$class = $this->getFunctionNodeClass($name, $line);
|
||||
try {
|
||||
$class = $this->getFunctionNodeClass($name, $line);
|
||||
} catch (Twig_Error_Syntax $e) {
|
||||
if (!$this->parser->hasMacro($name)) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return new Twig_Node_Expression_MacroCall(new Twig_Node_Expression_Name('_self', $line), $name, $this->createArrayFromArguments($args), $line);
|
||||
}
|
||||
|
||||
return new $class($name, $args, $line);
|
||||
}
|
||||
@ -343,7 +343,7 @@ class Twig_ExpressionParser
|
||||
$token = $stream->next();
|
||||
$lineno = $token->getLine();
|
||||
$arguments = new Twig_Node_Expression_Array(array(), $lineno);
|
||||
$type = Twig_TemplateInterface::ANY_CALL;
|
||||
$type = Twig_Template::ANY_CALL;
|
||||
if ($token->getValue() == '.') {
|
||||
$token = $stream->next();
|
||||
if (
|
||||
@ -354,13 +354,6 @@ class Twig_ExpressionParser
|
||||
($token->getType() == Twig_Token::OPERATOR_TYPE && preg_match(Twig_Lexer::REGEX_NAME, $token->getValue()))
|
||||
) {
|
||||
$arg = new Twig_Node_Expression_Constant($token->getValue(), $lineno);
|
||||
|
||||
if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
|
||||
$type = Twig_TemplateInterface::METHOD_CALL;
|
||||
foreach ($this->parseArguments() as $n) {
|
||||
$arguments->addElement($n);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Twig_Error_Syntax('Expected name or number', $lineno, $this->parser->getFilename());
|
||||
}
|
||||
@ -370,13 +363,17 @@ class Twig_ExpressionParser
|
||||
throw new Twig_Error_Syntax(sprintf('Dynamic macro names are not supported (called on "%s")', $node->getAttribute('name')), $token->getLine(), $this->parser->getFilename());
|
||||
}
|
||||
|
||||
$node = new Twig_Node_Expression_MethodCall($node, 'get'.$arg->getAttribute('value'), $arguments, $lineno);
|
||||
$node->setAttribute('safe', true);
|
||||
$arguments = $this->createArrayFromArguments($this->parseArguments(true));
|
||||
|
||||
return $node;
|
||||
return new Twig_Node_Expression_MacroCall($node, $arg->getAttribute('value'), $arguments, $lineno);
|
||||
}
|
||||
|
||||
if ($stream->test(Twig_Token::PUNCTUATION_TYPE, '(')) {
|
||||
$type = Twig_Template::METHOD_CALL;
|
||||
$arguments = $this->createArrayFromArguments($this->parseArguments());
|
||||
}
|
||||
} else {
|
||||
$type = Twig_TemplateInterface::ARRAY_CALL;
|
||||
$type = Twig_Template::ARRAY_CALL;
|
||||
|
||||
// slice?
|
||||
$slice = false;
|
||||
@ -452,6 +449,8 @@ class Twig_ExpressionParser
|
||||
*
|
||||
* @param Boolean $namedArguments Whether to allow named arguments or not
|
||||
* @param Boolean $definition Whether we are parsing arguments for a function definition
|
||||
*
|
||||
* @return Twig_Node
|
||||
*/
|
||||
public function parseArguments($namedArguments = false, $definition = false)
|
||||
{
|
||||
@ -483,25 +482,26 @@ class Twig_ExpressionParser
|
||||
$value = $this->parsePrimaryExpression();
|
||||
|
||||
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(), $this->parser->getFilename());
|
||||
throw new Twig_Error_Syntax('A default value for an argument must be a constant (a boolean, a string, a number, or an array).', $token->getLine(), $this->parser->getFilename());
|
||||
}
|
||||
} else {
|
||||
$value = $this->parseExpression();
|
||||
}
|
||||
}
|
||||
|
||||
if ($definition) {
|
||||
if (null === $name) {
|
||||
$name = $value->getAttribute('name');
|
||||
$value = new Twig_Node_Expression_Constant(null, $this->parser->getCurrentToken()->getLine());
|
||||
}
|
||||
$args[$name] = $value;
|
||||
if ($definition && null === $name) {
|
||||
$name = $value->getAttribute('name');
|
||||
$value = new Twig_Node_Expression_Constant(null, $this->parser->getCurrentToken()->getLine());
|
||||
}
|
||||
|
||||
if (null === $name) {
|
||||
$args[] = $value;
|
||||
} else {
|
||||
if (null === $name) {
|
||||
$args[] = $value;
|
||||
} else {
|
||||
$args[$name] = $value;
|
||||
if ($definition && isset($args[$name])) {
|
||||
throw new Twig_Error_Syntax(sprintf('Arguments cannot contain the same argument name more than once ("%s" is defined twice).', $name), $token->getLine(), $this->parser->getFilename());
|
||||
}
|
||||
|
||||
$args[$name] = $value;
|
||||
}
|
||||
}
|
||||
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis');
|
||||
@ -597,4 +597,15 @@ class Twig_ExpressionParser
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function createArrayFromArguments(Twig_Node $arguments, $line = null)
|
||||
{
|
||||
$line = null === $line ? $arguments->getLine() : $line;
|
||||
$array = new Twig_Node_Expression_Array(array(), $line);
|
||||
foreach ($arguments as $key => $value) {
|
||||
$array->addElement($value, new Twig_Node_Expression_Constant($key, $value->getLine()));
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
0
inc/lib/Twig/Extension.php
Normal file → Executable file
0
inc/lib/Twig/Extension.php
Normal file → Executable file
22
inc/lib/Twig/Extension/Core.php
Normal file → Executable file
22
inc/lib/Twig/Extension/Core.php
Normal file → Executable file
@ -348,7 +348,7 @@ function twig_random(Twig_Environment $env, $values = null)
|
||||
return $values < 0 ? mt_rand($values, 0) : mt_rand(0, $values);
|
||||
}
|
||||
|
||||
if ($values instanceof Traversable) {
|
||||
if (is_object($values) && $values instanceof Traversable) {
|
||||
$values = iterator_to_array($values);
|
||||
} elseif (is_string($values)) {
|
||||
if ('' === $values) {
|
||||
@ -620,7 +620,7 @@ function twig_array_merge($arr1, $arr2)
|
||||
*/
|
||||
function twig_slice(Twig_Environment $env, $item, $start, $length = null, $preserveKeys = false)
|
||||
{
|
||||
if ($item instanceof Traversable) {
|
||||
if (is_object($item) && $item instanceof Traversable) {
|
||||
$item = iterator_to_array($item, false);
|
||||
}
|
||||
|
||||
@ -687,7 +687,7 @@ function twig_last(Twig_Environment $env, $item)
|
||||
*/
|
||||
function twig_join_filter($value, $glue = '')
|
||||
{
|
||||
if ($value instanceof Traversable) {
|
||||
if (is_object($value) && $value instanceof Traversable) {
|
||||
$value = iterator_to_array($value, false);
|
||||
}
|
||||
|
||||
@ -829,7 +829,7 @@ function twig_in_filter($value, $compare)
|
||||
}
|
||||
|
||||
return false !== strpos($compare, (string) $value);
|
||||
} elseif ($compare instanceof Traversable) {
|
||||
} elseif (is_object($compare) && $compare instanceof Traversable) {
|
||||
return in_array($value, iterator_to_array($compare, false), is_object($value));
|
||||
}
|
||||
|
||||
@ -1329,13 +1329,13 @@ function twig_constant($constant, $object = null)
|
||||
*
|
||||
* @param array $items An array of items
|
||||
* @param integer $size The size of the batch
|
||||
* @param string $fill A string to fill missing items
|
||||
* @param mixed $fill A value used to fill missing items
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function twig_array_batch($items, $size, $fill = null)
|
||||
{
|
||||
if ($items instanceof Traversable) {
|
||||
if (is_object($items) && $items instanceof Traversable) {
|
||||
$items = iterator_to_array($items, false);
|
||||
}
|
||||
|
||||
@ -1345,10 +1345,12 @@ function twig_array_batch($items, $size, $fill = null)
|
||||
|
||||
if (null !== $fill) {
|
||||
$last = count($result) - 1;
|
||||
$result[$last] = array_merge(
|
||||
$result[$last],
|
||||
array_fill(0, $size - count($result[$last]), $fill)
|
||||
);
|
||||
if ($fillCount = $size - count($result[$last])) {
|
||||
$result[$last] = array_merge(
|
||||
$result[$last],
|
||||
array_fill(0, $fillCount, $fill)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
0
inc/lib/Twig/Extension/Debug.php
Normal file → Executable file
0
inc/lib/Twig/Extension/Debug.php
Normal file → Executable file
0
inc/lib/Twig/Extension/Escaper.php
Normal file → Executable file
0
inc/lib/Twig/Extension/Escaper.php
Normal file → Executable file
0
inc/lib/Twig/Extension/Optimizer.php
Normal file → Executable file
0
inc/lib/Twig/Extension/Optimizer.php
Normal file → Executable file
0
inc/lib/Twig/Extension/Sandbox.php
Normal file → Executable file
0
inc/lib/Twig/Extension/Sandbox.php
Normal file → Executable file
0
inc/lib/Twig/Extension/Staging.php
Normal file → Executable file
0
inc/lib/Twig/Extension/Staging.php
Normal file → Executable file
12
inc/lib/Twig/Extension/StringLoader.php
Normal file → Executable file
12
inc/lib/Twig/Extension/StringLoader.php
Normal file → Executable file
@ -43,16 +43,16 @@ class Twig_Extension_StringLoader extends Twig_Extension
|
||||
*/
|
||||
function twig_template_from_string(Twig_Environment $env, $template)
|
||||
{
|
||||
static $loader;
|
||||
$name = sprintf('__string_template__%s', hash('sha256', uniqid(mt_rand(), true), false));
|
||||
|
||||
if (null === $loader) {
|
||||
$loader = new Twig_Loader_String();
|
||||
}
|
||||
$loader = new Twig_Loader_Chain(array(
|
||||
new Twig_Loader_Array(array($name => $template)),
|
||||
$current = $env->getLoader(),
|
||||
));
|
||||
|
||||
$current = $env->getLoader();
|
||||
$env->setLoader($loader);
|
||||
try {
|
||||
$template = $env->loadTemplate($template);
|
||||
$template = $env->loadTemplate($name);
|
||||
} catch (Exception $e) {
|
||||
$env->setLoader($current);
|
||||
|
||||
|
0
inc/lib/Twig/ExtensionInterface.php
Normal file → Executable file
0
inc/lib/Twig/ExtensionInterface.php
Normal file → Executable file
0
inc/lib/Twig/Filter.php
Normal file → Executable file
0
inc/lib/Twig/Filter.php
Normal file → Executable file
0
inc/lib/Twig/Filter/Function.php
Normal file → Executable file
0
inc/lib/Twig/Filter/Function.php
Normal file → Executable file
0
inc/lib/Twig/Filter/Method.php
Normal file → Executable file
0
inc/lib/Twig/Filter/Method.php
Normal file → Executable file
0
inc/lib/Twig/Filter/Node.php
Normal file → Executable file
0
inc/lib/Twig/Filter/Node.php
Normal file → Executable file
0
inc/lib/Twig/FilterCallableInterface.php
Normal file → Executable file
0
inc/lib/Twig/FilterCallableInterface.php
Normal file → Executable file
0
inc/lib/Twig/FilterInterface.php
Normal file → Executable file
0
inc/lib/Twig/FilterInterface.php
Normal file → Executable file
0
inc/lib/Twig/Function.php
Normal file → Executable file
0
inc/lib/Twig/Function.php
Normal file → Executable file
0
inc/lib/Twig/Function/Function.php
Normal file → Executable file
0
inc/lib/Twig/Function/Function.php
Normal file → Executable file
0
inc/lib/Twig/Function/Method.php
Normal file → Executable file
0
inc/lib/Twig/Function/Method.php
Normal file → Executable file
0
inc/lib/Twig/Function/Node.php
Normal file → Executable file
0
inc/lib/Twig/Function/Node.php
Normal file → Executable file
0
inc/lib/Twig/FunctionCallableInterface.php
Normal file → Executable file
0
inc/lib/Twig/FunctionCallableInterface.php
Normal file → Executable file
0
inc/lib/Twig/FunctionInterface.php
Normal file → Executable file
0
inc/lib/Twig/FunctionInterface.php
Normal file → Executable file
0
inc/lib/Twig/Lexer.php
Normal file → Executable file
0
inc/lib/Twig/Lexer.php
Normal file → Executable file
0
inc/lib/Twig/LexerInterface.php
Normal file → Executable file
0
inc/lib/Twig/LexerInterface.php
Normal file → Executable file
7
inc/lib/Twig/Loader/Array.php
Normal file → Executable file
7
inc/lib/Twig/Loader/Array.php
Normal file → Executable file
@ -21,7 +21,7 @@
|
||||
*/
|
||||
class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface
|
||||
{
|
||||
protected $templates;
|
||||
protected $templates = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -32,10 +32,7 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
||||
*/
|
||||
public function __construct(array $templates)
|
||||
{
|
||||
$this->templates = array();
|
||||
foreach ($templates as $name => $template) {
|
||||
$this->templates[$name] = $template;
|
||||
}
|
||||
$this->templates = $templates;
|
||||
}
|
||||
|
||||
/**
|
||||
|
3
inc/lib/Twig/Loader/Chain.php
Normal file → Executable file
3
inc/lib/Twig/Loader/Chain.php
Normal file → Executable file
@ -17,7 +17,7 @@
|
||||
class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterface
|
||||
{
|
||||
private $hasSourceCache = array();
|
||||
protected $loaders;
|
||||
protected $loaders = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -26,7 +26,6 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
|
||||
*/
|
||||
public function __construct(array $loaders = array())
|
||||
{
|
||||
$this->loaders = array();
|
||||
foreach ($loaders as $loader) {
|
||||
$this->addLoader($loader);
|
||||
}
|
||||
|
27
inc/lib/Twig/Loader/Filesystem.php
Normal file → Executable file
27
inc/lib/Twig/Loader/Filesystem.php
Normal file → Executable file
@ -16,8 +16,11 @@
|
||||
*/
|
||||
class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface
|
||||
{
|
||||
protected $paths;
|
||||
protected $cache;
|
||||
/** Identifier of the main namespace. */
|
||||
const MAIN_NAMESPACE = '__main__';
|
||||
|
||||
protected $paths = array();
|
||||
protected $cache = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -38,7 +41,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
||||
*
|
||||
* @return array The array of paths where to look for templates
|
||||
*/
|
||||
public function getPaths($namespace = '__main__')
|
||||
public function getPaths($namespace = self::MAIN_NAMESPACE)
|
||||
{
|
||||
return isset($this->paths[$namespace]) ? $this->paths[$namespace] : array();
|
||||
}
|
||||
@ -46,7 +49,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
||||
/**
|
||||
* Returns the path namespaces.
|
||||
*
|
||||
* The "__main__" namespace is always defined.
|
||||
* The main namespace is always defined.
|
||||
*
|
||||
* @return array The array of defined namespaces
|
||||
*/
|
||||
@ -61,7 +64,7 @@ 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 $namespace A path namespace
|
||||
*/
|
||||
public function setPaths($paths, $namespace = '__main__')
|
||||
public function setPaths($paths, $namespace = self::MAIN_NAMESPACE)
|
||||
{
|
||||
if (!is_array($paths)) {
|
||||
$paths = array($paths);
|
||||
@ -81,7 +84,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
||||
*
|
||||
* @throws Twig_Error_Loader
|
||||
*/
|
||||
public function addPath($path, $namespace = '__main__')
|
||||
public function addPath($path, $namespace = self::MAIN_NAMESPACE)
|
||||
{
|
||||
// invalidate the cache
|
||||
$this->cache = array();
|
||||
@ -101,7 +104,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
||||
*
|
||||
* @throws Twig_Error_Loader
|
||||
*/
|
||||
public function prependPath($path, $namespace = '__main__')
|
||||
public function prependPath($path, $namespace = self::MAIN_NAMESPACE)
|
||||
{
|
||||
// invalidate the cache
|
||||
$this->cache = array();
|
||||
@ -175,15 +178,15 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
||||
|
||||
$this->validateName($name);
|
||||
|
||||
$namespace = '__main__';
|
||||
$namespace = self::MAIN_NAMESPACE;
|
||||
$shortname = $name;
|
||||
if (isset($name[0]) && '@' == $name[0]) {
|
||||
if (false === $pos = strpos($name, '/')) {
|
||||
throw new Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name));
|
||||
}
|
||||
|
||||
$namespace = substr($name, 1, $pos - 1);
|
||||
|
||||
$name = substr($name, $pos + 1);
|
||||
$shortname = substr($name, $pos + 1);
|
||||
}
|
||||
|
||||
if (!isset($this->paths[$namespace])) {
|
||||
@ -191,8 +194,8 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
|
||||
}
|
||||
|
||||
foreach ($this->paths[$namespace] as $path) {
|
||||
if (is_file($path.'/'.$name)) {
|
||||
return $this->cache[$name] = $path.'/'.$name;
|
||||
if (is_file($path.'/'.$shortname)) {
|
||||
return $this->cache[$name] = $path.'/'.$shortname;
|
||||
}
|
||||
}
|
||||
|
||||
|
0
inc/lib/Twig/Loader/String.php
Normal file → Executable file
0
inc/lib/Twig/Loader/String.php
Normal file → Executable file
0
inc/lib/Twig/LoaderInterface.php
Normal file → Executable file
0
inc/lib/Twig/LoaderInterface.php
Normal file → Executable file
0
inc/lib/Twig/Markup.php
Normal file → Executable file
0
inc/lib/Twig/Markup.php
Normal file → Executable file
0
inc/lib/Twig/Node.php
Normal file → Executable file
0
inc/lib/Twig/Node.php
Normal file → Executable file
0
inc/lib/Twig/Node/AutoEscape.php
Normal file → Executable file
0
inc/lib/Twig/Node/AutoEscape.php
Normal file → Executable file
0
inc/lib/Twig/Node/Block.php
Normal file → Executable file
0
inc/lib/Twig/Node/Block.php
Normal file → Executable file
0
inc/lib/Twig/Node/BlockReference.php
Normal file → Executable file
0
inc/lib/Twig/Node/BlockReference.php
Normal file → Executable file
0
inc/lib/Twig/Node/Body.php
Normal file → Executable file
0
inc/lib/Twig/Node/Body.php
Normal file → Executable file
0
inc/lib/Twig/Node/Do.php
Normal file → Executable file
0
inc/lib/Twig/Node/Do.php
Normal file → Executable file
0
inc/lib/Twig/Node/Embed.php
Normal file → Executable file
0
inc/lib/Twig/Node/Embed.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Array.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Array.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/AssignName.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/AssignName.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Add.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Add.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/And.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/And.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/BitwiseAnd.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/BitwiseAnd.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/BitwiseOr.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/BitwiseOr.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/BitwiseXor.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/BitwiseXor.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Concat.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Concat.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Div.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Div.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Equal.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Equal.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/FloorDiv.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/FloorDiv.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Greater.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Greater.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/GreaterEqual.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/GreaterEqual.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/In.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/In.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Less.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Less.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/LessEqual.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/LessEqual.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Mod.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Mod.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Mul.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Mul.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/NotEqual.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/NotEqual.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/NotIn.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/NotIn.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Or.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Or.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Power.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Power.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Range.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Range.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Sub.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Binary/Sub.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/BlockReference.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/BlockReference.php
Normal file → Executable file
6
inc/lib/Twig/Node/Expression/Call.php
Normal file → Executable file
6
inc/lib/Twig/Node/Expression/Call.php
Normal file → Executable file
@ -146,7 +146,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
||||
|
||||
if (array_key_exists($name, $parameters)) {
|
||||
if (array_key_exists($pos, $parameters)) {
|
||||
throw new Twig_Error_Syntax(sprintf('Arguments "%s" is defined twice for %s "%s".', $name, $this->getAttribute('type'), $this->getAttribute('name')));
|
||||
throw new Twig_Error_Syntax(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $this->getAttribute('type'), $this->getAttribute('name')));
|
||||
}
|
||||
|
||||
$arguments[] = $parameters[$name];
|
||||
@ -164,8 +164,8 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array_keys($parameters) as $name) {
|
||||
throw new Twig_Error_Syntax(sprintf('Unknown argument "%s" for %s "%s".', $name, $this->getAttribute('type'), $this->getAttribute('name')));
|
||||
if (!empty($parameters)) {
|
||||
throw new Twig_Error_Syntax(sprintf('Unknown argument%s "%s" for %s "%s".', count($parameters) > 1 ? 's' : '' , implode('", "', array_keys($parameters)), $this->getAttribute('type'), $this->getAttribute('name')));
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
|
0
inc/lib/Twig/Node/Expression/Conditional.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Conditional.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Constant.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Constant.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/ExtensionReference.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/ExtensionReference.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Filter.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Filter.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Filter/Default.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Filter/Default.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Function.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Function.php
Normal file → Executable file
4
inc/lib/Twig/Node/Expression/GetAttr.php
Normal file → Executable file
4
inc/lib/Twig/Node/Expression/GetAttr.php
Normal file → Executable file
@ -32,10 +32,10 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
|
||||
|
||||
$compiler->raw(', ')->subcompile($this->getNode('attribute'));
|
||||
|
||||
if (count($this->getNode('arguments')) || Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
|
||||
if (count($this->getNode('arguments')) || Twig_Template::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
|
||||
$compiler->raw(', ')->subcompile($this->getNode('arguments'));
|
||||
|
||||
if (Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
|
||||
if (Twig_Template::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
|
||||
$compiler->raw(', ')->repr($this->getAttribute('type'));
|
||||
}
|
||||
|
||||
|
60
inc/lib/Twig/Node/Expression/MacroCall.php
Executable file
60
inc/lib/Twig/Node/Expression/MacroCall.php
Executable file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2012 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a macro call node.
|
||||
*
|
||||
* @author Martin Hasoň <martin.hason@gmail.com>
|
||||
*/
|
||||
class Twig_Node_Expression_MacroCall extends Twig_Node_Expression
|
||||
{
|
||||
public function __construct(Twig_Node_Expression $template, $name, Twig_Node_Expression_Array $arguments, $lineno)
|
||||
{
|
||||
parent::__construct(array('template' => $template, 'arguments' => $arguments), array('name' => $name), $lineno);
|
||||
}
|
||||
|
||||
public function compile(Twig_Compiler $compiler)
|
||||
{
|
||||
$namedNames = array();
|
||||
$namedCount = 0;
|
||||
$positionalCount = 0;
|
||||
foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) {
|
||||
$name = $pair['key']->getAttribute('value');
|
||||
if (!is_int($name)) {
|
||||
$namedCount++;
|
||||
$namedNames[$name] = 1;
|
||||
} elseif ($namedCount > 0) {
|
||||
throw new Twig_Error_Syntax(sprintf('Positional arguments cannot be used after named arguments for macro "%s".', $this->getAttribute('name')), $this->lineno);
|
||||
} else {
|
||||
$positionalCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('$this->callMacro(')
|
||||
->subcompile($this->getNode('template'))
|
||||
->raw(', ')->repr($this->getAttribute('name'))
|
||||
->raw(', ')->subcompile($this->getNode('arguments'))
|
||||
;
|
||||
|
||||
if ($namedCount > 0) {
|
||||
$compiler
|
||||
->raw(', ')->repr($namedNames)
|
||||
->raw(', ')->repr($namedCount)
|
||||
->raw(', ')->repr($positionalCount)
|
||||
;
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
}
|
0
inc/lib/Twig/Node/Expression/MethodCall.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/MethodCall.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Name.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Name.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Parent.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Parent.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/TempName.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/TempName.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Constant.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Constant.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Defined.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Defined.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Divisibleby.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Divisibleby.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Even.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Even.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Null.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Null.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Odd.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Odd.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Sameas.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Test/Sameas.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Unary.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Unary.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Unary/Neg.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Unary/Neg.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Unary/Not.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Unary/Not.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Unary/Pos.php
Normal file → Executable file
0
inc/lib/Twig/Node/Expression/Unary/Pos.php
Normal file → Executable file
0
inc/lib/Twig/Node/Flush.php
Normal file → Executable file
0
inc/lib/Twig/Node/Flush.php
Normal file → Executable file
0
inc/lib/Twig/Node/For.php
Normal file → Executable file
0
inc/lib/Twig/Node/For.php
Normal file → Executable file
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