Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation.

This commit is contained in:
Pantheon Automation 2015-11-17 13:42:33 -08:00 committed by Greg Anderson
parent 4afb23bbd3
commit 7784f4c23d
929 changed files with 19798 additions and 5304 deletions

View file

@ -1,3 +1,24 @@
* 1.23.1 (2015-XX-XX)
* fixed some exception messages which triggered PHP warnings
* fixed BC on Twig_Test_NodeTestCase
* 1.23.0 (2015-10-29)
* deprecated the possibility to override an extension by registering another one with the same name
* deprecated Twig_ExtensionInterface::getGlobals() (added Twig_Extension_GlobalsInterface for BC)
* deprecated Twig_ExtensionInterface::initRuntime() (added Twig_Extension_InitRuntimeInterface for BC)
* deprecated Twig_Environment::computeAlternatives()
* 1.22.3 (2015-10-13)
* fixed regression when using null as a cache strategy
* improved performance when checking template freshness
* fixed warnings when loaded templates do not exist
* fixed template class name generation to prevent possible collisions
* fixed logic for custom escapers to call them even on integers and null values
* changed template cache names to take into account the Twig C extension
* 1.22.2 (2015-09-22)
* fixed a race condition in template loading

View file

@ -40,7 +40,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.22-dev"
"dev-master": "1.23-dev"
}
}
}

View file

@ -38,7 +38,7 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
{
$hash = hash('sha256', $className);
return $this->directory.'/'.$hash[0].'/'.$hash[1].'/'.$hash.'.php';
return $this->directory.'/'.$hash[0].$hash[1].'/'.$hash.'.php';
}
/**
@ -87,6 +87,10 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
*/
public function getTimestamp($key)
{
if (!file_exists($key)) {
return 0;
}
return (int) @filemtime($key);
}
}

View file

