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 26d67ea

Browse filesBrowse files
Use namespaced Twig
1 parent aa04f35 commit 26d67ea
Copy full SHA for 26d67ea

File tree

97 files changed

+856
-533
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner

97 files changed

+856
-533
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.28|~2.0",
24+
"twig/twig": "~1.34|~2.4",
2525
"psr/log": "~1.0"
2626
},
2727
"replace": {

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Command/DebugCommand.php
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Console\Input\InputOption;
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Output\OutputInterface;
19+
use Twig\Environment;
1920

2021
/**
2122
* Lists twig functions, filters, globals and tests present in the current project.
@@ -37,15 +38,15 @@ public function __construct($name = 'debug:twig')
3738
/**
3839
* Sets the twig environment.
3940
*
40-
* @param \Twig_Environment $twig
41+
* @param Environment $twig
4142
*/
42-
public function setTwigEnvironment(\Twig_Environment $twig)
43+
public function setTwigEnvironment(Environment $twig)
4344
{
4445
$this->twig = $twig;
4546
}
4647

4748
/**
48-
* @return \Twig_Environment $twig
49+
* @return Environment $twig
4950
*/
5051
protected function getTwigEnvironment()
5152
{
@@ -165,7 +166,7 @@ private function getMetadata($type, $entity)
165166
return false;
166167
}
167168

168-
return !$param->getClass() || $param->getClass()->getName() !== 'Twig_Environment';
169+
return !$param->getClass() || !in_array($param->getClass()->getName(), array('Twig_Environment', 'Twig\Environment'));
169170
});
170171

171172
// format args

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Command/LintCommand.php
+14-9Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\Finder\Finder;
20+
use Twig\Environment;
21+
use Twig\Error\Error;
22+
use Twig\Loader\ArrayLoader;
23+
use Twig\Source;
24+
use Twig\Template;
2025

2126
/**
2227
* Command that will validate your template syntax and output encountered errors.
@@ -39,15 +44,15 @@ public function __construct($name = 'lint:twig')
3944
/**
4045
* Sets the twig environment.
4146
*
42-
* @param \Twig_Environment $twig
47+
* @param Environment $twig
4348
*/
44-
public function setTwigEnvironment(\Twig_Environment $twig)
49+
public function setTwigEnvironment(Environment $twig)
4550
{
4651
$this->twig = $twig;
4752
}
4853

4954
/**
50-
* @return \Twig_Environment $twig
55+
* @return Environment $twig
5156
*/
5257
protected function getTwigEnvironment()
5358
{
@@ -117,7 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
117122
return $this->display($input, $output, $filesInfo);
118123
}
119124

120-
private function getFilesInfo(\Twig_Environment $twig, array $filenames)
125+
private function getFilesInfo(Environment $twig, array $filenames)
121126
{
122127
$filesInfo = array();
123128
foreach ($filenames as $filename) {
@@ -140,16 +145,16 @@ protected function findFiles($filename)
140145
throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename));
141146
}
142147

