Skip to content

Commit d7ec7e8

Browse files
Merge branch '3.3' into 3.4
* 3.3: fix merge typo [EventDispatcher] Fix ContainerAwareEventDispatcher::hasListeners(null) Use namespaced Twig
2 parents 5f2b26e + 4a6804c commit d7ec7e8

File tree

107 files changed

+786
-580
lines changed

Some content is hidden

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

107 files changed

+786
-580
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=5.5.9",
2020
"doctrine/common": "~2.4",
2121
"fig/link-util": "^1.0",
22-
"twig/twig": "~1.32|~2.2",
22+
"twig/twig": "~1.34|~2.4",
2323
"psr/cache": "~1.0",
2424
"psr/container": "^1.0",
2525
"psr/link": "^1.0",

src/Symfony/Bridge/Twig/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ CHANGELOG
3434
// ...
3535
$rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig'), $twig);
3636
// require Twig 1.30+
37-
$twig->addRuntimeLoader(new \Twig_FactoryRuntimeLoader(array(
37+
$twig->addRuntimeLoader(new \Twig\RuntimeLoader\FactoryRuntimeLoader(array(
3838
TwigRenderer::class => function () use ($rendererEngine, $csrfTokenManager) {
3939
return new TwigRenderer($rendererEngine, $csrfTokenManager);
4040
},

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\Console\Style\SymfonyStyle;
20+
use Twig\Environment;
2021

2122
/**
2223
* Lists twig functions, filters, globals and tests present in the current project.
@@ -35,18 +36,13 @@ public function __construct($name = 'debug:twig')
3536
parent::__construct($name);
3637
}
3738

38-
/**
39-
* Sets the twig environment.
40-
*
41-
* @param \Twig_Environment $twig
42-
*/
43-
public function setTwigEnvironment(\Twig_Environment $twig)
39+
public function setTwigEnvironment(Environment $twig)
4440
{
4541
$this->twig = $twig;
4642
}
4743

4844
/**
49-
* @return \Twig_Environment $twig
45+
* @return Environment $twig
5046
*/
5147
protected function getTwigEnvironment()
5248
{

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\Console\Style\SymfonyStyle;
2020
use Symfony\Component\Finder\Finder;
21+
use Twig\Environment;
22+
use Twig\Error\Error;
23+
use Twig\Loader\ArrayLoader;
24+
use Twig\Source;
2125

2226
/**
2327
* Command that will validate your template syntax and output encountered errors.
@@ -37,18 +41,13 @@ public function __construct($name = 'lint:twig')
3741
parent::__construct($name);
3842
}
3943

40-
/**
41-
* Sets the twig environment.
42-
*
43-
* @param \Twig_Environment $twig
44-
*/
45-
public function setTwigEnvironment(\Twig_Environment $twig)
44+
public function setTwigEnvironment(Environment $twig)
4645
{
4746
$this->twig = $twig;
4847
}
4948

5049
/**
51-
* @return \Twig_Environment $twig
50+
* @return Environment $twig
5251
*/
5352
protected function getTwigEnvironment()
5453
{
@@ -111,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
111110
return $this->display($input, $output, $io, $filesInfo);
112111
}
113112

114-
private function getFilesInfo(\Twig_Environment $twig, array $filenames)
113+
private function getFilesInfo(Environment $twig, array $filenames)
115114
{
116115
$filesInfo = array();
117116
foreach ($filenames as $filename) {
@@ -134,16 +133,16 @@ protected function findFiles($filename)
134133
throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename));
135134
}
136135

137-
private function validate(\Twig_Environment $twig, $template, $file)
136+
private function validate(Environment $twig, $template, $file)
138137
{
139138
$realLoader = $twig->getLoader();
140139
try {
141-
$temporaryLoader = new \Twig_Loader_Array(array((string) $file => $template));
140+
$temporaryLoader = new ArrayLoader(array((string) $file => $template));
142141
$twig->setLoader($temporaryLoader);
143-
$nodeTree = $twig->parse($twig->tokenize(new \Twig_Source($template, (string) $file)));
142+
$nodeTree = $twig->parse($twig->tokenize(new Source($template, (string) $file)));
144143
$twig->compile($nodeTree);
145144
$twig->setLoader($realLoader);
146-
} catch (\Twig_Error $e) {
145+
} catch (Error $e) {
147146
$twig->setLoader($realLoader);
148147

149148
return array('template' => $template, 'file' => $file, 'valid' => false, 'exception' => $e);
@@ -205,7 +204,7 @@ private function displayJson(OutputInterface $output, $filesInfo)
205204
return min($errors, 1);
206205
}
207206

208-
private function renderException(OutputInterface $output, $template, \Twig_Error $exception, $file = null)
207+
private function renderException(OutputInterface $output, $template, Error $exception, $file = null)
209208
{
210209
$line = $exception->getTemplateLine();
211210

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
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;
1821

1922
/**
2023
* TwigDataCollector.
@@ -26,7 +29,7 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterf
2629
private $profile;
2730
private $computed;
2831

29-
public function __construct(\Twig_Profiler_Profile $profile)
32+
public function __construct(Profile $profile)
3033
{
3134
$this->profile = $profile;
3235
}
@@ -73,7 +76,7 @@ public function getMacroCount()
7376

7477
public function getHtmlCallGraph()
7578
{
76-
$dumper = new \Twig_Profiler_Dumper_Html();
79+
$dumper = new HtmlDumper();
7780
$dump = $dumper->dump($this->getProfile());
7881

7982
// needed to remove the hardcoded CSS styles
@@ -87,14 +90,14 @@ public function getHtmlCallGraph()
8790
'<span class="status-success">',
8891
), $dump);
8992

90-
return new \Twig_Markup($dump, 'UTF-8');
93+
return new Markup($dump, 'UTF-8');
9194
}
9295

9396
public function getProfile()
9497
{
9598
if (null === $this->profile) {
9699
if (PHP_VERSION_ID >= 70000) {
97-
$this->profile = unserialize($this->data['profile'], array('allowed_classes' => array('Twig_Profiler_Profile')));
100+
$this->profile = unserialize($this->data['profile'], array('allowed_classes' => array('Twig_Profiler_Profile', 'Twig\Profiler\Profile')));
98101
} else {
99102
$this->profile = unserialize($this->data['profile']);
100103
}
@@ -112,7 +115,7 @@ private function getComputedData($index)
112115
return $this->computed[$index];
113116
}
114117

115-
private function computeData(\Twig_Profiler_Profile $profile)
118+
private function computeData(Profile $profile)
116119
{
117120
$data = array(
118121
'template_count' => 0,

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
namespace Symfony\Bridge\Twig\Extension;
1313

1414
use Symfony\Component\Asset\Packages;
15+
use Twig\Extension\AbstractExtension;
16+
use Twig\TwigFunction;
1517

1618
/**
1719
* Twig extension for the Symfony Asset component.
1820
*
1921
* @author Fabien Potencier <[email protected]>
2022
*/
21-
class AssetExtension extends \Twig_Extension
23+
class AssetExtension extends AbstractExtension
2224
{
2325
private $packages;
2426

@@ -33,8 +35,8 @@ public function __construct(Packages $packages)
3335
public function getFunctions()
3436
{
3537
return array(
36-
new \Twig_SimpleFunction('asset', array($this, 'getAssetUrl')),
37-
new \Twig_SimpleFunction('asset_version', array($this, 'getAssetVersion')),
38+
new TwigFunction('asset', array($this, 'getAssetUrl')),
39+
new TwigFunction('asset_version', array($this, 'getAssetVersion')),
3840
);
3941
}
4042

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
namespace Symfony\Bridge\Twig\Extension;
1313

1414
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
15+
use Twig\Extension\AbstractExtension;
16+
use Twig\TwigFilter;
1517

1618
/**
1719
* Twig extension relate to PHP code and used by the profiler and the default exception templates.
1820
*
1921
* @author Fabien Potencier <[email protected]>
2022
*/
21-
class CodeExtension extends \Twig_Extension
23+
class CodeExtension extends AbstractExtension
2224
{
2325
private $fileLinkFormat;
2426
private $rootDir;
@@ -44,15 +46,15 @@ public function __construct($fileLinkFormat, $rootDir, $charset)
4446
public function getFilters()
4547
{
4648
return array(
47-
new \Twig_SimpleFilter('abbr_class', array($this, 'abbrClass'), array('is_safe' => array('html'))),
48-
new \Twig_SimpleFilter('abbr_method', array($this, 'abbrMethod'), array('is_safe' => array('html'))),
49-
new \Twig_SimpleFilter('format_args', array($this, 'formatArgs'), array('is_safe' => array('html'))),
50-
new \Twig_SimpleFilter('format_args_as_text', array($this, 'formatArgsAsText')),
51-
new \Twig_SimpleFilter('file_excerpt', array($this, 'fileExcerpt'), array('is_safe' => array('html'))),
52-
new \Twig_SimpleFilter('format_file', array($this, 'formatFile'), array('is_safe' => array('html'))),
53-
new \Twig_SimpleFilter('format_file_from_text', array($this, 'formatFileFromText'), array('is_safe' => array('html'))),
54-
new \Twig_SimpleFilter('format_log_message', array($this, 'formatLogMessage'), array('is_safe' => array('html'))),
55-
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('format_log_message', array($this, 'formatLogMessage'), array('is_safe' => array('html'))),
57+
new TwigFilter('file_link', array($this, 'getFileLink')),
5658
);
5759
}
5860

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
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\Template;
20+
use Twig\TwigFunction;
1721

1822
/**
1923
* Provides integration of the dump() function with Twig.
2024
*
2125
* @author Nicolas Grekas <[email protected]>
2226
*/
23-
class DumpExtension extends \Twig_Extension
27+
class DumpExtension extends AbstractExtension
2428
{
2529
private $cloner;
2630
private $dumper;
@@ -34,7 +38,7 @@ public function __construct(ClonerInterface $cloner, HtmlDumper $dumper = null)
3438
public function getFunctions()
3539
{
3640
return array(
37-
new \Twig_SimpleFunction('dump', array($this, 'dump'), array('is_safe' => array('html'), 'needs_context' => true, 'needs_environment' => true)),
41+
new TwigFunction('dump', array($this, 'dump'), array('is_safe' => array('html'), 'needs_context' => true, 'needs_environment' => true)),
3842
);
3943
}
4044

@@ -48,7 +52,7 @@ public function getName()
4852
return 'dump';
4953
}
5054

51-
public function dump(\Twig_Environment $env, $context)
55+
public function dump(Environment $env, $context)
5256
{
5357
if (!$env->isDebug()) {
5458
return;
@@ -57,7 +61,7 @@ public function dump(\Twig_Environment $env, $context)
5761
if (2 === func_num_args()) {
5862
$vars = array();
5963
foreach ($context as $key => $value) {
60-
if (!$value instanceof \Twig_Template) {
64+
if (!$value instanceof Template) {
6165
$vars[$key] = $value;
6266
}
6367
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@
1212
namespace Symfony\Bridge\Twig\Extension;
1313

1414
use Symfony\Component\ExpressionLanguage\Expression;
15+
use Twig\Extension\AbstractExtension;
16+
use Twig\TwigFunction;
1517

1618
/**
1719
* ExpressionExtension gives a way to create Expressions from a template.
1820
*
1921
* @author Fabien Potencier <[email protected]>
2022
*/
21-
class ExpressionExtension extends \Twig_Extension
23+
class ExpressionExtension extends AbstractExtension
2224
{
2325
/**
2426
* {@inheritdoc}
2527
*/
2628
public function getFunctions()
2729
{
2830
return array(
29-
new \Twig_SimpleFunction('expression', array($this, 'createExpression')),
31+
new TwigFunction('expression', array($this, 'createExpression')),
3032
);
3133
}
3234

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@
1515
use Symfony\Bridge\Twig\Form\TwigRendererInterface;
1616
use Symfony\Component\DependencyInjection\ContainerInterface;
1717
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
18+
use Twig\Environment;
19+
use Twig\Extension\AbstractExtension;
20+
use Twig\Extension\InitRuntimeInterface;
21+
use Twig\TwigFilter;
22+
use Twig\TwigFunction;
23+
use Twig\TwigTest;
1824

1925
/**
2026
* FormExtension extends Twig with form capabilities.
2127
*
2228
* @author Fabien Potencier <[email protected]>
2329
* @author Bernhard Schussek <[email protected]>
2430
*/
25-
class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface
31+
class FormExtension extends AbstractExtension implements InitRuntimeInterface
2632
{
2733
/**
2834
* @deprecated since version 3.2, to be removed in 4.0 alongside with magic methods below
@@ -32,7 +38,7 @@ class FormExtension extends \Twig_Extension implements \Twig_Extension_InitRunti
3238
public function __construct($renderer = null)
3339
{
3440
if ($renderer instanceof TwigRendererInterface) {
35-
@trigger_error(sprintf('Passing a Twig Form Renderer to the "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0. Pass the Twig_Environment to the TwigRendererEngine constructor instead.', static::class), E_USER_DEPRECATED);
41+
@trigger_error(sprintf('Passing a Twig Form Renderer to the "%s" constructor is deprecated since version 3.2 and won\'t be possible in 4.0. Pass the Twig\Environment to the TwigRendererEngine constructor instead.', static::class), E_USER_DEPRECATED);
3642
} elseif (null !== $renderer && !(is_array($renderer) && isset($renderer[0], $renderer[1]) && $renderer[0] instanceof ContainerInterface)) {
3743
throw new \InvalidArgumentException(sprintf('Passing any arguments the constructor of %s is reserved for internal use.', __CLASS__));
3844
}
@@ -44,7 +50,7 @@ public function __construct($renderer = null)
4450
*
4551
* To be removed in 4.0
4652
*/
47-
public function initRuntime(\Twig_Environment $environment)
53+
public function initRuntime(Environment $environment)
4854
{
4955
if ($this->renderer instanceof TwigRendererInterface) {
5056
$this->renderer->setEnvironment($environment);
@@ -70,15 +76,15 @@ public function getTokenParsers()
7076
public function getFunctions()
7177
{
7278
return array(
73-
new \Twig_SimpleFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
74-
new \Twig_SimpleFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
75-
new \Twig_SimpleFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
76-
new \Twig_SimpleFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
77-
new \Twig_SimpleFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
78-
new \Twig_SimpleFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
79-
new \Twig_SimpleFunction('form_start', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
80-
new \Twig_SimpleFunction('form_end', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
81-
new \Twig_SimpleFunction('csrf_token', array('Symfony\Bridge\Twig\Form\TwigRenderer', 'renderCsrfToken')),
79+
new TwigFunction('form_widget', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
80+
new TwigFunction('form_errors', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
81+
new TwigFunction('form_label', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
82+
new TwigFunction('form_row', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
83+
new TwigFunction('form_rest', null, array('node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', 'is_safe' => array('html'))),
84+
new TwigFunction('form', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
85+
new TwigFunction('form_start', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
86+
new TwigFunction('form_end', null, array('node_class' => 'Symfony\Bridge\Twig\Node\RenderBlockNode', 'is_safe' => array('html'))),
87+
new TwigFunction('csrf_token', array('Symfony\Bridge\Twig\Form\TwigRenderer', 'renderCsrfToken')),
8288
);
8389
}
8490

@@ -88,7 +94,7 @@ public function getFunctions()
8894
public function getFilters()
8995
{
9096
return array(
91-
new \Twig_SimpleFilter('humanize', array('Symfony\Bridge\Twig\Form\TwigRenderer', 'humanize')),
97+
new TwigFilter('humanize', array('Symfony\Bridge\Twig\Form\TwigRenderer', 'humanize')),
9298
);
9399
}
94100

@@ -98,7 +104,7 @@ public function getFilters()
98104
public function getTests()
99105
{
100106
return array(
101-
new \Twig_SimpleTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),
107+
new TwigTest('selectedchoice', 'Symfony\Bridge\Twig\Extension\twig_is_selected_choice'),
102108
);
103109
}
104110

0 commit comments

Comments
 (0)