Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b68cd71

Browse filesBrowse files
committed
[TwigBridge] removed deprecations added in Twig 1.27
1 parent 287713f commit b68cd71
Copy full SHA for b68cd71

File tree

14 files changed

+31
-28
lines changed
Filter options

14 files changed

+31
-28
lines changed

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"paragonie/random_compat": "~1.0",
2222
"symfony/polyfill-apcu": "~1.1",
2323
"symfony/polyfill-mbstring": "~1.1",
24-
"twig/twig": "~1.26|~2.0",
24+
"twig/twig": "~1.27|~2.0",
2525
"psr/log": "~1.0"
2626
},
2727
"replace": {

‎src/Symfony/Bridge/Twig/Command/LintCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Command/LintCommand.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private function validate(\Twig_Environment $twig, $template, $file)
146146
try {
147147
$temporaryLoader = new \Twig_Loader_Array(array((string) $file => $template));
148148
$twig->setLoader($temporaryLoader);
149-
$nodeTree = $twig->parse($twig->tokenize($template, (string) $file));
149+
$nodeTree = $twig->parse($twig->tokenize(new \Twig_Source($template, (string) $file)));
150150
$twig->compile($nodeTree);
151151
$twig->setLoader($realLoader);
152152
} catch (\Twig_Error $e) {

‎src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testEscaping($template, $mustBeEscaped)
2323
$twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
2424
$twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
2525

26-
$nodes = $twig->parse($twig->tokenize($template));
26+
$nodes = $twig->parse($twig->tokenize(new \Twig_Source($template)));
2727

2828
$this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
2929
}

‎src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/TranslationExtensionTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testTrans($template, $expected, array $variables = array())
3636
$twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
3737
$twig->addExtension(new TranslationExtension(new Translator('en', new MessageSelector())));
3838

39-
echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSource('index'), 'index')))."\n\n";
39+
echo $twig->compile($twig->parse($twig->tokenize(new \Twig_Source($twig->getLoader()->getSource('index'), 'index'))))."\n\n";
4040
$this->assertEquals($expected, $this->getTemplate($template)->render($variables));
4141
}
4242

‎src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function getModule($content)
2525
new \Twig_Node_Expression_Array(array(), 0),
2626
new \Twig_Node_Expression_Array(array(), 0),
2727
null,
28-
null
28+
new \Twig_Source('')
2929
);
3030
}
3131

‎src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testCompile($source, $expected)
2323
{
2424
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
2525
$env->addTokenParser(new FormThemeTokenParser());
26-
$stream = $env->tokenize($source);
26+
$stream = $env->tokenize(new \Twig_Source($source));
2727
$parser = new \Twig_Parser($env);
2828

2929
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));

‎src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function parse(\Twig_Token $token)
6464
$body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true);
6565

6666
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
67-
throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getLine(), $stream->getFilename());
67+
throw new \Twig_Error_Syntax('A message inside a transchoice tag must be a simple text.', $body->getLine(), $stream->getSourceContext()->getName());
6868
}
6969

7070
$stream->expect(\Twig_Token::BLOCK_END_TYPE);

‎src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function parse(\Twig_Token $token)
5555
$stream->next();
5656
$locale = $this->parser->getExpressionParser()->parseExpression();
5757
} elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
58-
throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getFilename());
58+
throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with", "from", or "into" keyword.', $stream->getCurrent()->getLine(), $stream->getSourceContext()->getName());
5959
}
6060
}
6161

@@ -64,7 +64,7 @@ public function parse(\Twig_Token $token)
6464
$body = $this->parser->subparse(array($this, 'decideTransFork'), true);
6565

6666
if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) {
67-
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getLine(), $stream->getFilename());
67+
throw new \Twig_Error_Syntax('A message inside a trans tag must be a simple text.', $body->getLine(), $stream->getSourceContext()->getName());
6868
}
6969

7070
$stream->expect(\Twig_Token::BLOCK_END_TYPE);

