Skip to content

Commit

Permalink
feature #644 Using the new Twig namespace (yceruto)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
javiereguiluz committed Sep 7, 2017
2 parents a8e9adc + a4e5725 commit fe8f4ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/Twig/AppExtension.php
Expand Up @@ -13,6 +13,9 @@

use App\Utils\Markdown;
use Symfony\Component\Intl\Intl;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;

/**
* This Twig extension adds a new 'md2html' filter to easily transform Markdown
Expand All @@ -27,7 +30,7 @@
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
* @author Julien ITARD <julienitard@gmail.com>
*/
class AppExtension extends \Twig_Extension
class AppExtension extends AbstractExtension
{
private $parser;
private $localeCodes;
Expand All @@ -45,7 +48,7 @@ public function __construct(Markdown $parser, $locales)
public function getFilters()
{
return [
new \Twig_SimpleFilter('md2html', [$this, 'markdownToHtml'], ['is_safe' => ['html']]),
new TwigFilter('md2html', [$this, 'markdownToHtml'], ['is_safe' => ['html']]),
];
}

Expand All @@ -55,7 +58,7 @@ public function getFilters()
public function getFunctions()
{
return [
new \Twig_SimpleFunction('locales', [$this, 'getLocales']),
new TwigFunction('locales', [$this, 'getLocales']),
];
}

Expand Down
13 changes: 9 additions & 4 deletions src/Twig/SourceCodeExtension.php
Expand Up @@ -11,6 +11,11 @@

namespace App\Twig;

use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\Template;
use Twig\TwigFunction;

/**
* CAUTION: this is an extremely advanced Twig extension. It's used to get the
* source code of the controller and the template used to render the current
Expand All @@ -20,7 +25,7 @@
* @author Ryan Weaver <weaverryan@gmail.com>
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*/
class SourceCodeExtension extends \Twig_Extension
class SourceCodeExtension extends AbstractExtension
{
private $controller;

Expand All @@ -35,11 +40,11 @@ public function setController($controller)
public function getFunctions()
{
return [
new \Twig_SimpleFunction('show_source_code', [$this, 'showSourceCode'], ['is_safe' => ['html'], 'needs_environment' => true]),
new TwigFunction('show_source_code', [$this, 'showSourceCode'], ['is_safe' => ['html'], 'needs_environment' => true]),
];
}

public function showSourceCode(\Twig_Environment $twig, $template)
public function showSourceCode(Environment $twig, $template)
{
return $twig->render('debug/source_code.html.twig', [
'controller' => $this->getController(),
Expand Down Expand Up @@ -91,7 +96,7 @@ private function getCallableReflector($callable)
return new \ReflectionFunction($callable);
}

private function getTemplateSource(\Twig_Template $template)
private function getTemplateSource(Template $template)
{
$templateSource = $template->getSourceContext();

Expand Down

0 comments on commit fe8f4ab

Please sign in to comment.