mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 18:36:53 +00:00
got rid of filename when we meant template name
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 1.27.0 (2016-XX-XX)
|
||||
|
||||
* deprecated the "filename" escaping strategy (use "name" instead)
|
||||
* added Twig_Source to hold information about the original template
|
||||
* deprecated Twig_Error::getTemplateFile() and Twig_Error::setTemplateFile() in favor of Twig_Error::getTemplateName() and Twig_Error::setTemplateName()
|
||||
* deprecated Parser::getFilename()
|
||||
|
||||
@@ -85,10 +85,10 @@ class Twig_Compiler implements Twig_CompilerInterface
|
||||
$this->indentation = $indentation;
|
||||
|
||||
if ($node instanceof Twig_Node_Module) {
|
||||
$node->setFilename($node->getAttribute('filename'));
|
||||
$node->setFilename($node->getAttribute('name'));
|
||||
|
||||
// to be removed in 2.0
|
||||
$this->filename = $node->getAttribute('filename');
|
||||
$this->filename = $node->getAttribute('name');
|
||||
}
|
||||
|
||||
$node->compile($this);
|
||||
|
||||
@@ -82,8 +82,8 @@ class Twig_Environment
|
||||
* * false: disable auto-escaping
|
||||
* * true: equivalent to html
|
||||
* * html, js: set the autoescaping to one of the supported strategies
|
||||
* * filename: set the autoescaping strategy based on the template filename extension
|
||||
* * PHP callback: a PHP callback that returns an escaping strategy based on the template "filename"
|
||||
* * name: set the autoescaping strategy based on the template name extension
|
||||
* * PHP callback: a PHP callback that returns an escaping strategy based on the template "name"
|
||||
*
|
||||
* * optimizations: A flag that indicates which optimizations to apply
|
||||
* (default to -1 which means that all optimizations are enabled;
|
||||
|
||||
@@ -45,7 +45,7 @@ class Twig_Extension_Escaper extends Twig_Extension
|
||||
* Sets the default strategy to use when not defined by the user.
|
||||
*
|
||||
* The strategy can be a valid PHP callback that takes the template
|
||||
* "filename" as an argument and returns the strategy to use.
|
||||
* name as an argument and returns the strategy to use.
|
||||
*
|
||||
* @param string|false|callable $defaultStrategy An escaping strategy
|
||||
*/
|
||||
@@ -59,6 +59,12 @@ class Twig_Extension_Escaper extends Twig_Extension
|
||||
}
|
||||
|
||||
if ('filename' === $defaultStrategy) {
|
||||
@trigger_error('Using "filename" as the default strategy is deprecated since version 1.27. Use "name" instead.', E_USER_DEPRECATED);
|
||||
|
||||
$defaultStrategy = 'name';
|
||||
}
|
||||
|
||||
if ('name' === $defaultStrategy) {
|
||||
$defaultStrategy = array('Twig_FileExtensionEscapingStrategy', 'guess');
|
||||
}
|
||||
|
||||
@@ -68,16 +74,16 @@ class Twig_Extension_Escaper extends Twig_Extension
|
||||
/**
|
||||
* Gets the default strategy to use when not defined by the user.
|
||||
*
|
||||
* @param string $filename The template "filename"
|
||||
* @param string $name The template name
|
||||
*
|
||||
* @return string|false The default strategy to use for the template
|
||||
*/
|
||||
public function getDefaultStrategy($filename)
|
||||
public function getDefaultStrategy($name)
|
||||
{
|
||||
// disable string callables to avoid calling a function named html or js,
|
||||
// or any other upcoming escaping strategy
|
||||
if (!is_string($this->defaultStrategy) && false !== $this->defaultStrategy) {
|
||||
return call_user_func($this->defaultStrategy, $filename);
|
||||
return call_user_func($this->defaultStrategy, $name);
|
||||
}
|
||||
|
||||
return $this->defaultStrategy;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* Default autoescaping strategy based on file names.
|
||||
*
|
||||
* This strategy sets the HTML as the default autoescaping strategy,
|
||||
* but changes it based on the filename.
|
||||
* but changes it based on the template name.
|
||||
*
|
||||
* Note that there is no runtime performance impact as the
|
||||
* default autoescaping strategy is set at compilation time.
|
||||
@@ -25,21 +25,21 @@ class Twig_FileExtensionEscapingStrategy
|
||||
/**
|
||||
* Guesses the best autoescaping strategy based on the file name.
|
||||
*
|
||||
* @param string $filename The template file name
|
||||
* @param string $name The template name
|
||||
*
|
||||
* @return string|false The escaping strategy name to use or false to disable
|
||||
*/
|
||||
public static function guess($filename)
|
||||
public static function guess($name)
|
||||
{
|
||||
if (in_array(substr($filename, -1), array('/', '\\'))) {
|
||||
if (in_array(substr($name, -1), array('/', '\\'))) {
|
||||
return 'html'; // return html for directories
|
||||
}
|
||||
|
||||
if ('.twig' === substr($filename, -5)) {
|
||||
$filename = substr($filename, 0, -5);
|
||||
if ('.twig' === substr($name, -5)) {
|
||||
$name = substr($name, 0, -5);
|
||||
}
|
||||
|
||||
$extension = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
$extension = pathinfo($name, PATHINFO_EXTENSION);
|
||||
|
||||
switch ($extension) {
|
||||
case 'js':
|
||||
|
||||
@@ -17,11 +17,13 @@
|
||||
class Twig_Node_Embed extends Twig_Node_Include
|
||||
{
|
||||
// we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module)
|
||||
public function __construct($filename, $index, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
|
||||
public function __construct($name, $index, Twig_Node_Expression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
|
||||
{
|
||||
parent::__construct(new Twig_Node_Expression_Constant('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag);
|
||||
|
||||
$this->setAttribute('filename', $filename);
|
||||
$this->setAttribute('name', $name);
|
||||
// to be removed in 2.0, used name instead
|
||||
$this->setAttribute('filename', $name);
|
||||
$this->setAttribute('index', $index);
|
||||
}
|
||||
|
||||
@@ -29,7 +31,7 @@ class Twig_Node_Embed extends Twig_Node_Include
|
||||
{
|
||||
$compiler
|
||||
->write('$this->loadTemplate(')
|
||||
->string($this->getAttribute('filename'))
|
||||
->string($this->getAttribute('name'))
|
||||
->raw(', ')
|
||||
->repr($this->getFilename())
|
||||
->raw(', ')
|
||||
|
||||
@@ -34,7 +34,7 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor
|
||||
protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
|
||||
{
|
||||
if ($node instanceof Twig_Node_Module) {
|
||||
if ($env->hasExtension('Twig_Extension_Escaper') && $defaultStrategy = $env->getExtension('Twig_Extension_Escaper')->getDefaultStrategy($node->getAttribute('filename'))) {
|
||||
if ($env->hasExtension('Twig_Extension_Escaper') && $defaultStrategy = $env->getExtension('Twig_Extension_Escaper')->getDefaultStrategy($node->getAttribute('name'))) {
|
||||
$this->defaultStrategy = $defaultStrategy;
|
||||
}
|
||||
$this->safeVars = array();
|
||||
|
||||
@@ -36,7 +36,7 @@ class Twig_Profiler_NodeVisitor_Profiler extends Twig_BaseNodeVisitor
|
||||
{
|
||||
if ($node instanceof Twig_Node_Module) {
|
||||
$varName = $this->getVarName();
|
||||
$node->setNode('display_start', new Twig_Node(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::TEMPLATE, $node->getAttribute('filename'), $varName), $node->getNode('display_start'))));
|
||||
$node->setNode('display_start', new Twig_Node(array(new Twig_Profiler_Node_EnterProfile($this->extensionName, Twig_Profiler_Profile::TEMPLATE, $node->getAttribute('name'), $varName), $node->getNode('display_start'))));
|
||||
$node->setNode('display_end', new Twig_Node(array(new Twig_Profiler_Node_LeaveProfile($varName), $node->getNode('display_end'))));
|
||||
} elseif ($node instanceof Twig_Node_Block) {
|
||||
$varName = $this->getVarName();
|
||||
|
||||
@@ -48,7 +48,7 @@ class Twig_TokenParser_Embed extends Twig_TokenParser_Include
|
||||
|
||||
$stream->expect(Twig_Token::BLOCK_END_TYPE);
|
||||
|
||||
return new Twig_Node_Embed($module->getAttribute('filename'), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
|
||||
return new Twig_Node_Embed($module->getAttribute('name'), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag());
|
||||
}
|
||||
|
||||
public function decideBlockEnd(Twig_Token $token)
|
||||
|
||||
@@ -16,6 +16,6 @@ blocks and autoescape
|
||||
--DATA--
|
||||
return array('br' => '<br />')
|
||||
--CONFIG--
|
||||
return array('autoescape' => 'filename')
|
||||
return array('autoescape' => 'name')
|
||||
--EXPECT--
|
||||
<br />
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
"filename" autoescape strategy
|
||||
"name" autoescape strategy
|
||||
--TEMPLATE--
|
||||
{{ br -}}
|
||||
{{ include('index.html.twig') -}}
|
||||
@@ -11,7 +11,7 @@
|
||||
--DATA--
|
||||
return array('br' => '<br />')
|
||||
--CONFIG--
|
||||
return array('autoescape' => 'filename')
|
||||
return array('autoescape' => 'name')
|
||||
--EXPECT--
|
||||
<br />
|
||||
<br />
|
||||
Reference in New Issue
Block a user