Skip to content

Commit 6f565c3

Browse files
author
Frank Verhoeven
authored
Merge pull request #2 from MyOnlineStore/update-twig
fix twig deprecations and upgrade twig to ~2|~3
2 parents 8347a13 + 9ea981b commit 6f565c3

File tree

6 files changed

+54
-47
lines changed

6 files changed

+54
-47
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ clover.xml
66
/vendor/
77
/Tests/cache
88
/Tests/log
9+
.phpunit.result.cache

DependencyInjection/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class Configuration implements ConfigurationInterface
2525
*/
2626
public function getConfigTreeBuilder()
2727
{
28-
$treeBuilder = new TreeBuilder();
29-
$rootNode = $treeBuilder->root('fm_bbcode', 'array');
28+
$treeBuilder = new TreeBuilder('fm_bbcode');
29+
$rootNode = $treeBuilder->getRootNode();
3030

3131
$rootNode
3232
->children()

Templating/BbcodeExtension.php

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
namespace FM\BbcodeBundle\Templating;
44

5+
use FM\BbcodeBundle\Decoda\DecodaManager;
56
use Symfony\Component\DependencyInjection\ContainerInterface;
6-
use FM\BbcodeBundle\Decoda\DecodaManager as DecodaManager;
7+
use Twig\Error\RuntimeError;
8+
use Twig\Extension\AbstractExtension;
9+
use Twig\TwigFilter;
710

811
/**
9-
* @author Al Ganiev <helios.ag@gmail.com>
12+
* @author Al Ganiev <helios.ag@gmail.com>
1013
* @copyright 2012-2015 Al Ganiev
11-
* @license http://www.opensource.org/licenses/mit-license.php MIT License
14+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
1215
*/
13-
class BbcodeExtension extends \Twig_Extension
16+
class BbcodeExtension extends AbstractExtension
1417
{
1518
/**
1619
* @var DecodaManager
@@ -26,20 +29,22 @@ public function __construct(DecodaManager $decodaManager)
2629
}
2730

2831
/**
29-
* (non-PHPdoc).
32+
* Strip tags.
3033
*
31-
* @see Twig_Extension::getFilters()
34+
* @param $value
35+
* @param $filterSet
3236
*
33-
* @return array
37+
* @return string
38+
*
39+
* @throws RuntimeError
3440
*/
35-
public function getFilters()
41+
public function clean($value, $filterSet = DecodaManager::DECODA_DEFAULT)
3642
{
37-
$options = array('is_safe' => array('html'));
43+
if (!is_string($value)) {
44+
throw new RuntimeError('The filter can be applied to strings only.');
45+
}
3846

39-
return array(
40-
new \Twig_SimpleFilter('bbcode_filter', array($this, 'filter'), $options),
41-
new \Twig_SimpleFilter('bbcode_clean', array($this, 'clean'), $options),
42-
);
47+
return $this->decodaManager->get($value, $filterSet)->strip(true);
4348
}
4449

4550
/**
@@ -49,40 +54,38 @@ public function getFilters()
4954
* @return string
5055
* @return \FM\BbcodeBundle\Decoda\Decoda
5156
*
52-
* @throws \Twig_Error_Runtime
57+
* @throws RuntimeError
5358
*/
5459
public function filter($value, $filterSet = DecodaManager::DECODA_DEFAULT)
5560
{
5661
if (!is_string($value)) {
57-
throw new \Twig_Error_Runtime('The filter can be applied to strings only.');
62+
throw new RuntimeError('The filter can be applied to strings only.');
5863
}
5964

6065
return $this->decodaManager->get($value, $filterSet)->parse();
6166
}
6267

6368
/**
64-
* Strip tags.
65-
*
66-
* @param $value
67-
* @param $filterSet
69+
* (non-PHPdoc).
6870
*
69-
* @return string
71+
* @return array
72+
* @see AbstractExtension::getFilters()
7073
*
71-
* @throws \Twig_Error_Runtime
7274
*/
73-
public function clean($value, $filterSet = DecodaManager::DECODA_DEFAULT)
75+
public function getFilters()
7476
{
75-
if (!is_string($value)) {
76-
throw new \Twig_Error_Runtime('The filter can be applied to strings only.');
77-
}
77+
$options = ['is_safe' => ['html']];
7878

79-
return $this->decodaManager->get($value, $filterSet)->strip(true);
79+
return [
80+
new TwigFilter('bbcode_filter', [$this, 'filter'], $options),
81+
new TwigFilter('bbcode_clean', [$this, 'clean'], $options),
82+
];
8083
}
8184

8285
/**
8386
* (non-PHPdoc).
8487
*
85-
* @see Twig_ExtensionInterface::getName()
88+
* @see AbstractExtension::getName()
8689
*/
8790
public function getName()
8891
{

Templating/Helper/BbcodeHelper.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
use Symfony\Component\DependencyInjection\ContainerInterface;
66
use Symfony\Component\Templating\Helper\Helper;
7-
use FM\BbcodeBundle\Decoda\DecodaManager as DecodaManager;
7+
use FM\BbcodeBundle\Decoda\DecodaManager;
8+
use Twig\Error\RuntimeError;
89

910
/**
1011
* @author Al Ganiev <helios.ag@gmail.com>
@@ -32,12 +33,12 @@ public function __construct(DecodaManager $decodaManager)
3233
*
3334
* @return string
3435
*
35-
* @throws \Twig_Error_Runtime
36+
* @throws RuntimeError
3637
*/
3738
public function filter($value, $filterSet = DecodaManager::DECODA_DEFAULT)
3839
{
3940
if (!is_string($value)) {
40-
throw new \Twig_Error_Runtime('The filter can be applied to strings only.');
41+
throw new RuntimeError('The filter can be applied to strings only.');
4142
}
4243

4344
return $this->decodaManager->get($value, $filterSet)->parse();
@@ -51,12 +52,12 @@ public function filter($value, $filterSet = DecodaManager::DECODA_DEFAULT)
5152
*
5253
* @return string
5354
*
54-
* @throws \Twig_Error_Runtime
55+
* @throws RuntimeError
5556
*/
5657
public function clean($value, $filterSet = DecodaManager::DECODA_DEFAULT)
5758
{
5859
if (!is_string($value)) {
59-
throw new \Twig_Error_Runtime('The filter can be applied to strings only.');
60+
throw new RuntimeError('The filter can be applied to strings only.');
6061
}
6162

6263
return $this->decodaManager->get($value, $filterSet)->strip(true);

Tests/TwigBasedTestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace FM\BbcodeBundle\Tests;
44

55
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6+
use Twig\Environment;
67

78
/**
89
* @author Christian Raue <christian.raue@gmail.com>
@@ -12,7 +13,7 @@
1213
abstract class TwigBasedTestCase extends WebTestCase
1314
{
1415
/**
15-
* @var \Twig_Environment
16+
* @var Environment
1617
*/
1718
protected $twig;
1819

composer.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@
1414
}
1515
],
1616
"require": {
17-
"php": "^7.1.3",
17+
"php": "^7.2",
1818
"mjohnson/decoda": "6.*",
19-
"symfony/twig-bundle": "~3.3|~4.0",
20-
"symfony/config": "~3.3|~4.0",
21-
"symfony/console": "~3.3|~4.0",
22-
"symfony/dependency-injection": "~3.3|~4.0",
19+
"symfony/twig-bundle": "~4.0",
20+
"symfony/config": "~4.0",
21+
"symfony/console": "~4.0",
22+
"symfony/dependency-injection": "~4.0",
2323
"symfony/framework-bundle": "~3.2|~4.0",
2424
"symfony/http-foundation": "~3.2|~4.0",
25-
"symfony/http-kernel": "~3.3|~4.0",
26-
"symfony/process": "~3.3|~4.0",
27-
"symfony/templating": "~3.3|~4.0",
28-
"symfony/yaml": "~3.3|~4.0",
29-
"twig/twig": "^1.42"
25+
"symfony/http-kernel": "~4.0",
26+
"symfony/process": "~4.0",
27+
"symfony/templating": "~4.0",
28+
"symfony/yaml": "~4.0",
29+
"twig/twig": "~2|~3"
3030
},
3131
"require-dev": {
3232
"roave/security-advisories": "dev-master",
33-
"symfony/symfony": "~3.3|~4.0",
33+
"symfony/symfony": "~4.0",
3434
"php-coveralls/php-coveralls": "~2.0",
35-
"phpunit/phpunit": "~7.1"
35+
"phpunit/phpunit": "~7.1",
36+
"symfony/phpunit-bridge": "^5.1"
3637
},
3738
"autoload": {
3839
"psr-4": {

0 commit comments

Comments
 (0)