Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated TwigExtension to prevent deprecated messages #171

Merged
merged 1 commit into from
Sep 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Tests/Twig/Extension/LocaleSwitcherExtensionTest.php
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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