-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop Twig 1.x support / Add Twig 3.x support (#1270)
* Drop Twig 1.x support * Avoid using internal method/class usage * Support Twig 3.x * Update tests
- Loading branch information
Showing
11 changed files
with
89 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the MopaBootstrapBundle. | ||
* | ||
* (c) Philipp A. Mohrenweiser <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Mopa\Bundle\BootstrapBundle\Tests\Stub; | ||
|
||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
class StubTranslator implements TranslatorInterface | ||
{ | ||
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null): string | ||
{ | ||
return '[trans]'.\strtr($id, $parameters).'[/trans]'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,33 +11,30 @@ | |
|
||
namespace Mopa\Bundle\BootstrapBundle\Twig; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
/** | ||
* MopaBootstrap Flash Extension. | ||
* | ||
* @author Nikolai Zujev (jaymecd) <[email protected]> | ||
*/ | ||
class FlashExtension extends \Twig_Extension | ||
class FlashExtension extends AbstractExtension | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $mapping = []; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct(array $mapping) | ||
{ | ||
$this->mapping = $mapping; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFunctions() | ||
public function getFunctions(): array | ||
{ | ||
return [ | ||
new \Twig_SimpleFunction('mopa_bootstrap_flash_mapping', [$this, 'getMapping'], ['is_safe' => ['html']]), | ||
new TwigFunction('mopa_bootstrap_flash_mapping', [$this, 'getMapping'], ['is_safe' => ['html']]), | ||
]; | ||
} | ||
|
||
|
@@ -50,12 +47,4 @@ public function getMapping() | |
{ | ||
return $this->mapping; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'mopa_bootstrap_flash'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,9 @@ | |
|
||
namespace Mopa\Bundle\BootstrapBundle\Twig; | ||
|
||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFunction; | ||
|
||
/** | ||
* Twig extension for form. | ||
* | ||
|
@@ -19,34 +22,19 @@ | |
* @author Paweł Madej (nysander) <[email protected]> | ||
* @author Charles Sanquer <[email protected]> | ||
*/ | ||
class FormExtension extends \Twig_Extension | ||
class FormExtension extends AbstractExtension | ||
{ | ||
/** | ||
* Returns a list of functions to add to the existing list. | ||
* | ||
* @return array An array of functions | ||
*/ | ||
public function getFunctions() | ||
public function getFunctions(): array | ||
{ | ||
return [ | ||
new \Twig_SimpleFunction('form_help', null, [ | ||
new TwigFunction('form_help', null, [ | ||
'node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', | ||
'is_safe' => ['html'], | ||
]), | ||
new \Twig_SimpleFunction('form_tabs', null, [ | ||
new TwigFunction('form_tabs', null, [ | ||
'node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode', | ||
'is_safe' => ['html'], | ||
]), | ||
]; | ||
} | ||
|
||
/** | ||
* Returns the name of the extension. | ||
* | ||
* @return string The extension name | ||
*/ | ||
public function getName() | ||
{ | ||
return 'bootstrap_form'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,58 +11,56 @@ | |
|
||
namespace Mopa\Bundle\BootstrapBundle\Twig; | ||
|
||
use Symfony\Component\HttpFoundation\Response; | ||
use Twig\Environment; | ||
use Twig\Extension\AbstractExtension; | ||
use Twig\TemplateWrapper; | ||
use Twig\TwigFunction; | ||
|
||
/** | ||
* MopaBootstrap Icon Extension. | ||
* | ||
* @author Craig Blanchette (isometriks) <[email protected]> | ||
*/ | ||
class IconExtension extends \Twig_Extension | ||
class IconExtension extends AbstractExtension | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $iconSet; | ||
|
||
/** | ||
* @var string | ||
* @var string|null | ||
*/ | ||
protected $shortcut; | ||
|
||
/** | ||
* @var \Twig_Template | ||
* @var TemplateWrapper|null | ||
*/ | ||
protected $iconTemplate; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param string $iconSet | ||
* @param string $shortcut | ||
* @param string $iconSet | ||
* @param string|null $shortcut | ||
*/ | ||
public function __construct($iconSet, $shortcut = null) | ||
{ | ||
$this->iconSet = $iconSet; | ||
$this->shortcut = $shortcut; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFunctions() | ||
public function getFunctions(): array | ||
{ | ||
$options = [ | ||
'is_safe' => ['html'], | ||
'needs_environment' => true, | ||
]; | ||
|
||
$functions = [ | ||
new \Twig_SimpleFunction('mopa_bootstrap_icon', [$this, 'renderIcon'], $options), | ||
new TwigFunction('mopa_bootstrap_icon', [$this, 'renderIcon'], $options), | ||
]; | ||
|
||
if ($this->shortcut) { | ||
$functions[] = new \Twig_SimpleFunction($this->shortcut, [$this, 'renderIcon'], $options); | ||
$functions[] = new TwigFunction($this->shortcut, [$this, 'renderIcon'], $options); | ||
} | ||
|
||
return $functions; | ||
|
@@ -73,10 +71,8 @@ public function getFunctions() | |
* | ||
* @param string $icon | ||
* @param bool $inverted | ||
* | ||
* @return Response | ||
*/ | ||
public function renderIcon(\Twig_Environment $env, $icon, $inverted = false) | ||
public function renderIcon(Environment $env, $icon, $inverted = false): string | ||
{ | ||
$template = $this->getIconTemplate($env); | ||
$context = [ | ||
|
@@ -87,21 +83,10 @@ public function renderIcon(\Twig_Environment $env, $icon, $inverted = false) | |
return $template->renderBlock($this->iconSet, $context); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'mopa_bootstrap_icon'; | ||
} | ||
|
||
/** | ||
* @return \Twig_Template | ||
*/ | ||
protected function getIconTemplate(\Twig_Environment $env) | ||
protected function getIconTemplate(Environment $env): TemplateWrapper | ||
{ | ||
if ($this->iconTemplate === null) { | ||
$this->iconTemplate = $env->loadTemplate('@MopaBootstrap/icons.html.twig'); | ||
$this->iconTemplate = $env->load('@MopaBootstrap/icons.html.twig'); | ||
} | ||
|
||
return $this->iconTemplate; | ||
|
Oops, something went wrong.