Skip to content

Commit fe8f4ab

Browse files
committed
feature #644 Using the new Twig namespace (yceruto)
This PR was merged into the master branch. Discussion ---------- Using the new Twig namespace Moving on to the latest changes... Commits ------- a4e5725 Using the new Twig namespace
2 parents a8e9adc + a4e5725 commit fe8f4ab

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/Twig/AppExtension.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
use App\Utils\Markdown;
1515
use Symfony\Component\Intl\Intl;
16+
use Twig\Extension\AbstractExtension;
17+
use Twig\TwigFilter;
18+
use Twig\TwigFunction;
1619

1720
/**
1821
* This Twig extension adds a new 'md2html' filter to easily transform Markdown
@@ -27,7 +30,7 @@
2730
* @author Javier Eguiluz <[email protected]>
2831
* @author Julien ITARD <[email protected]>
2932
*/
30-
class AppExtension extends \Twig_Extension
33+
class AppExtension extends AbstractExtension
3134
{
3235
private $parser;
3336
private $localeCodes;
@@ -45,7 +48,7 @@ public function __construct(Markdown $parser, $locales)
4548
public function getFilters()
4649
{
4750
return [
48-
new \Twig_SimpleFilter('md2html', [$this, 'markdownToHtml'], ['is_safe' => ['html']]),
51+
new TwigFilter('md2html', [$this, 'markdownToHtml'], ['is_safe' => ['html']]),
4952
];
5053
}
5154

@@ -55,7 +58,7 @@ public function getFilters()
5558
public function getFunctions()
5659
{
5760
return [
58-
new \Twig_SimpleFunction('locales', [$this, 'getLocales']),
61+
new TwigFunction('locales', [$this, 'getLocales']),
5962
];
6063
}
6164

src/Twig/SourceCodeExtension.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
namespace App\Twig;
1313

14+
use Twig\Environment;
15+
use Twig\Extension\AbstractExtension;
16+
use Twig\Template;
17+
use Twig\TwigFunction;
18+
1419
/**
1520
* CAUTION: this is an extremely advanced Twig extension. It's used to get the
1621
* source code of the controller and the template used to render the current
@@ -20,7 +25,7 @@
2025
* @author Ryan Weaver <[email protected]>
2126
* @author Javier Eguiluz <[email protected]>
2227
*/
23-
class SourceCodeExtension extends \Twig_Extension
28+
class SourceCodeExtension extends AbstractExtension
2429
{
2530
private $controller;
2631

@@ -35,11 +40,11 @@ public function setController($controller)
3540
public function getFunctions()
3641
{
3742
return [
38-
new \Twig_SimpleFunction('show_source_code', [$this, 'showSourceCode'], ['is_safe' => ['html'], 'needs_environment' => true]),
43+
new TwigFunction('show_source_code', [$this, 'showSourceCode'], ['is_safe' => ['html'], 'needs_environment' => true]),
3944
];
4045
}
4146

42-
public function showSourceCode(\Twig_Environment $twig, $template)
47+
public function showSourceCode(Environment $twig, $template)
4348
{
4449
return $twig->render('debug/source_code.html.twig', [
4550
'controller' => $this->getController(),
@@ -91,7 +96,7 @@ private function getCallableReflector($callable)
9196
return new \ReflectionFunction($callable);
9297
}
9398

94-
private function getTemplateSource(\Twig_Template $template)
99+
private function getTemplateSource(Template $template)
95100
{
96101
$templateSource = $template->getSourceContext();
97102

0 commit comments

Comments
 (0)