@ -16,7 +16,7 @@
*/
class Twig_Environment
{
const VERSION = '1.22.2';
const VERSION = '1.23.1';
protected $charset;
protected $loader;
@ -48,6 +48,7 @@ class Twig_Environment
private $originalCache;
private $bcWriteCacheFile = false;
private $bcGetCacheFilename = false;
private $lastModifiedExtension = 0;
/**
* Constructor.
@ -263,6 +264,10 @@ class Twig_Environment
} elseif (false === $cache) {
$this->originalCache = $cache;
$this->cache = new Twig_Cache_Null();
} elseif (null === $cache) {
@trigger_error('Using "null" as the cache strategy is deprecated and will be removed in Twig 2.0.', E_USER_DEPRECATED);
$this->originalCache = false;
$this->cache = new Twig_Cache_Null();
} elseif ($cache instanceof Twig_CacheInterface) {
$this->originalCache = $this->cache = $cache;
} else {
@ -291,14 +296,22 @@ class Twig_Environment
/**
* Gets the template class associated with the given string.
*
* @param string $name The name for which to calculate the template class name
* @param int $index The index if it is an embedded template
* The generated template class is based on the following parameters:
*
* * The cache key for the given template;
* * The currently enabled extensions;
* * Whether the Twig C extension is available or not.
*
* @param string $name The name for which to calculate the template class name
* @param int|null $index The index if it is an embedded template
*
* @return string The template class name
*/
public function getTemplateClass($name, $index = null)
{
$key = $this->getLoader()->getCacheKey($name).'__'.implode('__', array_keys($this->extensions));
$key = $this->getLoader()->getCacheKey($name);
$key .= json_encode(array_keys($this->extensions));
$key .= function_exists('twig_template_get_attributes');
return $this->templateClassPrefix.hash('sha256', $key).(null === $index ? '' : '_'.$index);
}
@ -446,14 +459,16 @@ class Twig_Environment
*/
public function isTemplateFresh($name, $time)
{
foreach ($this->extensions as $extension) {
$r = new ReflectionObject($extension);
if (filemtime($r->getFileName()) > $time) {
return false;
if (0 === $this->lastModifiedExtension) {
foreach ($this->extensions as $extension) {
$r = new ReflectionObject($extension);
if (file_exists($r->getFileName()) && ($extensionTime = filemtime($r->getFileName())) > $this->lastModifiedExtension) {
$this->lastModifiedExtension = $extensionTime;
}
}
}
return $this->getLoader()->isFresh($name, $time);
return $this->lastModifiedExtension <= $time && $this->getLoader()->isFresh($name, $time);
}
/**
@ -710,12 +725,22 @@ class Twig_Environment
/**
* Initializes the runtime environment.
*
* @deprecated since 1.23 (to be removed in 2.0)
*/
public function initRuntime()
{
$this->runtimeInitialized = true;
foreach ($this->getExtensions() as $extension) {
foreach ($this->getExtensions() as $name => $extension) {
if (!$extension instanceof Twig_Extension_InitRuntimeInterface) {
$m = new ReflectionMethod($extension, 'initRuntime');
if ('Twig_Extension' !== $m->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Defining the initRuntime() method in the "%s" extension is deprecated. Use the `needs_environment` option to get the Twig_Environment instance in filters, functions, or tests; or explicitly implement Twig_Extension_InitRuntimeInterface if needed (not recommended).', $name), E_USER_DEPRECATED);
}
}
$extension->initRuntime($this);
}
}
@ -755,11 +780,19 @@ class Twig_Environment
*/
public function addExtension(Twig_ExtensionInterface $extension)
{
$name = $extension->getName();
if ($this->extensionInitialized) {
throw new LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName()));
throw new LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $name));
}
$this->extensions[$extension->getName()] = $extension;
if (isset($this->extensions[$name])) {
@trigger_error(sprintf('The possibility to register the same extension twice ("%s") is deprecated and will be removed in Twig 2.0. Use proper PHP inheritance instead.', $name), E_USER_DEPRECATED);
}
$this->lastModifiedExtension = 0;
$this->extensions[$name] = $extension;
}
/**
@ -1218,24 +1251,28 @@ class Twig_Environment
return $this->binaryOperators;
}
/**
* @deprecated since 1.23 (to be removed in 2.0)
*/
public function computeAlternatives($name, $items)
{
$alternatives = array();
foreach ($items as $item) {
$lev = levenshtein($name, $item);
if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) {
$alternatives[$item] = $lev;
}
}
asort($alternatives);
@trigger_error(sprintf('The %s method is deprecated and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED);
return array_keys($alternatives);
return Twig_Error_Syntax::computeAlternatives($name, $items);
}
protected function initGlobals()
{
$globals = array();
foreach ($this->extensions as $extension) {
foreach ($this->extensions as $name => $extension) {
if (!$extension instanceof Twig_Extension_GlobalsInterface) {
$m = new ReflectionMethod($extension, 'getGlobals');
if ('Twig_Extension' !== $m->getDeclaringClass()->getName()) {
@trigger_error(sprintf('Defining the getGlobals() method in the "%s" extension is deprecated without explicitly implementing Twig_Extension_GlobalsInterface.', $name), E_USER_DEPRECATED);
}
}
$extGlob = $extension->getGlobals();
if (!is_array($extGlob)) {
throw new UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', get_class($extension)));

View file

@ -155,6 +155,15 @@ class Twig_Error extends Exception
throw new BadMethodCallException(sprintf('Method "Twig_Error::%s()" does not exist.', $method));
}
public function appendMessage($rawMessage)
{
$this->rawMessage .= $rawMessage;
$this->updateRepr();
}
/**
* @internal
*/
protected function updateRepr()
{
$this->message = $this->rawMessage;
@ -165,6 +174,12 @@ class Twig_Error extends Exception
$dot = true;
}
$questionMark = false;
if ('?' === substr($this->message, -1)) {
$this->message = substr($this->message, 0, -1);
$questionMark = true;
}
if ($this->filename) {
if (is_string($this->filename) || (is_object($this->filename) && method_exists($this->filename, '__toString'))) {
$filename = sprintf('"%s"', $this->filename);
@ -181,8 +196,15 @@ class Twig_Error extends Exception
if ($dot) {
$this->message .= '.';
}
if ($questionMark) {
$this->message .= '?';
}
}
/**
* @internal
*/
protected function guessTemplateInfo()
{
$template = null;

View file

@ -17,4 +17,37 @@
*/
class Twig_Error_Syntax extends Twig_Error
{
/**
* Tweaks the error message to include suggestions.
*
* @param string $name The original name of the item that does not exist
* @param array $items An array of possible items
*/
public function addSuggestions($name, array $items)
{
if (!$alternatives = self::computeAlternatives($name, $items)) {
return;
}
$this->appendMessage(sprintf(' Did you mean "%s"?', implode('", "', $alternatives)));
}
/**
* @internal
*
* To be merged with the addSuggestions() method in 2.0.
*/
public static function computeAlternatives($name, $items)
{
$alternatives = array();
foreach ($items as $item) {
$lev = levenshtein($name, $item);
if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) {
$alternatives[$item] = $lev;
}
}
asort($alternatives);
return array_keys($alternatives);
}
}

View file

@ -171,7 +171,7 @@ class Twig_ExpressionParser
$negClass = 'Twig_Node_Expression_Unary_Neg';
$posClass = 'Twig_Node_Expression_Unary_Pos';
if (!(in_array($ref->getName(), array($negClass, $posClass)) || $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass))) {
throw new Twig_Error_Syntax(sprintf('Unexpected unary operator "%s"', $token->getValue()), $token->getLine(), $this->parser->getFilename());
throw new Twig_Error_Syntax(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getFilename());
}
$this->parser->getStream()->next();
@ -187,7 +187,7 @@ class Twig_ExpressionParser
} elseif ($token->test(Twig_Token::PUNCTUATION_TYPE, '{')) {
$node = $this->parseHashExpression();
} else {
throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', Twig_Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getFilename());
throw new Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s".', Twig_Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getFilename());
}
}
@ -278,7 +278,7 @@ class Twig_ExpressionParser
} else {
$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(), $this->parser->getFilename());
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(), $this->parser->getFilename());
}
$stream->expect(Twig_Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)');
@ -317,11 +317,11 @@ class Twig_ExpressionParser
case 'parent':
$this->parseArguments();
if (!count($this->parser->getBlockStack())) {
throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden', $line, $this->parser->getFilename());
throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden.', $line, $this->parser->getFilename());
}
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->getFilename());
throw new Twig_Error_Syntax('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getFilename());
}
return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $line);
@ -330,7 +330,7 @@ class Twig_ExpressionParser
case 'attribute':
$args = $this->parseArguments();
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->getFilename());
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) : null, Twig_Template::ANY_CALL, $line);
@ -384,13 +384,13 @@ class Twig_ExpressionParser
if ($node instanceof Twig_Node_Expression_Name && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) {
if (!$arg instanceof Twig_Node_Expression_Constant) {
throw new Twig_Error_Syntax(sprintf('Dynamic macro names are not supported (called on "%s")', $node->getAttribute('name')), $token->getLine(), $this->parser->getFilename());
throw new Twig_Error_Syntax(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $this->parser->getFilename());
}
$name = $arg->getAttribute('value');
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(), $this->parser->getFilename());
throw new Twig_Error_Syntax(sprintf('"%s" cannot be called as macro as it is a reserved keyword.', $name), $token->getLine(), $this->parser->getFilename());
}
$node = new Twig_Node_Expression_MethodCall($node, 'get'.$name, $arguments, $lineno);
@ -500,7 +500,7 @@ class Twig_ExpressionParser
$name = null;
if ($namedArguments && $token = $stream->nextIf(Twig_Token::OPERATOR_TYPE, '=')) {
if (!$value instanceof Twig_Node_Expression_Name) {
throw new Twig_Error_Syntax(sprintf('A parameter name must be a string, "%s" given', get_class($value)), $token->getLine(), $this->parser->getFilename());
throw new Twig_Error_Syntax(sprintf('A parameter name must be a string, "%s" given.', get_class($value)), $token->getLine(), $this->parser->getFilename());
}
$name = $value->getAttribute('name');
@ -540,7 +540,7 @@ class Twig_ExpressionParser
while (true) {
$token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, null, 'Only variables can be assigned to');
if (in_array($token->getValue(), array('true', 'false', 'none'))) {
throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s"', $token->getValue()), $token->getLine(), $this->parser->getFilename());
throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s".', $token->getValue()), $token->getLine(), $this->parser->getFilename());
}
$targets[] = new Twig_Node_Expression_AssignName($token->getValue(), $token->getLine());
@ -570,12 +570,10 @@ class Twig_ExpressionParser
$env = $this->parser->getEnvironment();
if (false === $function = $env->getFunction($name)) {
$message = sprintf('The function "%s" does not exist', $name);
if ($alternatives = $env->computeAlternatives($name, array_keys($env->getFunctions()))) {
$message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
}
$e = new Twig_Error_Syntax(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getFilename());
$e->addSuggestions($name, array_keys($env->getFunctions()));
throw new Twig_Error_Syntax($message, $line, $this->parser->getFilename());
throw $e;
}
if ($function instanceof Twig_SimpleFunction && $function->isDeprecated()) {
@ -600,12 +598,10 @@ class Twig_ExpressionParser
$env = $this->parser->getEnvironment();
if (false === $filter = $env->getFilter($name)) {
$message = sprintf('The filter "%s" does not exist', $name);
if ($alternatives = $env->computeAlternatives($name, array_keys($env->getFilters()))) {
$message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
}
$e = new Twig_Error_Syntax(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getFilename());
$e->addSuggestions($name, array_keys($env->getFilters()));
throw new Twig_Error_Syntax($message, $line, $this->parser->getFilename());
throw $e;
}
if ($filter instanceof Twig_SimpleFilter && $filter->isDeprecated()) {

View file

@ -11,20 +11,16 @@
abstract class Twig_Extension implements Twig_ExtensionInterface
{
/**
* Initializes the runtime environment.
* {@inheritdoc}
*
* This is where you can load some file that contains filter functions for instance.
*
* @param Twig_Environment $environment The current Twig_Environment instance
* @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_InitRuntimeInterface instead
*/
public function initRuntime(Twig_Environment $environment)
{
}
/**
* Returns the token parser instances to add to the existing list.
*
* @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances
* {@inheritdoc}
*/
public function getTokenParsers()
{
@ -32,9 +28,7 @@ abstract class Twig_Extension implements Twig_ExtensionInterface
}
/**
* Returns the node visitor instances to add to the existing list.
*
* @return Twig_NodeVisitorInterface[] An array of Twig_NodeVisitorInterface instances
* {@inheritdoc}
*/
public function getNodeVisitors()
{
@ -42,9 +36,7 @@ abstract class Twig_Extension implements Twig_ExtensionInterface
}
/**
* Returns a list of filters to add to the existing list.
*
* @return array An array of filters
* {@inheritdoc}
*/
public function getFilters()
{
@ -52,9 +44,7 @@ abstract class Twig_Extension implements Twig_ExtensionInterface
}
/**
* Returns a list of tests to add to the existing list.
*
* @return array An array of tests
* {@inheritdoc}
*/
public function getTests()
{
@ -62,9 +52,7 @@ abstract class Twig_Extension implements Twig_ExtensionInterface
}
/**
* Returns a list of functions to add to the existing list.
*
* @return array An array of functions
* {@inheritdoc}
*/
public function getFunctions()
{
@ -72,9 +60,7 @@ abstract class Twig_Extension implements Twig_ExtensionInterface
}
/**
* Returns a list of operators to add to the existing list.
*
* @return array An array of operators
* {@inheritdoc}
*/
public function getOperators()
{
@ -82,9 +68,9 @@ abstract class Twig_Extension implements Twig_ExtensionInterface
}
/**
* Returns a list of global variables to add to the existing list.
* {@inheritdoc}
*
* @return array An array of global variables
* @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_GlobalsInterface instead
*/
public function getGlobals()
{

View file

@ -114,11 +114,6 @@ class Twig_Extension_Core extends Twig_Extension
return $this->numberFormat;
}
/**
* Returns the token parser instance to add to the existing list.
*
* @return Twig_TokenParser[] An array of Twig_TokenParser instances
*/
public function getTokenParsers()
{
return array(
@ -140,11 +135,6 @@ class Twig_Extension_Core extends Twig_Extension
);
}
/**
* Returns a list of filters to add to the existing list.
*
* @return array An array of filters
*/
public function getFilters()
{
$filters = array(
@ -202,11 +192,6 @@ class Twig_Extension_Core extends Twig_Extension
return $filters;
}
/**
* Returns a list of global functions to add to the existing list.
*
* @return array An array of global functions
*/
public function getFunctions()
{
return array(
@ -222,11 +207,6 @@ class Twig_Extension_Core extends Twig_Extension
);
}
/**
* Returns a list of tests to add to the existing list.
*
* @return array An array of tests
*/
public function getTests()
{
return array(
@ -245,11 +225,6 @@ class Twig_Extension_Core extends Twig_Extension
);
}
/**
* Returns a list of operators to add to the existing list.
*
* @return array An array of operators
*/
public function getOperators()
{
return array(
@ -340,12 +315,10 @@ class Twig_Extension_Core extends Twig_Extension
}
}
$message = sprintf('The test "%s" does not exist', $name);
if ($alternatives = $env->computeAlternatives($name, array_keys($env->getTests()))) {
$message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
}
$e = new Twig_Error_Syntax(sprintf('Unknown "%s" test.', $name), $line, $parser->getFilename());
$e->addSuggestions($name, array_keys($env->getTests()));
throw new Twig_Error_Syntax($message, $line, $parser->getFilename());
throw $e;
}
protected function getTestNodeClass(Twig_Parser $parser, $test)
@ -357,11 +330,6 @@ class Twig_Extension_Core extends Twig_Extension
return $test instanceof Twig_Test_Node ? $test->getClass() : 'Twig_Node_Expression_Test';
}
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'core';
@ -849,9 +817,10 @@ function twig_join_filter($value, $glue = '')
* {# returns [aa, bb, cc] #}
* </pre>
*
* @param string $value A string
* @param string $delimiter The delimiter
* @param int $limit The limit
* @param Twig_Environment $env A Twig_Environment instance
* @param string $value A string
* @param string $delimiter The delimiter
* @param int $limit The limit
*
* @return array The split string as an array
*/
@ -1021,7 +990,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html',
if (!is_string($string)) {
if (is_object($string) && method_exists($string, '__toString')) {
$string = (string) $string;
} else {
} elseif (in_array($strategy, array('html', 'js', 'css', 'html_attr', 'url'))) {
return $string;
}
}
@ -1508,8 +1477,9 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = a
/**
* Returns a template content without rendering it.
*
* @param string $name The template name
* @param bool $ignoreMissing Whether to ignore missing templates or not
* @param Twig_Environment $env
* @param string $name The template name
* @param bool $ignoreMissing Whether to ignore missing templates or not
*
* @return string The template source
*/

View file

@ -10,11 +10,6 @@
*/
class Twig_Extension_Debug extends Twig_Extension
{
/**
* Returns a list of global functions to add to the existing list.
*
* @return array An array of global functions
*/
public function getFunctions()
{
// dump is safe if var_dump is overridden by xdebug
@ -32,11 +27,6 @@ class Twig_Extension_Debug extends Twig_Extension
);
}
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'debug';

View file

@ -24,31 +24,16 @@ class Twig_Extension_Escaper extends Twig_Extension
$this->setDefaultStrategy($defaultStrategy);
}
/**
* Returns the token parser instances to add to the existing list.
*
* @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances
*/
public function getTokenParsers()
{
return array(new Twig_TokenParser_AutoEscape());
}
/**
* Returns the node visitor instances to add to the existing list.
*
* @return Twig_NodeVisitorInterface[] An array of Twig_NodeVisitorInterface instances
*/
public function getNodeVisitors()
{
return array(new Twig_NodeVisitor_Escaper());
}
/**
* Returns a list of filters to add to the existing list.
*
* @return array An array of filters
*/
public function getFilters()
{
return array(
@ -98,11 +83,6 @@ class Twig_Extension_Escaper extends Twig_Extension
return $this->defaultStrategy;
}
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'escaper';

View file

@ -0,0 +1,22 @@
<?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.
*/
/**
* Enables usage of the deprecated Twig_Extension::getGlobals() method.
*
* Explicitly implement this interface if you really need to implement the
* deprecated getGlobals() method in your extensions.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface Twig_Extension_GlobalsInterface
{
}

View file

@ -0,0 +1,22 @@
<?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.
*/
/**
* Enables usage of the deprecated Twig_Extension::initRuntime() method.
*
* Explicitly implement this interface if you really need to implement the
* deprecated initRuntime() method in your extensions.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface Twig_Extension_InitRuntimeInterface
{
}

View file

@ -17,17 +17,11 @@ class Twig_Extension_Optimizer extends Twig_Extension
$this->optimizers = $optimizers;
}
/**
* {@inheritdoc}
*/
public function getNodeVisitors()
{
return array(new Twig_NodeVisitor_Optimizer($this->optimizers));
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'optimizer';

View file

@ -34,17 +34,11 @@ class Twig_Extension_Profiler extends Twig_Extension
}
}
/**
* {@inheritdoc}
*/
public function getNodeVisitors()
{
return array(new Twig_Profiler_NodeVisitor_Profiler($this->getName()));
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'profiler';

View file

@ -20,21 +20,11 @@ class Twig_Extension_Sandbox extends Twig_Extension
$this->sandboxedGlobally = $sandboxed;
}
/**
* Returns the token parser instances to add to the existing list.
*
* @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances
*/
public function getTokenParsers()
{
return array(new Twig_TokenParser_Sandbox());
}
/**
* Returns the node visitor instances to add to the existing list.
*
* @return Twig_NodeVisitorInterface[] An array of Twig_NodeVisitorInterface instances
*/
public function getNodeVisitors()
{
return array(new Twig_NodeVisitor_Sandbox());
@ -100,11 +90,6 @@ class Twig_Extension_Sandbox extends Twig_Extension
return $obj;
}
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'sandbox';

View file

@ -32,9 +32,6 @@ class Twig_Extension_Staging extends Twig_Extension
$this->functions[$name] = $function;
}
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return $this->functions;
@ -45,9 +42,6 @@ class Twig_Extension_Staging extends Twig_Extension
$this->filters[$name] = $filter;
}
/**
* {@inheritdoc}
*/
public function getFilters()
{
return $this->filters;
@ -58,9 +52,6 @@ class Twig_Extension_Staging extends Twig_Extension
$this->visitors[] = $visitor;
}
/**
* {@inheritdoc}
*/
public function getNodeVisitors()
{
return $this->visitors;
@ -71,9 +62,6 @@ class Twig_Extension_Staging extends Twig_Extension
$this->tokenParsers[] = $parser;
}
/**
* {@inheritdoc}
*/
public function getTokenParsers()
{
return $this->tokenParsers;
@ -84,9 +72,6 @@ class Twig_Extension_Staging extends Twig_Extension
$this->globals[$name] = $value;
}
/**
* {@inheritdoc}
*/
public function getGlobals()
{
return $this->globals;
@ -97,17 +82,11 @@ class Twig_Extension_Staging extends Twig_Extension
$this->tests[$name] = $test;
}
/**
* {@inheritdoc}
*/
public function getTests()
{
return $this->tests;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'staging';

View file

@ -10,9 +10,6 @@
*/
class Twig_Extension_StringLoader extends Twig_Extension
{
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return array(
@ -20,9 +17,6 @@ class Twig_Extension_StringLoader extends Twig_Extension
);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'string_loader';

View file

@ -22,13 +22,15 @@ interface Twig_ExtensionInterface
* This is where you can load some file that contains filter functions for instance.
*
* @param Twig_Environment $environment The current Twig_Environment instance
*
* @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_InitRuntimeInterace instead
*/
public function initRuntime(Twig_Environment $environment);
/**
* Returns the token parser instances to add to the existing list.
*
* @return array An array of Twig_TokenParserInterface or Twig_TokenParserBrokerInterface instances
* @return Twig_TokenParserInterface[]
*/
public function getTokenParsers();
@ -42,21 +44,21 @@ interface Twig_ExtensionInterface
/**
* Returns a list of filters to add to the existing list.
*
* @return array An array of filters
* @return Twig_SimpleFilter[]
*/
public function getFilters();
/**
* Returns a list of tests to add to the existing list.
*
* @return array An array of tests
* @return Twig_SimpleTest[]
*/
public function getTests();
/**
* Returns a list of functions to add to the existing list.
*
* @return array An array of functions
* @return Twig_SimpleFunction[]
*/
public function getFunctions();
@ -71,6 +73,8 @@ interface Twig_ExtensionInterface
* Returns a list of global variables to add to the existing list.
*
* @return array An array of global variables
*
* @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_GlobalsInterface instead
*/
public function getGlobals();

View file

@ -129,7 +129,7 @@ class Twig_Lexer implements Twig_LexerInterface
if (!empty($this->brackets)) {
list($expect, $lineno) = array_pop($this->brackets);
throw new Twig_Error_Syntax(sprintf('Unclosed "%s"', $expect), $lineno, $this->filename);
throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->filename);
}
if ($mbEncoding) {
@ -224,7 +224,7 @@ class Twig_Lexer implements Twig_LexerInterface
$this->moveCursor($match[0]);
if ($this->cursor >= $this->end) {
throw new Twig_Error_Syntax(sprintf('Unclosed "%s"', $this->state === self::STATE_BLOCK ? 'block' : 'variable'), $this->currentVarBlockLine, $this->filename);
throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $this->state === self::STATE_BLOCK ? 'block' : 'variable'), $this->currentVarBlockLine, $this->filename);
}
}
@ -256,12 +256,12 @@ class Twig_Lexer implements Twig_LexerInterface
// closing bracket
elseif (false !== strpos(')]}', $this->code[$this->cursor])) {
if (empty($this->brackets)) {
throw new Twig_Error_Syntax(sprintf('Unexpected "%s"', $this->code[$this->cursor]), $this->lineno, $this->filename);
throw new Twig_Error_Syntax(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->filename);
}
list($expect, $lineno) = array_pop($this->brackets);
if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) {
throw new Twig_Error_Syntax(sprintf('Unclosed "%s"', $expect), $lineno, $this->filename);
throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->filename);
}
}
@ -281,7 +281,7 @@ class Twig_Lexer implements Twig_LexerInterface
}
// unlexable
else {
throw new Twig_Error_Syntax(sprintf('Unexpected character "%s"', $this->code[$this->cursor]), $this->lineno, $this->filename);
throw new Twig_Error_Syntax(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->filename);
}
}
@ -292,7 +292,7 @@ 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)) {
throw new Twig_Error_Syntax(sprintf('Unexpected end of file: Unclosed "%s" block', $tag), $this->lineno, $this->filename);
throw new Twig_Error_Syntax(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->filename);
}
$text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor);
@ -308,7 +308,7 @@ class Twig_Lexer implements Twig_LexerInterface
protected function lexComment()
{
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->filename);
throw new Twig_Error_Syntax('Unclosed comment.', $this->lineno, $this->filename);
}
$this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]);
@ -327,7 +327,7 @@ class Twig_Lexer implements Twig_LexerInterface
} elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) {
list($expect, $lineno) = array_pop($this->brackets);
if ($this->code[$this->cursor] != '"') {
throw new Twig_Error_Syntax(sprintf('Unclosed "%s"', $expect), $lineno, $this->filename);
throw new Twig_Error_Syntax(sprintf('Unclosed "%s".', $expect), $lineno, $this->filename);
}
$this->popState();

View file

@ -101,7 +101,7 @@ class Twig_Node implements Twig_NodeInterface
$node->appendChild($child);
}
return $asDom ? $dom : $dom->saveXml();
return $asDom ? $dom : $dom->saveXML();
}
public function compile(Twig_Compiler $compiler)

