Skip to content

Commit

Permalink
Merge pull request #171 from jeroenvdgulik/master
Browse files Browse the repository at this point in the history
Updated TwigExtension to prevent deprecated messages
  • Loading branch information
lunetics committed Sep 11, 2015
2 parents fb41502 + 27a3dbf commit bcadc42
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions Tests/Twig/Extension/LocaleSwitcherExtensionTest.php
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of the LuneticsLocaleBundle package.
*
Expand All @@ -7,12 +8,12 @@
* For the full copyright and license information, please view the LICENSE
* file that is distributed with this source code.
*/

namespace Lunetics\LocaleBundle\Tests\Twig\Extension;

use Lunetics\LocaleBundle\LocaleInformation\AllowedLocalesProvider;
use Lunetics\LocaleBundle\Twig\Extension\LocaleSwitcherExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* @covers \Lunetics\LocaleBundle\Twig\Extension\LocaleSwitcherExtension
Expand All @@ -28,10 +29,10 @@ public function testGetFunctions()

$functions = $extension->getFunctions();

/** @var \Twig_Function_Method $twigExtension */
$twigExtension = $functions['locale_switcher'];
/** @var \Twig_SimpleFunction $twigExtension */
$twigExtension = current($functions);

$this->assertInstanceOf('Twig_Function_Method', $twigExtension);
$this->assertInstanceOf('Twig_SimpleFunction', $twigExtension);
$callable = $twigExtension->getCallable();
$this->assertEquals('renderSwitcher', $callable[1]);
$this->assertEquals(array('html'), $twigExtension->getSafe(new \Twig_Node()));
Expand Down
12 changes: 6 additions & 6 deletions Twig/Extension/LocaleSwitcherExtension.php
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of the LuneticsLocaleBundle package.
*
Expand All @@ -7,6 +8,7 @@
* For the full copyright and license information, please view the LICENSE
* file that is distributed with this source code.
*/

namespace Lunetics\LocaleBundle\Twig\Extension;

use Symfony\Component\DependencyInjection\ContainerInterface;
Expand All @@ -24,7 +26,7 @@ class LocaleSwitcherExtension extends \Twig_Extension
protected $container;

/**
* Constructor
* Constructor.
*
* @param ContainerInterface $container
*/
Expand All @@ -34,18 +36,16 @@ public function __construct(ContainerInterface $container)
}

/**
*
* @return array The added functions
*/
public function getFunctions()
{
return array(
'locale_switcher' => new \Twig_Function_Method($this, 'renderSwitcher', array('is_safe' => array('html')))
new \Twig_SimpleFunction('locale_switcher', array($this, 'renderSwitcher'), array('is_safe' => array('html'))),
);
}

/**
*
* @return string The name of the extension
*/
public function getName()
Expand All @@ -54,8 +54,8 @@ public function getName()
}

/**
* @param string $route A route name for which the switch has to be made
* @param array $parameters
* @param string $route A route name for which the switch has to be made
* @param array $parameters
* @param string $template
*
* @return mixed
Expand Down

0 comments on commit bcadc42

Please sign in to comment.