‎src/Symfony/Bridge/Twig/Translation/TwigExtractor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Translation/TwigExtractor.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public function extract($resource, MessageCatalogue $catalogue)
6262
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
6363
} catch (\Twig_Error $e) {
6464
if ($file instanceof SplFileInfo) {
65-
$e->setTemplateFile($file->getRelativePathname());
65+
$e->setTemplateName($file->getRelativePathname());
6666
} elseif ($file instanceof \SplFileInfo) {
67-
$e->setTemplateFile($file->getRealPath());
67+
$e->setTemplateName($file->getRealPath());
6868
}
6969

7070
throw $e;
@@ -85,7 +85,7 @@ protected function extractTemplate($template, MessageCatalogue $catalogue)
8585
$visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor();
8686
$visitor->enable();
8787

88-
$this->twig->parse($this->twig->tokenize($template));
88+
$this->twig->parse($this->twig->tokenize(new \Twig_Source($template)));
8989

9090
foreach ($visitor->getMessages() as $message) {
9191
$catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain);

‎src/Symfony/Bridge/Twig/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.9",
20-
"twig/twig": "~1.26|~2.0"
20+
"twig/twig": "~1.27|~2.0"
2121
},
2222
"require-dev": {
2323
"symfony/asset": "~2.7",

‎src/Symfony/Bundle/SecurityBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"symfony/yaml": "~2.0,>=2.0.5",
3838
"symfony/expression-language": "~2.6",
3939
"doctrine/doctrine-bundle": "~1.2",
40-
"twig/twig": "~1.26|~2.0",
40+
"twig/twig": "~1.27|~2.0",
4141
"ircmaxell/password-compat": "~1.0"
4242
},
4343
"autoload": {

‎src/Symfony/Bundle/TwigBundle/TwigEngine.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/TwigEngine.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public function render($name, array $parameters = array())
7373
} catch (\Twig_Error $e) {
7474
if ($name instanceof TemplateReference) {
7575
try {
76-
// try to get the real file name of the template where the error occurred
77-
$e->setTemplateFile(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateFile()))));
76+
// try to get the real name of the template where the error occurred
77+
$e->setTemplateName(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateName()))));
7878
} catch (\Exception $e2) {
7979
}
8080
}

‎src/Symfony/Bundle/TwigBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=5.3.9",
2020
"symfony/asset": "~2.7",
2121
"symfony/twig-bridge": "~2.7",
22-
"twig/twig": "~1.26|~2.0",
22+
"twig/twig": "~1.27|~2.0",
2323
"symfony/http-foundation": "~2.5",
2424
"symfony/http-kernel": "~2.7"
2525
},

‎src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php
+14-11Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,24 @@ public function dump(Data $data)
9797

9898
break;
9999
} elseif (isset($trace[$i]['object']) && $trace[$i]['object'] instanceof \Twig_Template) {
100-
$info = $trace[$i]['object'];
101-
$name = $info->getTemplateName();
102-
$src = method_exists($info, 'getSource') ? $info->getSource() : $info->getEnvironment()->getLoader()->getSource($name);
103-
$info = $info->getDebugInfo();
100+
$template = $trace[$i]['object'];
101+
$name = $template->getTemplateName();
102+
$file = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getPath() : false;
103+
$src = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false);
104+
$info = $template->getDebugInfo();
104105
if (null !== $src && isset($info[$trace[$i - 1]['line']])) {
105-
$file = false;
106106
$line = $info[$trace[$i - 1]['line']];
107-
$src = explode("\n", $src);
108-
$fileExcerpt = array();
109107

110-
for ($i = max($line - 3, 1), $max = min($line + 3, count($src)); $i <= $max; ++$i) {
111-
$fileExcerpt[] = '<li'.($i === $line ? ' class="selected"' : '').'><code>'.$this->htmlEncode($src[$i - 1]).'</code></li>';
112-
}
108+
if ($src) {
109+
$src = explode("\n", $src);
110+
$fileExcerpt = array();
111+
112+
for ($i = max($line - 3, 1), $max = min($line + 3, count($src)); $i <= $max; ++$i) {
113+
$fileExcerpt[] = '<li'.($i === $line ? ' class="selected"' : '').'><code>'.$this->htmlEncode($src[$i - 1]).'</code></li>';
114+
}
113115

114-
$fileExcerpt = '<ol start="'.max($line - 3, 1).'">'.implode("\n", $fileExcerpt).'</ol>';
116+
$fileExcerpt = '<ol start="'.max($line - 3, 1).'">'.implode("\n", $fileExcerpt).'</ol>';
117+
}
115118
}
116119
break;
117120
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.