View file

@ -27,11 +27,6 @@ class Twig_Node_AutoEscape extends Twig_Node
parent::__construct(array('body' => $body), array('value' => $value), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->subcompile($this->getNode('body'));

View file

@ -22,11 +22,6 @@ class Twig_Node_Block extends Twig_Node
parent::__construct(array('body' => $body), array('name' => $name), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -22,11 +22,6 @@ class Twig_Node_BlockReference extends Twig_Node implements Twig_NodeOutputInter
parent::__construct(array(), array('name' => $name), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -21,11 +21,6 @@ class Twig_Node_Do extends Twig_Node
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -60,11 +60,6 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
array_push($this->nodes, $key, $value);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->raw('array(');

View file

@ -12,11 +12,6 @@
class Twig_Node_Expression_AssignName extends Twig_Node_Expression_Name
{
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -16,11 +16,6 @@ abstract class Twig_Node_Expression_Binary extends Twig_Node_Expression
parent::__construct(array('left' => $left, 'right' => $right), array(), $lineno);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -10,11 +10,6 @@
*/
class Twig_Node_Expression_Binary_FloorDiv extends Twig_Node_Expression_Binary
{
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->raw('intval(floor(');

View file

@ -10,11 +10,6 @@
*/
class Twig_Node_Expression_Binary_In extends Twig_Node_Expression_Binary
{
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -10,11 +10,6 @@
*/
class Twig_Node_Expression_Binary_NotIn extends Twig_Node_Expression_Binary
{
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -10,11 +10,6 @@
*/
class Twig_Node_Expression_Binary_Power extends Twig_Node_Expression_Binary
{
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -10,11 +10,6 @@
*/
class Twig_Node_Expression_Binary_Range extends Twig_Node_Expression_Binary
{
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -22,11 +22,6 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
parent::__construct(array('name' => $name), array('as_string' => $asString, 'output' => false), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
if ($this->getAttribute('as_string')) {

View file

@ -21,11 +21,6 @@ class Twig_Node_Expression_ExtensionReference extends Twig_Node_Expression
parent::__construct(array(), array('name' => $name), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->raw(sprintf("\$this->env->getExtension('%s')", $this->getAttribute('name')));

View file

@ -22,11 +22,6 @@ class Twig_Node_Expression_Parent extends Twig_Node_Expression
parent::__construct(array(), array('output' => false, 'name' => $name), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
if ($this->getAttribute('output')) {

View file

@ -34,7 +34,7 @@ class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test
$this->changeIgnoreStrictCheck($node);
} else {
throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine());
throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getLine());
}
}

View file

@ -21,11 +21,6 @@ class Twig_Node_Flush extends Twig_Node
parent::__construct(array(), array(), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -30,11 +30,6 @@ class Twig_Node_For extends Twig_Node
parent::__construct(array('key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body, 'else' => $else), array('with_loop' => true, 'ifexpr' => null !== $ifexpr), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -21,11 +21,6 @@ class Twig_Node_ForLoop extends Twig_Node
parent::__construct(array(), array('with_loop' => false, 'ifexpr' => false, 'else' => false), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
if ($this->getAttribute('else')) {

View file

@ -22,11 +22,6 @@ class Twig_Node_If extends Twig_Node
parent::__construct(array('tests' => $tests, 'else' => $else), array(), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);

View file

@ -21,11 +21,6 @@ class Twig_Node_Import extends Twig_Node
parent::__construct(array('expr' => $expr, 'var' => $var), array(), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -22,11 +22,6 @@ class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface
parent::__construct(array('expr' => $expr, 'variables' => $variables), array('only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);

View file

@ -22,18 +22,13 @@ class Twig_Node_Macro extends Twig_Node
{
foreach ($arguments as $argumentName => $argument) {
if (self::VARARGS_NAME === $argumentName) {
throw new Twig_Error_Syntax(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getLine());
throw new Twig_Error_Syntax(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getLine());
}
}
parent::__construct(array('body' => $body, 'arguments' => $arguments), array('name' => $name), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -47,11 +47,6 @@ class Twig_Node_Module extends Twig_Node
$this->setAttribute('index', $index);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$this->compileTemplate($compiler);

View file

@ -22,11 +22,6 @@ class Twig_Node_Print extends Twig_Node implements Twig_NodeOutputInterface
parent::__construct(array('expr' => $expr), array(), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -21,11 +21,6 @@ class Twig_Node_Sandbox extends Twig_Node
parent::__construct(array('body' => $body), array(), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -21,16 +21,6 @@
*/
class Twig_Node_SandboxedPrint extends Twig_Node_Print
{
public function __construct(Twig_Node_Expression $expr, $lineno, $tag = null)
{
parent::__construct($expr, $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -36,11 +36,6 @@ class Twig_Node_Set extends Twig_Node
}
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);

View file

@ -23,11 +23,6 @@ class Twig_Node_Spaceless extends Twig_Node
parent::__construct(array('body' => $body), array(), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -22,11 +22,6 @@ class Twig_Node_Text extends Twig_Node implements Twig_NodeOutputInterface
parent::__construct(array(), array('data' => $data), $lineno);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler $compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler

View file

@ -94,10 +94,8 @@ class Twig_Parser implements Twig_ParserInterface
try {
$body = $this->subparse($test, $dropNeedle);
if (null !== $this->parent) {
if (null === $body = $this->filterBodyNodes($body)) {
$body = new Twig_Node();
}
if (null !== $this->parent && null === $body = $this->filterBodyNodes($body)) {
$body = new Twig_Node();
}
} catch (Twig_Error_Syntax $e) {
if (!$e->getTemplateFile()) {
@ -148,7 +146,7 @@ class Twig_Parser implements Twig_ParserInterface
$token = $this->getCurrentToken();
if ($token->getType() !== Twig_Token::NAME_TYPE) {
throw new Twig_Error_Syntax('A block must start with a tag name', $token->getLine(), $this->getFilename());
throw new Twig_Error_Syntax('A block must start with a tag name.', $token->getLine(), $this->getFilename());
}
if (null !== $test && call_user_func($test, $token)) {
@ -166,20 +164,17 @@ class Twig_Parser implements Twig_ParserInterface
$subparser = $this->handlers->getTokenParser($token->getValue());
if (null === $subparser) {
if (null !== $test) {
$error = sprintf('Unexpected tag name "%s"', $token->getValue());
$e = new Twig_Error_Syntax(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->getFilename());
if (is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) {
$error .= sprintf(' (expecting closing tag for the "%s" tag defined near line %s)', $test[0]->getTag(), $lineno);
$e->appendMessage(sprintf(' (expecting closing tag for the "%s" tag defined near line %s).', $test[0]->getTag(), $lineno));
}
throw new Twig_Error_Syntax($error, $token->getLine(), $this->getFilename());
} else {
$e = new Twig_Error_Syntax(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->getFilename());
$e->addSuggestions($token->getValue(), array_keys($this->env->getTags()));
}
$message = sprintf('Unknown tag name "%s"', $token->getValue());
if ($alternatives = $this->env->computeAlternatives($token->getValue(), array_keys($this->env->getTags()))) {
$message = sprintf('%s. Did you mean "%s"', $message, implode('", "', $alternatives));
}
throw new Twig_Error_Syntax($message, $token->getLine(), $this->getFilename());
throw $e;
}
$this->stream->next();
@ -255,7 +250,7 @@ class Twig_Parser implements Twig_ParserInterface
public function setMacro($name, Twig_Node_Macro $node)
{
if ($this->isReservedMacroName($name)) {
throw new Twig_Error_Syntax(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword', $name), $node->getLine(), $this->getFilename());
throw new Twig_Error_Syntax(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword.', $name), $node->getLine(), $this->getFilename());
}
$this->macros[$name] = $node;

View file

@ -90,13 +90,13 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
if (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) {
$message = $match[1];
$condition = $match[2];
$templates = $this->parseTemplates($match[3]);
$templates = self::parseTemplates($match[3]);
$exception = $match[5];
$outputs = array(array(null, $match[4], null, ''));
} elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) {
$message = $match[1];
$condition = $match[2];
$templates = $this->parseTemplates($match[3]);
$templates = self::parseTemplates($match[3]);
$exception = false;
preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER);
} else {
@ -165,7 +165,9 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
$template = $twig->loadTemplate('index.twig');
} catch (Exception $e) {
if (false !== $exception) {
$this->assertSame(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage())));
$message = $e->getMessage();
$this->assertSame(trim($exception), trim(sprintf('%s: %s', get_class($e), $message)));
$this->assertSame('.', substr($message, strlen($message) - 1), $message, 'Exception message must end with a dot.');
return;
}

View file

@ -15,17 +15,21 @@ abstract class Twig_Test_NodeTestCase extends PHPUnit_Framework_TestCase
/**
* @dataProvider getTests
*/
public function testCompile($node, $source, $environment = null)
public function testCompile($node, $source, $environment = null, $isPattern = false)
{
$this->assertNodeCompilation($source, $node, $environment);
$this->assertNodeCompilation($source, $node, $environment, $isPattern);
}
public function assertNodeCompilation($source, Twig_Node $node, Twig_Environment $environment = null)
public function assertNodeCompilation($source, Twig_Node $node, Twig_Environment $environment = null, $isPattern = false)
{
$compiler = $this->getCompiler($environment);
$compiler->compile($node);
$this->assertEquals($source, trim($compiler->getSource()));
if ($isPattern) {
$this->assertStringMatchesFormat($source, trim($compiler->getSource()));
} else {
$this->assertEquals($source, trim($compiler->getSource()));
}
}
protected function getCompiler(Twig_Environment $environment = null)

View file

@ -29,13 +29,6 @@
*/
class Twig_TokenParser_AutoEscape extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$lineno = $token->getLine();
@ -46,7 +39,7 @@ class Twig_TokenParser_AutoEscape extends Twig_TokenParser
} else {
$expr = $this->parser->getExpressionParser()->parseExpression();
if (!$expr instanceof Twig_Node_Expression_Constant) {
throw new Twig_Error_Syntax('An escaping strategy must be a string or a Boolean.', $stream->getCurrent()->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getFilename());
}
$value = $expr->getAttribute('value');
@ -79,11 +72,6 @@ class Twig_TokenParser_AutoEscape extends Twig_TokenParser
return $token->test('endautoescape');
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'autoescape';

View file

@ -22,20 +22,13 @@
*/
class Twig_TokenParser_Block extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
$name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
if ($this->parser->hasBlock($name)) {
throw new Twig_Error_Syntax(sprintf("The block '$name' has already been defined line %d", $this->parser->getBlock($name)->getLine()), $stream->getCurrent()->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getLine()), $stream->getCurrent()->getLine(), $stream->getFilename());
}
$this->parser->setBlock($name, $block = new Twig_Node_Block($name, new Twig_Node(array()), $lineno));
$this->parser->pushLocalScope();
@ -47,7 +40,7 @@ class Twig_TokenParser_Block extends Twig_TokenParser
$value = $token->getValue();
if ($value != $name) {
throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given)', $name, $value), $stream->getCurrent()->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getFilename());
}
}
} else {
@ -69,11 +62,6 @@ class Twig_TokenParser_Block extends Twig_TokenParser
return $token->test('endblock');
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'block';

View file

@ -14,13 +14,6 @@
*/
class Twig_TokenParser_Do extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$expr = $this->parser->getExpressionParser()->parseExpression();
@ -30,11 +23,6 @@ class Twig_TokenParser_Do extends Twig_TokenParser
return new Twig_Node_Do($expr, $token->getLine(), $this->getTag());
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'do';

View file

@ -14,13 +14,6 @@
*/
class Twig_TokenParser_Embed extends Twig_TokenParser_Include
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$stream = $this->parser->getStream();
@ -54,11 +47,6 @@ class Twig_TokenParser_Embed extends Twig_TokenParser_Include
return $token->test('endembed');
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'embed';

View file

@ -19,32 +19,20 @@
*/
class Twig_TokenParser_Extends extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
if (!$this->parser->isMainScope()) {
throw new Twig_Error_Syntax('Cannot extend from a block', $token->getLine(), $this->parser->getFilename());
throw new Twig_Error_Syntax('Cannot extend from a block.', $token->getLine(), $this->parser->getFilename());
}
if (null !== $this->parser->getParent()) {
throw new Twig_Error_Syntax('Multiple extends tags are forbidden', $token->getLine(), $this->parser->getFilename());
throw new Twig_Error_Syntax('Multiple extends tags are forbidden.', $token->getLine(), $this->parser->getFilename());
}
$this->parser->setParent($this->parser->getExpressionParser()->parseExpression());
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'extends';

View file

@ -20,13 +20,6 @@
*/
class Twig_TokenParser_Filter extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$name = $this->parser->getVarName();
@ -49,11 +42,6 @@ class Twig_TokenParser_Filter extends Twig_TokenParser
return $token->test('endfilter');
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'filter';

View file

@ -16,13 +16,6 @@
*/
class Twig_TokenParser_Flush extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
@ -30,11 +23,6 @@ class Twig_TokenParser_Flush extends Twig_TokenParser
return new Twig_Node_Flush($token->getLine(), $this->getTag());
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'flush';

View file

@ -23,13 +23,6 @@
*/
class Twig_TokenParser_For extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$lineno = $token->getLine();
@ -86,7 +79,7 @@ class Twig_TokenParser_For extends Twig_TokenParser
protected function checkLoopUsageCondition(Twig_TokenStream $stream, Twig_NodeInterface $node)
{
if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition', $node->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax('The "loop" variable cannot be used in a looping condition.', $node->getLine(), $stream->getFilename());
}
foreach ($node as $n) {
@ -105,7 +98,7 @@ class Twig_TokenParser_For extends Twig_TokenParser
if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) {
$attribute = $node->getNode('attribute');
if ($attribute instanceof Twig_Node_Expression_Constant && in_array($attribute->getAttribute('value'), array('length', 'revindex0', 'revindex', 'last'))) {
throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition', $attribute->getAttribute('value')), $node->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getLine(), $stream->getFilename());
}
}
@ -123,11 +116,6 @@ class Twig_TokenParser_For extends Twig_TokenParser
}
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'for';

View file

@ -18,13 +18,6 @@
*/
class Twig_TokenParser_From extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$macro = $this->parser->getExpressionParser()->parseExpression();
@ -53,7 +46,7 @@ class Twig_TokenParser_From extends Twig_TokenParser
foreach ($targets as $name => $alias) {
if ($this->parser->isReservedMacroName($name)) {
throw new Twig_Error_Syntax(sprintf('"%s" cannot be an imported macro as it is a reserved keyword', $name), $token->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getFilename());
}
$this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var'));
@ -62,11 +55,6 @@ class Twig_TokenParser_From extends Twig_TokenParser
return $node;
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'from';

View file

@ -25,13 +25,6 @@
*/
class Twig_TokenParser_If extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$lineno = $token->getLine();
@ -63,7 +56,7 @@ class Twig_TokenParser_If extends Twig_TokenParser
break;
default:
throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d)', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getFilename());
}
}
@ -82,11 +75,6 @@ class Twig_TokenParser_If extends Twig_TokenParser
return $token->test(array('endif'));
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'if';

View file

@ -18,13 +18,6 @@
*/
class Twig_TokenParser_Import extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$macro = $this->parser->getExpressionParser()->parseExpression();
@ -37,11 +30,6 @@ class Twig_TokenParser_Import extends Twig_TokenParser
return new Twig_Node_Import($macro, $var, $token->getLine(), $this->getTag());
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'import';

View file

@ -21,13 +21,6 @@
*/
class Twig_TokenParser_Include extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$expr = $this->parser->getExpressionParser()->parseExpression();
@ -63,11 +56,6 @@ class Twig_TokenParser_Include extends Twig_TokenParser
return array($variables, $only, $ignoreMissing);
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'include';

View file

@ -20,13 +20,6 @@
*/
class Twig_TokenParser_Macro extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$lineno = $token->getLine();
@ -42,7 +35,7 @@ class Twig_TokenParser_Macro extends Twig_TokenParser
$value = $token->getValue();
if ($value != $name) {
throw new Twig_Error_Syntax(sprintf('Expected endmacro for macro "%s" (but "%s" given)', $name, $value), $stream->getCurrent()->getLine(), $stream->getFilename());
throw new Twig_Error_Syntax(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getFilename());
}
}
$this->parser->popLocalScope();
@ -56,11 +49,6 @@ class Twig_TokenParser_Macro extends Twig_TokenParser
return $token->test('endmacro');
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'macro';

View file

@ -22,13 +22,6 @@
*/
class Twig_TokenParser_Sandbox extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
@ -43,7 +36,7 @@ class Twig_TokenParser_Sandbox extends Twig_TokenParser
}
if (!$node instanceof Twig_Node_Include) {
throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section', $node->getLine(), $this->parser->getFilename());
throw new Twig_Error_Syntax('Only "include" tags are allowed within a "sandbox" section.', $node->getLine(), $this->parser->getFilename());
}
}
}
@ -56,11 +49,6 @@ class Twig_TokenParser_Sandbox extends Twig_TokenParser
return $token->test('endsandbox');
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'sandbox';

View file

@ -28,13 +28,6 @@
*/
class Twig_TokenParser_Set extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$lineno = $token->getLine();
@ -71,11 +64,6 @@ class Twig_TokenParser_Set extends Twig_TokenParser
return $token->test('endset');
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'set';

View file

@ -24,13 +24,6 @@
*/
class Twig_TokenParser_Spaceless extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$lineno = $token->getLine();
@ -47,11 +40,6 @@ class Twig_TokenParser_Spaceless extends Twig_TokenParser
return $token->test('endspaceless');
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'spaceless';

View file

@ -25,13 +25,6 @@
*/
class Twig_TokenParser_Use extends Twig_TokenParser
{
/**
* Parses a token and returns a node.
*
* @param Twig_Token $token A Twig_Token instance
*
* @return Twig_NodeInterface A Twig_NodeInterface instance
*/
public function parse(Twig_Token $token)
{
$template = $this->parser->getExpressionParser()->parseExpression();
@ -64,11 +57,6 @@ class Twig_TokenParser_Use extends Twig_TokenParser
$this->parser->addTrait(new Twig_Node(array('template' => $template, 'targets' => new Twig_Node($targets))));
}
/**
* Gets the tag name associated with this token parser.
*
* @return string The tag name
*/
public function getTag()
{
return 'use';

View file

@ -26,8 +26,9 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface
/**
* Constructor.
*
* @param array|Traversable $parsers A Traversable of Twig_TokenParserInterface instances
* @param array|Traversable $brokers A Traversable of Twig_TokenParserBrokerInterface instances
* @param array|Traversable $parsers A Traversable of Twig_TokenParserInterface instances
* @param array|Traversable $brokers A Traversable of Twig_TokenParserBrokerInterface instances
* @param bool $triggerDeprecationError
*/
public function __construct($parsers = array(), $brokers = array(), $triggerDeprecationError = true)
{
@ -37,13 +38,13 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface
foreach ($parsers as $parser) {
if (!$parser instanceof Twig_TokenParserInterface) {
throw new LogicException('$parsers must a an array of Twig_TokenParserInterface');
throw new LogicException('$parsers must a an array of Twig_TokenParserInterface.');
}
$this->parsers[$parser->getTag()] = $parser;
}
foreach ($brokers as $broker) {
if (!$broker instanceof Twig_TokenParserBrokerInterface) {
throw new LogicException('$brokers must a an array of Twig_TokenParserBrokerInterface');
throw new LogicException('$brokers must a an array of Twig_TokenParserBrokerInterface.');
}
$this->brokers[] = $broker;
}

View file

@ -56,7 +56,7 @@ class Twig_TokenStream
public function next()
{
if (!isset($this->tokens[++$this->current])) {
throw new Twig_Error_Syntax('Unexpected end of template', $this->tokens[$this->current - 1]->getLine(), $this->filename);
throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->filename);
}
return $this->tokens[$this->current - 1];
@ -84,7 +84,7 @@ class Twig_TokenStream
$token = $this->tokens[$this->current];
if (!$token->test($type, $value)) {
$line = $token->getLine();
throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s)',
throw new Twig_Error_Syntax(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).',
$message ? $message.'. ' : '',
Twig_Token::typeToEnglish($token->getType()), $token->getValue(),
Twig_Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''),
@ -107,7 +107,7 @@ class Twig_TokenStream
public function look($number = 1)
{
if (!isset($this->tokens[$this->current + $number])) {
throw new Twig_Error_Syntax('Unexpected end of template', $this->tokens[$this->current + $number - 1]->getLine(), $this->filename);
throw new Twig_Error_Syntax('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->filename);
}
return $this->tokens[$this->current + $number];