Skip to content

Commit 7c22b40

Browse files
committed
Update Twig bridge
1 parent 8b5d787 commit 7c22b40

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

SensioLabs/AnsiConverter/Bridge/Twig/AnsiExtension.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,45 @@
33
namespace SensioLabs\AnsiConverter\Bridge\Twig;
44

55
use SensioLabs\AnsiConverter\AnsiToHtmlConverter;
6+
use Twig\Extension\AbstractExtension;
7+
use Twig\TwigFilter;
8+
use Twig\TwigFunction;
69

7-
class AnsiExtension extends \Twig_Extension
10+
class AnsiExtension extends AbstractExtension
811
{
12+
/** @var AnsiToHtmlConverter */
913
private $converter;
1014

1115
public function __construct(AnsiToHtmlConverter $converter = null)
1216
{
1317
$this->converter = $converter ?: new AnsiToHtmlConverter();
1418
}
1519

16-
public function getFilters()
20+
public function getFilters(): array
1721
{
18-
return array(
19-
new \Twig_SimpleFilter('ansi_to_html', array($this, 'ansiToHtml'), array('is_safe' => array('html'))),
20-
);
22+
return [
23+
new TwigFilter('ansi_to_html', [$this, 'ansiToHtml'], ['is_safe' => ['html']]),
24+
];
2125
}
2226

23-
public function getFunctions()
27+
public function getFunctions(): array
2428
{
25-
return array(
26-
new \Twig_SimpleFunction('ansi_css', array($this, 'css'), array('is_safe' => array('css'))),
27-
);
29+
return [
30+
new TwigFunction('ansi_css', [$this, 'css'], ['is_safe' => ['css']]),
31+
];
2832
}
2933

3034
public function ansiToHtml($string)
3135
{
3236
return $this->converter->convert($string);
3337
}
3438

35-
public function css()
39+
public function css(): string
3640
{
3741
return $this->converter->getTheme()->asCss();
3842
}
3943

40-
public function getName()
44+
public function getName(): string
4145
{
4246
return 'sensiolabs_ansi';
4347
}

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=5.3.0"
13+
"php": "^7.0"
14+
},
15+
"require-dev": {
16+
"twig/twig": "^2.4 || ^3.0"
1417
},
1518
"suggest": {
1619
"twig/twig": "Provides nice templating features"
1720
},
21+
"conflict": {
22+
"twig/twig": "< 2.4.0"
23+
},
1824
"autoload": {
1925
"psr-0": { "SensioLabs\\AnsiConverter": "." }
2026
},
2127
"extra": {
2228
"branch-alias": {
23-
"dev-master": "1.1-dev"
29+
"dev-master": "1.2-dev"
2430
}
2531
}
2632
}

0 commit comments

Comments
 (0)