[TwigBridge] removed deprecations added in Twig 1.27
This commit is contained in:
parent
287713fd6a
commit
f0849d8331
@ -21,7 +21,7 @@
|
|||||||
"paragonie/random_compat": "~1.0",
|
"paragonie/random_compat": "~1.0",
|
||||||
"symfony/polyfill-apcu": "~1.1",
|
"symfony/polyfill-apcu": "~1.1",
|
||||||
"symfony/polyfill-mbstring": "~1.1",
|
"symfony/polyfill-mbstring": "~1.1",
|
||||||
"twig/twig": "~1.26|~2.0",
|
"twig/twig": "~1.27|~2.0",
|
||||||
"psr/log": "~1.0"
|
"psr/log": "~1.0"
|
||||||
},
|
},
|
||||||
"replace": {
|
"replace": {
|
||||||
|
@ -146,7 +146,7 @@ EOF
|
|||||||
try {
|
try {
|
||||||
$temporaryLoader = new \Twig_Loader_Array(array((string) $file => $template));
|
$temporaryLoader = new \Twig_Loader_Array(array((string) $file => $template));
|
||||||
$twig->setLoader($temporaryLoader);
|
$twig->setLoader($temporaryLoader);
|
||||||
$nodeTree = $twig->parse($twig->tokenize($template, (string) $file));
|
$nodeTree = $twig->parse($twig->tokenize(new \Twig_Source($template, (string) $file)));
|
||||||
$twig->compile($nodeTree);
|
$twig->compile($nodeTree);
|
||||||
$twig->setLoader($realLoader);
|
$twig->setLoader($realLoader);
|
||||||
} catch (\Twig_Error $e) {
|
} catch (\Twig_Error $e) {
|
||||||
|
@ -23,7 +23,7 @@ class RoutingExtensionTest extends \PHPUnit_Framework_TestCase
|
|||||||
$twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
|
$twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
|
||||||
$twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
|
$twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
|
||||||
|
|
||||||
$nodes = $twig->parse($twig->tokenize($template));
|
$nodes = $twig->parse($twig->tokenize(new \Twig_Source($template)));
|
||||||
|
|
||||||
$this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
|
$this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ class TranslationExtensionTest extends \PHPUnit_Framework_TestCase
|
|||||||
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
|
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
|
||||||
$twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector())));
|
$twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector())));
|
||||||
|
|
||||||
echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSource('index'), 'index')))."\n\n";
|
echo $twig->compile($twig->parse($twig->tokenize(new \Twig_Source($twig->getLoader()->getSource('index'), 'index'))))."\n\n";
|
||||||
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
|
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class TwigNodeProvider
|
|||||||
new \Twig_Node_Expression_Array(array(), 0),
|
new \Twig_Node_Expression_Array(array(), 0),
|
||||||
new \Twig_Node_Expression_Array(array(), 0),
|
new \Twig_Node_Expression_Array(array(), 0),
|
||||||
null,
|
null,
|
||||||
null
|
new \Twig_Source('')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class FormThemeTokenParserTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
|
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
|
||||||
$env->addTokenParser(new FormThemeTokenParser());
|
$env->addTokenParser(new FormThemeTokenParser());
|
||||||
$stream = $env->tokenize($source);
|
$stream = $env->tokenize(new \Twig_Source($source));
|
||||||
$parser = new \Twig_Parser($env);
|
$parser = new \Twig_Parser($env);
|
||||||
|
|
||||||
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
|
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
|
||||||
|
@ -64,7 +64,7 @@ class TransChoiceTokenParser extends TransTokenParser
|
|||||||
$body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
|
$body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
|
||||||
|
|
||||||
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
|
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
|
||||||
throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getLine(), $stream->getFilename());
|
throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getLine(), $stream->getSourceContext()->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
@ -55,7 +55,7 @@ class TransTokenParser extends \Twig_TokenParser
|
|||||||
$stream->next();
|
$stream->next();
|
||||||
$locale = $this->parser->getExpressionParser()->parseExpression();
|
$locale = $this->parser->getExpressionParser()->parseExpression();
|
||||||
} elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
|
} elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
|
||||||
throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getFilename());
|
throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getSourceContext()->getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ class TransTokenParser extends \Twig_TokenParser
|
|||||||
$body = $this->parser->subparse(array($this, 'decideTransFork'), true);
|
$body = $this->parser->subparse(array($this, 'decideTransFork'), true);
|
||||||
|
|
||||||
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
|
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
|
||||||
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getLine(), $stream->getFilename());
|
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getLine(), $stream->getSourceContext()->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
|
||||||
|
@ -62,9 +62,9 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
|
|||||||
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
|
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
|
||||||
} catch (\Twig_Error $e) {
|
} catch (\Twig_Error $e) {
|
||||||
if ($file instanceof SplFileInfo) {
|
if ($file instanceof SplFileInfo) {
|
||||||
$e->setTemplateFile($file->getRelativePathname());
|
$e->setTemplateName($file->getRelativePathname());
|
||||||
} elseif ($file instanceof \SplFileInfo) {
|
} elseif ($file instanceof \SplFileInfo) {
|
||||||
$e->setTemplateFile($file->getRealPath());
|
$e->setTemplateName($file->getRealPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
@ -85,7 +85,7 @@ class TwigExtractor extends AbstractFileExtractor implements ExtractorInterface
|
|||||||
$visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor();
|
$visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor();
|
||||||
$visitor->enable();
|
$visitor->enable();
|
||||||
|
|
||||||
$this->twig->parse($this->twig->tokenize($template));
|
$this->twig->parse($this->twig->tokenize(new \Twig_Source($template)));
|
||||||
|
|
||||||
foreach ($visitor->getMessages() as $message) {
|
foreach ($visitor->getMessages() as $message) {
|
||||||
$catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain);
|
$catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain);
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.9",
|
"php": ">=5.3.9",
|
||||||
"twig/twig": "~1.26|~2.0"
|
"twig/twig": "~1.27|~2.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/asset": "~2.7",
|
"symfony/asset": "~2.7",
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
"symfony/yaml": "~2.0,>=2.0.5",
|
"symfony/yaml": "~2.0,>=2.0.5",
|
||||||
"symfony/expression-language": "~2.6",
|
"symfony/expression-language": "~2.6",
|
||||||
"doctrine/doctrine-bundle": "~1.2",
|
"doctrine/doctrine-bundle": "~1.2",
|
||||||
"twig/twig": "~1.26|~2.0",
|
"twig/twig": "~1.27|~2.0",
|
||||||
"ircmaxell/password-compat": "~1.0"
|
"ircmaxell/password-compat": "~1.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
@ -167,7 +167,7 @@ class Configuration implements ConfigurationInterface
|
|||||||
$rootNode
|
$rootNode
|
||||||
->fixXmlConfig('path')
|
->fixXmlConfig('path')
|
||||||
->children()
|
->children()
|
||||||
->variableNode('autoescape')->defaultValue('filename')->end()
|
->variableNode('autoescape')->defaultValue('name')->end()
|
||||||
->scalarNode('autoescape_service')->defaultNull()->end()
|
->scalarNode('autoescape_service')->defaultNull()->end()
|
||||||
->scalarNode('autoescape_service_method')->defaultNull()->end()
|
->scalarNode('autoescape_service_method')->defaultNull()->end()
|
||||||
->scalarNode('base_template_class')->example('Twig_Template')->cannotBeEmpty()->end()
|
->scalarNode('base_template_class')->example('Twig_Template')->cannotBeEmpty()->end()
|
||||||
|
@ -147,7 +147,7 @@ class TwigExtensionTest extends TestCase
|
|||||||
$this->compileContainer($container);
|
$this->compileContainer($container);
|
||||||
|
|
||||||
$options = $container->getDefinition('twig')->getArgument(1);
|
$options = $container->getDefinition('twig')->getArgument(1);
|
||||||
$this->assertEquals('filename', $options['autoescape']);
|
$this->assertEquals('name', $options['autoescape']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGlobalsWithDifferentTypesAndValues()
|
public function testGlobalsWithDifferentTypesAndValues()
|
||||||
|
@ -27,7 +27,7 @@ class LegacyRenderTokenParserTest extends TestCase
|
|||||||
{
|
{
|
||||||
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
|
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
|
||||||
$env->addTokenParser(new RenderTokenParser());
|
$env->addTokenParser(new RenderTokenParser());
|
||||||
$stream = $env->tokenize($source);
|
$stream = $env->tokenize(new \Twig_Source($source));
|
||||||
$parser = new \Twig_Parser($env);
|
$parser = new \Twig_Parser($env);
|
||||||
|
|
||||||
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
|
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));
|
||||||
|
@ -54,13 +54,13 @@ class TwigEngine extends BaseEngine implements EngineInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated since version 2.7, to be removed in 3.0.
|
* @deprecated since version 2.7, to be removed in 3.0.
|
||||||
* Use the 'filename' strategy instead.
|
* Use the 'name' strategy instead.
|
||||||
*/
|
*/
|
||||||
public function guessDefaultEscapingStrategy($filename)
|
public function guessDefaultEscapingStrategy($name)
|
||||||
{
|
{
|
||||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Use the Twig_FileExtensionEscapingStrategy::guess method instead.', E_USER_DEPRECATED);
|
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.7 and will be removed in 3.0. Use the Twig_FileExtensionEscapingStrategy::guess method instead.', E_USER_DEPRECATED);
|
||||||
|
|
||||||
return \Twig_FileExtensionEscapingStrategy::guess($filename);
|
return \Twig_FileExtensionEscapingStrategy::guess($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,8 +73,8 @@ class TwigEngine extends BaseEngine implements EngineInterface
|
|||||||
} catch (\Twig_Error $e) {
|
} catch (\Twig_Error $e) {
|
||||||
if ($name instanceof TemplateReference) {
|
if ($name instanceof TemplateReference) {
|
||||||
try {
|
try {
|
||||||
// try to get the real file name of the template where the error occurred
|
// try to get the real name of the template where the error occurred
|
||||||
$e->setTemplateFile(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateFile()))));
|
$e->setTemplateName(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateName()))));
|
||||||
} catch (\Exception $e2) {
|
} catch (\Exception $e2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"php": ">=5.3.9",
|
"php": ">=5.3.9",
|
||||||
"symfony/asset": "~2.7",
|
"symfony/asset": "~2.7",
|
||||||
"symfony/twig-bridge": "~2.7",
|
"symfony/twig-bridge": "~2.7",
|
||||||
"twig/twig": "~1.26|~2.0",
|
"twig/twig": "~1.27|~2.0",
|
||||||
"symfony/http-foundation": "~2.5",
|
"symfony/http-foundation": "~2.5",
|
||||||
"symfony/http-kernel": "~2.7"
|
"symfony/http-kernel": "~2.7"
|
||||||
},
|
},
|
||||||
|
@ -97,21 +97,24 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
} elseif (isset($trace[$i]['object']) && $trace[$i]['object'] instanceof \Twig_Template) {
|
} elseif (isset($trace[$i]['object']) && $trace[$i]['object'] instanceof \Twig_Template) {
|
||||||
$info = $trace[$i]['object'];
|
$template = $trace[$i]['object'];
|
||||||
$name = $info->getTemplateName();
|
$name = $template->getTemplateName();
|
||||||
$src = method_exists($info, 'getSource') ? $info->getSource() : $info->getEnvironment()->getLoader()->getSource($name);
|
$file = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getPath() : false;
|
||||||
$info = $info->getDebugInfo();
|
$src = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false);
|
||||||
|
$info = $template->getDebugInfo();
|
||||||
if (null !== $src && isset($info[$trace[$i - 1]['line']])) {
|
if (null !== $src && isset($info[$trace[$i - 1]['line']])) {
|
||||||
$file = false;
|
|
||||||
$line = $info[$trace[$i - 1]['line']];
|
$line = $info[$trace[$i - 1]['line']];
|
||||||
$src = explode("\n", $src);
|
|
||||||
$fileExcerpt = array();
|
|
||||||
|
|
||||||
for ($i = max($line - 3, 1), $max = min($line + 3, count($src)); $i <= $max; ++$i) {
|
if ($src) {
|
||||||
$fileExcerpt[] = '<li'.($i === $line ? ' class="selected"' : '').'><code>'.$this->htmlEncode($src[$i - 1]).'</code></li>';
|
$src = explode("\n", $src);
|
||||||
|
$fileExcerpt = array();
|
||||||
|
|
||||||
|
for ($i = max($line - 3, 1), $max = min($line + 3, count($src)); $i <= $max; ++$i) {
|
||||||
|
$fileExcerpt[] = '<li'.($i === $line ? ' class="selected"' : '').'><code>'.$this->htmlEncode($src[$i - 1]).'</code></li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileExcerpt = '<ol start="'.max($line - 3, 1).'">'.implode("\n", $fileExcerpt).'</ol>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$fileExcerpt = '<ol start="'.max($line - 3, 1).'">'.implode("\n", $fileExcerpt).'</ol>';
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user