143-
private function validate(\Twig_Environment $twig, $template, $file)
148+
private function validate(Environment $twig, $template, $file)
144149
{
145150
$realLoader = $twig->getLoader();
146151
try {
147-
$temporaryLoader = new \Twig_Loader_Array(array((string) $file => $template));
152+
$temporaryLoader = new ArrayLoader(array((string) $file => $template));
148153
$twig->setLoader($temporaryLoader);
149-
$nodeTree = $twig->parse($twig->tokenize(new \Twig_Source($template, (string) $file)));
154+
$nodeTree = $twig->parse($twig->tokenize(new Source($template, (string) $file)));
150155
$twig->compile($nodeTree);
151156
$twig->setLoader($realLoader);
152-
} catch (\Twig_Error $e) {
157+
} catch (Error $e) {
153158
$twig->setLoader($realLoader);
154159

155160
return array('template' => $template, 'file' => $file, 'valid' => false, 'exception' => $e);
@@ -207,7 +212,7 @@ private function displayJson(OutputInterface $output, $filesInfo)
207212
return min($errors, 1);
208213
}
209214

210-
private function renderException(OutputInterface $output, $template, \Twig_Error $exception, $file = null)
215+
private function renderException(OutputInterface $output, $template, Error $exception, $file = null)
211216
{
212217
$line = $exception->getTemplateLine();
213218

‎src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
18+
use Twig\Markup;
19+
use Twig\Profiler\Dumper\HtmlDumper;
20+
use Twig\Profiler\Profile;
21+
use Twig\Source;
1822

1923
/**
2024
* TwigDataCollector.
@@ -26,7 +30,7 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
2630
private $profile;
2731
private $computed;
2832

29-
public function __construct(\Twig_Profiler_Profile $profile)
33+
public function __construct(Profile $profile)
3034
{
3135
$this->profile = $profile;
3236
}
@@ -73,9 +77,9 @@ public function getMacroCount()
7377

7478
public function getHtmlCallGraph()
7579
{
76-
$dumper = new \Twig_Profiler_Dumper_Html();
80+
$dumper = new HtmlDumper();
7781

78-
return new \Twig_Markup($dumper->dump($this->getProfile()), 'UTF-8');
82+
return new Markup($dumper->dump($this->getProfile()), 'UTF-8');
7983
}
8084

8185
public function getProfile()
@@ -96,7 +100,7 @@ private function getComputedData($index)
96100
return $this->computed[$index];
97101
}
98102

99-
private function computeData(\Twig_Profiler_Profile $profile)
103+
private function computeData(Profile $profile)
100104
{
101105
$data = array(
102106
'template_count' => 0,

‎src/Symfony/Bridge/Twig/Extension/AssetExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/AssetExtension.php
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313

1414
use Symfony\Component\Asset\Packages;
1515
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
16+
use Twig\Extension\AbstractExtension;
17+
use Twig\Source;
18+
use Twig\TwigFunction;
1619

1720
/**
1821
* Twig extension for the Symfony Asset component.
1922
*
2023
* @author Fabien Potencier <fabien@symfony.com>
2124
*/
22-
class AssetExtension extends \Twig_Extension
25+
class AssetExtension extends AbstractExtension
2326
{
2427
private $packages;
2528
private $foundationExtension;
@@ -40,9 +43,9 @@ public function __construct(Packages $packages, HttpFoundationExtension $foundat
4043
public function getFunctions()
4144
{
4245
return array(
43-
new \Twig_SimpleFunction('asset', array($this, 'getAssetUrl')),
44-
new \Twig_SimpleFunction('asset_version', array($this, 'getAssetVersion')),
45-
new \Twig_SimpleFunction('assets_version', array($this, 'getAssetsVersion'), array('deprecated' => true, 'alternative' => 'asset_version')),
46+
new TwigFunction('asset', array($this, 'getAssetUrl')),
47+
new TwigFunction('asset_version', array($this, 'getAssetVersion')),
48+
new TwigFunction('assets_version', array($this, 'getAssetsVersion'), array('deprecated' => true, 'alternative' => 'asset_version')),
4649
);
4750
}
4851

‎src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/CodeExtension.php
+13-9Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111

1212
namespace Symfony\Bridge\Twig\Extension;
1313

14+
use Twig\Extension\AbstractExtension;
15+
use Twig\Source;
16+
use Twig\TwigFilter;
17+
1418
/**
1519
* Twig extension relate to PHP code and used by the profiler and the default exception templates.
1620
*
1721
* @author Fabien Potencier <fabien@symfony.com>
1822
*/
19-
class CodeExtension extends \Twig_Extension
23+
class CodeExtension extends AbstractExtension
2024
{
2125
private $fileLinkFormat;
2226
private $rootDir;
@@ -42,14 +46,14 @@ public function __construct($fileLinkFormat, $rootDir, $charset)
4246
public function getFilters()
4347
{
4448
return array(
45-
new \Twig_SimpleFilter('abbr_class', array($this, 'abbrClass'), array('is_safe' => array('html'))),
46-
new \Twig_SimpleFilter('abbr_method', array($this, 'abbrMethod'), array('is_safe' => array('html'))),
47-
new \Twig_SimpleFilter('format_args', array($this, 'formatArgs'), array('is_safe' => array('html'))),
48-
new \Twig_SimpleFilter('format_args_as_text', array($this, 'formatArgsAsText')),
49-
new \Twig_SimpleFilter('file_excerpt', array($this, 'fileExcerpt'), array('is_safe' => array('html'))),
50-
new \Twig_SimpleFilter('format_file', array($this, 'formatFile'), array('is_safe' => array('html'))),
51-
new \Twig_SimpleFilter('format_file_from_text', array($this, 'formatFileFromText'), array('is_safe' => array('html'))),
52-
new \Twig_SimpleFilter('file_link', array($this, 'getFileLink')),
49+
new TwigFilter('abbr_class', array($this, 'abbrClass'), array('is_safe' => array('html'))),
50+
new TwigFilter('abbr_method', array($this, 'abbrMethod'), array('is_safe' => array('html'))),
51+
new TwigFilter('format_args', array($this, 'formatArgs'), array('is_safe' => array('html'))),
52+
new TwigFilter('format_args_as_text', array($this, 'formatArgsAsText')),
53+
new TwigFilter('file_excerpt', array($this, 'fileExcerpt'), array('is_safe' => array('html'))),
54+
new TwigFilter('format_file', array($this, 'formatFile'), array('is_safe' => array('html'))),
55+
new TwigFilter('format_file_from_text', array($this, 'formatFileFromText'), array('is_safe' => array('html'))),
56+
new TwigFilter('file_link', array($this, 'getFileLink')),
5357
);
5458
}
5559

‎src/Symfony/Bridge/Twig/Extension/DumpExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/DumpExtension.php
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414
use Symfony\Bridge\Twig\TokenParser\DumpTokenParser;
1515
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
1616
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
17+
use Twig\Environment;
18+
use Twig\Extension\AbstractExtension;
19+
use Twig\Source;
20+
use Twig\Template;
21+
use Twig\TwigFunction;
1722

1823
/**
1924
* Provides integration of the dump() function with Twig.
2025
*
2126
* @author Nicolas Grekas <p@tchwork.com>
2227
*/
23-
class DumpExtension extends \Twig_Extension
28+
class DumpExtension extends AbstractExtension
2429
{
2530
private $cloner;
2631

@@ -32,7 +37,7 @@ public function __construct(ClonerInterface $cloner)
3237
public function getFunctions()
3338
{
3439
return array(
35-
new \Twig_SimpleFunction('dump', array($this, 'dump'), array('is_safe' => array('html'), 'needs_context' => true, 'needs_environment' => true)),
40+
new TwigFunction('dump', array($this, 'dump'), array('is_safe' => array('html'), 'needs_context' => true, 'needs_environment' => true)),
3641
);
3742
}
3843

@@ -46,7 +51,7 @@ public function getName()
4651
return 'dump';
4752
}
4853

49-
public function dump(\Twig_Environment $env, $context)
54+
public function dump(Environment $env, $context)
5055
{
5156
if (!$env->isDebug()) {
5257
return;
@@ -55,7 +60,7 @@ public function dump(\Twig_Environment $env, $context)
5560
if (2 === func_num_args()) {
5661
$vars = array();
5762
foreach ($context as $key => $value) {
58-
if (!$value instanceof \Twig_Template) {
63+
if (!$value instanceof Template) {
5964
$vars[$key] = $value;
6065
}
6166
}

‎src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/ExpressionExtension.php
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,25 @@
1212
namespace Symfony\Bridge\Twig\Extension;
1313

1414
use Symfony\Component\ExpressionLanguage\Expression;
15+
use Twig\Extension\AbstractExtension;
16+
use Twig\Source;
17+
use Twig\Template;
18+
use Twig\TwigFunction;
1519

1620
/**
1721
* ExpressionExtension gives a way to create Expressions from a template.
1822
*
1923
* @author Fabien Potencier <fabien@symfony.com>
2024
*/
21-
class ExpressionExtension extends \Twig_Extension
25+
class ExpressionExtension extends AbstractExtension
2226
{
2327
/**
2428
* {@inheritdoc}
2529
*/
2630
public function getFunctions()
2731
{
2832
return array(
29-
new \Twig_SimpleFunction('expression', array($this, 'createExpression')),
33+
new TwigFunction('expression', array($this, 'createExpression')),
3034
);
3135
}
3236

‎src/Symfony/Bridge/Twig/Extension/FormExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Extension/FormExtension.php
+22-14Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@
1414
use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
1515
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
1616
use Symfony\Component\Form\Extension\Core\View\ChoiceView;
17+
use Twig\Environment;
18+
use Twig\Extension\AbstractExtension;
19+
use Twig\Source;
20+
use Twig\Template;
21+
use Twig\Token;
22+
use Twig\TwigFilter;
23+
use Twig\TwigFunction;
24+
use Twig\TwigTest;
1725

1826
/**
1927
* FormExtension extends Twig with form capabilities.
2028
*
2129
* @author Fabien Potencier <fabien@symfony.com>
2230
* @author Bernhard Schussek <bschussek@gmail.com>
2331
*/
24-
class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface
32+
class FormExtension extends AbstractExtension implements \Twig_Extension_InitRuntimeInterface
2533
{
2634
/**
2735
* This property is public so that it can be accessed directly from compiled
@@ -39,7 +47,7 @@ public function __construct(TwigRendererInterface $renderer)
3947
/**
4048
* {@inheritdoc}
4149
*/
42-
public function initRuntime(\Twig_Environment $environment)
50+
public function initRuntime(Environment $environment)
4351
{
4452
$this->renderer->setEnvironment($environment);
4553
}
@@ -61,16 +69,16 @@ public function getTokenParsers()
6169
public function getFunctions()
6270
{
6371
return array(
64-
new \Twig_SimpleFunction('form_enctype', null, array('node_class' => 'Symfony\Bridge\Twig\Node\FormEnctypeNode', 'is_safe' => array('html'), 'deprecated' => true, 'alternative' => 'form_start')),
65-
new \Twig_SimpleFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
66-
new \Twig_SimpleFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
67-
new \Twig_SimpleFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
68-
new \Twig_SimpleFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
69-
new \Twig_SimpleFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
70-
new \Twig_SimpleFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
71-
new \Twig_SimpleFunction('form_start', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
72-
new \Twig_SimpleFunction('form_end', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
73-
new \Twig_SimpleFunction('csrf_token', array($this, 'renderCsrfToken')),
72+
new TwigFunction('form_enctype', null, array('node_class' => 'Symfony\Bridge\Twig\Node\FormEnctypeNode', 'is_safe' => array('html'), 'deprecated' => true, 'alternative' => 'form_start')),
73+
new TwigFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
74+
new TwigFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
75+
new TwigFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
76+
new TwigFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
77+
new TwigFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
78+
new TwigFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
79+
new TwigFunction('form_start', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
80+
new TwigFunction('form_end', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
81+
new TwigFunction('csrf_token', array($this, 'renderCsrfToken')),
7482
);
7583
}
7684

@@ -80,7 +88,7 @@ public function getFunctions()
8088
public function getFilters()
8189
{
8290
return array(
83-
new \Twig_SimpleFilter('humanize', array($this, 'humanize')),
91+
new TwigFilter('humanize', array($this, 'humanize')),
8492
);
8593
}
8694

@@ -90,7 +98,7 @@ public function getFilters()
9098
public function getTests()
9199
{
92100
return array(
93-
new \Twig_SimpleTest('selectedchoice', array($this, 'isSelectedChoice')),
101+
new TwigTest('selectedchoice', array($this, 'isSelectedChoice')),
94102
);
95103
}
96104

0 commit comments

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