Commit 2aaa191c authored by Crise's avatar Crise

Twig 1.30.0

parent 8dd71f63
......@@ -16,9 +16,6 @@
*/
abstract class Twig_BaseNodeVisitor implements Twig_NodeVisitorInterface
{
/**
* {@inheritdoc}
*/
final public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if (!$node instanceof Twig_Node) {
......@@ -28,9 +25,6 @@ abstract class Twig_BaseNodeVisitor implements Twig_NodeVisitorInterface
return $this->doEnterNode($node, $env);
}
/**
* {@inheritdoc}
*/
final public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
{
if (!$node instanceof Twig_Node) {
......
* 1.30.0 (2016-12-23)
* added Twig_FactoryRuntimeLoader
* deprecated function/test/filter/tag overriding
* deprecated the "disable_c_ext" attribute on Twig_Node_Expression_GetAttr
* 1.29.0 (2016-12-13)
* fixed sandbox being left enabled if an exception is thrown while rendering
......
......@@ -31,9 +31,6 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
$this->options = $options;
}
/**
* {@inheritdoc}
*/
public function generateKey($name, $className)
{
$hash = hash('sha256', $className);
......@@ -41,9 +38,6 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php';
}
/**
* {@inheritdoc}
*/
public function load($key)
{
if (file_exists($key)) {
......@@ -51,9 +45,6 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
}
}
/**
* {@inheritdoc}
*/
public function write($key, $content)
{
$dir = dirname($key);
......@@ -84,9 +75,6 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface
throw new RuntimeException(sprintf('Failed to write cache file "%s".', $key));
}
/**
* {@inheritdoc}
*/
public function getTimestamp($key)
{
if (!file_exists($key)) {
......
......@@ -18,31 +18,19 @@
*/
class Twig_Cache_Null implements Twig_CacheInterface
{
/**
* {@inheritdoc}
*/
public function generateKey($name, $className)
{
return '';
}
/**
* {@inheritdoc}
*/
public function write($key, $content)
{
}
/**
* {@inheritdoc}
*/
public function load($key)
{
}
/**
* {@inheritdoc}
*/
public function getTimestamp($key)
{
return 0;
......
......@@ -16,10 +16,10 @@
*/
class Twig_Environment
{
const VERSION = '1.29.0';
const VERSION_ID = 12900;
const VERSION = '1.30.0';
const VERSION_ID = 13000;
const MAJOR_VERSION = 1;
const MINOR_VERSION = 29;
const MINOR_VERSION = 30;
const RELEASE_VERSION = 0;
const EXTRA_VERSION = '';
......@@ -831,7 +831,7 @@ class Twig_Environment
return true;
}
return isset($this->extensionsByClass[ltrim($class, '\\')]);
return isset($this->extensionsByClass[$class]);
}
/**
......
......@@ -33,7 +33,7 @@ class Twig_ExpressionParser
private $env;
public function __construct(Twig_Parser $parser, Twig_Environment $env = null)
public function __construct(Twig_Parser $parser, $env = null)
{
$this->parser = $parser;
......
......@@ -11,65 +11,43 @@
abstract class Twig_Extension implements Twig_ExtensionInterface
{
/**
* {@inheritdoc}
*
* @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_InitRuntimeInterface instead
*/
public function initRuntime(Twig_Environment $environment)
{
}
/**
* {@inheritdoc}
*/
public function getTokenParsers()
{
return array();
}
/**
* {@inheritdoc}
*/
public function getNodeVisitors()
{
return array();
}
/**
* {@inheritdoc}
*/
public function getFilters()
{
return array();
}
/**
* {@inheritdoc}
*/
public function getTests()
{
return array();
}
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return array();
}
/**
* {@inheritdoc}
*/
public function getOperators()
{
return array();
}
/**
* {@inheritdoc}
*
* @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_GlobalsInterface instead
*/
public function getGlobals()
......@@ -78,8 +56,6 @@ abstract class Twig_Extension implements Twig_ExtensionInterface
}
/**
* {@inheritdoc}
*
* @deprecated since 1.26 (to be removed in 2.0), not used anymore internally
*/
public function getName()
......
......@@ -29,6 +29,10 @@ class Twig_Extension_Staging extends Twig_Extension
public function addFunction($name, $function)
{
if (isset($this->functions[$name])) {
@trigger_error(sprintf('Overriding function "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED);
}
$this->functions[$name] = $function;
}
......@@ -39,6 +43,10 @@ class Twig_Extension_Staging extends Twig_Extension
public function addFilter($name, $filter)
{
if (isset($this->filters[$name])) {
@trigger_error(sprintf('Overriding filter "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED);
}
$this->filters[$name] = $filter;
}
......@@ -59,7 +67,11 @@ class Twig_Extension_Staging extends Twig_Extension
public function addTokenParser(Twig_TokenParserInterface $parser)
{
$this->tokenParsers[] = $parser;
if (isset($this->tokenParsers[$parser->getTag()])) {
@trigger_error(sprintf('Overriding tag "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $parser->getTag()), E_USER_DEPRECATED);
}
$this->tokenParsers[$parser->getTag()] = $parser;
}
public function getTokenParsers()
......@@ -79,6 +91,10 @@ class Twig_Extension_Staging extends Twig_Extension
public function addTest($name, $test)
{
if (isset($this->tests[$name])) {
@trigger_error(sprintf('Overriding test "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED);
}
$this->tests[$name] = $test;
}
......
<?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.
*/
/**
* Lazy loads the runtime implementations for a Twig element.
*
* @author Robin Chalas <robin.chalas@gmail.com>
*/
class Twig_FactoryRuntimeLoader implements Twig_RuntimeLoaderInterface
{
private $map;
/**
* @param array $map An array where keys are class names and keys factory callables
*/
public function __construct($map = array())
{
$this->map = $map;
}
public function load($class)
{
if (isset($this->map[$class])) {
$runtimeFactory = $this->map[$class];
return $runtimeFactory();
}
}
}
......@@ -75,9 +75,6 @@ class Twig_Lexer implements Twig_LexerInterface
);
}
/**
* {@inheritdoc}
*/
public function tokenize($code, $name = null)
{
if (!$code instanceof Twig_Source) {
......
......@@ -46,9 +46,6 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
$this->templates[(string) $name] = $template;
}
/**
* {@inheritdoc}
*/
public function getSource($name)
{
@trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
......@@ -61,9 +58,6 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
return $this->templates[$name];
}
/**
* {@inheritdoc}
*/
public function getSourceContext($name)
{
$name = (string) $name;
......@@ -74,17 +68,11 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
return new Twig_Source($this->templates[$name], $name);
}
/**
* {@inheritdoc}
*/
public function exists($name)
{
return isset($this->templates[(string) $name]);
}
/**
* {@inheritdoc}
*/
public function getCacheKey($name)
{
$name = (string) $name;
......@@ -95,9 +83,6 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
return $this->templates[$name];
}
/**
* {@inheritdoc}
*/
public function isFresh($name, $time)
{
$name = (string) $name;
......
......@@ -37,9 +37,6 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
$this->hasSourceCache = array();
}
/**
* {@inheritdoc}
*/
public function getSource($name)
{
@trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
......@@ -60,9 +57,6 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
}
/**
* {@inheritdoc}
*/
public function getSourceContext($name)
{
$exceptions = array();
......@@ -85,9 +79,6 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
}
/**
* {@inheritdoc}
*/
public function exists($name)
{
$name = (string) $name;
......@@ -120,9 +111,6 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
return $this->hasSourceCache[$name] = false;
}
/**
* {@inheritdoc}
*/
public function getCacheKey($name)
{
$exceptions = array();
......@@ -141,9 +129,6 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
throw new Twig_Error_Loader(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : ''));
}
/**
* {@inheritdoc}
*/
public function isFresh($name, $time)
{
$exceptions = array();
......
......@@ -131,9 +131,6 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
}
}
/**
* {@inheritdoc}
*/
public function getSource($name)
{
@trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
......@@ -141,9 +138,6 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
return file_get_contents($this->findTemplate($name));
}
/**
* {@inheritdoc}
*/
public function getSourceContext($name)
{
$path = $this->findTemplate($name);
......@@ -151,9 +145,6 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
return new Twig_Source(file_get_contents($path), $name, $path);
}
/**
* {@inheritdoc}
*/
public function getCacheKey($name)
{
$path = $this->findTemplate($name);
......@@ -165,9 +156,6 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
return $path;
}
/**
* {@inheritdoc}
*/
public function exists($name)
{
$name = $this->normalizeName($name);
......@@ -185,9 +173,6 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
}
}
/**
* {@inheritdoc}
*/
public function isFresh($name, $time)
{
return filemtime($this->findTemplate($name)) <= $time;
......
......@@ -29,9 +29,6 @@
*/
class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
{
/**
* {@inheritdoc}
*/
public function getSource($name)
{
@trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
......@@ -39,33 +36,21 @@ class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExistsLoaderInter
return $name;
}
/**
* {@inheritdoc}
*/
public function getSourceContext($name)
{
return new Twig_Source($name, $name);
}
/**
* {@inheritdoc}
*/
public function exists($name)
{
return true;
}
/**
* {@inheritdoc}
*/
public function getCacheKey($name)
{
return $name;
}
/**
* {@inheritdoc}
*/
public function isFresh($name, $time)
{
return true;
......
......@@ -23,6 +23,10 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
public function compile(Twig_Compiler $compiler)
{
if ($this->getAttribute('disable_c_ext')) {
@trigger_error(sprintf('Using the "disable_c_ext" attribute on %s is deprecated since version 1.30 and will be removed in 2.0.', __CLASS__), E_USER_DEPRECATED);
}
if (function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) {
$compiler->raw('twig_template_get_attributes($this, ');
} else {
......
......@@ -30,9 +30,6 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
$this->safeAnalysis = new Twig_NodeVisitor_SafeAnalysis();
}
/**
* {@inheritdoc}
*/
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
......@@ -52,9 +49,6 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
return $node;
}
/**
* {@inheritdoc}
*/
protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
......@@ -151,9 +145,6 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
return new Twig_Node_Expression_Filter($node, $name, $args, $line);
}
/**
* {@inheritdoc}
*/
public function getPriority()
{
return 0;
......
......@@ -47,9 +47,6 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
$this->optimizers = $optimizers;
}
/**
* {@inheritdoc}
*/
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
{
if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) {
......@@ -73,9 +70,6 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
return $node;
}
/**
* {@inheritdoc}
*/
protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
{
$expression = $node instanceof Twig_Node_Expression;
......@@ -250,9 +244,6 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor
}
}
/**
* {@inheritdoc}
*/
public function getPriority()
{
return 255;
......
......@@ -60,17 +60,11 @@ class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor
);
}
/**
* {@inheritdoc}
*/
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
{
return $node;
}
/**
* {@inheritdoc}
*/
protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Expression_Constant) {
......@@ -147,9 +141,6 @@ class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor
return array_intersect($a, $b);
}
/**
* {@inheritdoc}
*/
public function getPriority()
{
return 0;
......
......@@ -23,9 +23,6 @@ class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor
protected $filters;
protected $functions;
/**
* {@inheritdoc}
*/
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
......@@ -60,9 +57,6 @@ class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor
return $node;
}
/**
* {@inheritdoc}
*/
protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
......@@ -74,9 +68,6 @@ class Twig_NodeVisitor_Sandbox extends Twig_BaseNodeVisitor
return $node;
}
/**
* {@inheritdoc}
*/
public function getPriority()
{
return 0;
......
......@@ -62,9 +62,6 @@ class Twig_Parser implements Twig_ParserInterface
return $this->stream->getSourceContext()->getName();
}
/**
* {@inheritdoc}
*/
public function parse(Twig_TokenStream $stream, $test = null, $dropNeedle = false)
{
// push all variables into the stack to keep the current state of the parser
......
......@@ -21,9 +21,6 @@ class Twig_Profiler_Node_EnterProfile extends Twig_Node
parent::__construct(array(), array('extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName));
}
/**
* {@inheritdoc}
*/
public function compile(Twig_Compiler $compiler)
{
$compiler
......
......@@ -21,9 +21,6 @@ class Twig_Profiler_Node_LeaveProfile extends Twig_Node
parent::__construct(array(), array('var_name' => $varName));
}
/**
* {@inheritdoc}
*/
public function compile(Twig_Compiler $compiler)
{
$compiler
......
......@@ -23,17 +23,11 @@ class Twig_Profiler_NodeVisitor_Profiler extends Twig_BaseNodeVisitor
$this->extensionName = $extensionName;
}
/**
* {@inheritdoc}
*/
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
{
return $node;
}
/**
* {@inheritdoc}
*/
protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
{
if ($node instanceof Twig_Node_Module) {
......@@ -64,9 +58,6 @@ class Twig_Profiler_NodeVisitor_Profiler extends Twig_BaseNodeVisitor
return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false));
}
/**
* {@inheritdoc}
*/
public function getPriority()
{
return 0;
......
......@@ -12,6 +12,8 @@
/**
* Represents a template filter.
*
* @final
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Twig_SimpleFilter
......
......@@ -12,6 +12,8 @@
/**
* Represents a template function.
*
* @final
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Twig_SimpleFunction
......
......@@ -12,6 +12,8 @@
/**
* Represents a template test.
*
* @final
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Twig_SimpleTest
......
......@@ -232,7 +232,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
} elseif (false !== $parent = $this->getParent($context)) {
$parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false);
} else {
@trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0.', $name, $this->getTemplateName()), E_USER_DEPRECATED);
@trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block(\'%s\') is defined" expression to test for block existence.', $name, $this->getTemplateName(), $name), E_USER_DEPRECATED);
}
}
......@@ -398,17 +398,11 @@ abstract class Twig_Template implements Twig_TemplateInterface
return $this->blocks;
}
/**
* {@inheritdoc}
*/
public function display(array $context, array $blocks = array())
{
$this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks));
}
/**
* {@inheritdoc}
*/
public function render(array $context)
{
$level = ob_get_level();
......@@ -689,7 +683,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
// @deprecated in 1.28
if ($object instanceof Twig_TemplateInterface) {
$self = $object->getTemplateName() === $this->getTemplateName();
$message = sprintf('Calling "%s" on template "%s" from template "%s" is deprecated since version 1.28 and won\'t be supported anymore in 2.0.', $method, $object->getTemplateName(), $this->getTemplateName());
$message = sprintf('Calling "%s" on template "%s" from template "%s" is deprecated since version 1.28 and won\'t be supported anymore in 2.0.', $item, $object->getTemplateName(), $this->getTemplateName());
if ('renderBlock' === $method || 'displayBlock' === $method) {
$message .= sprintf(' Use block("%s"%s) instead).', $arguments[0], $self ? '' : ', template');
} elseif ('hasBlock' === $method) {
......