Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 661438c

Browse files
authored
Merge pull request #930 from victormacko/update-to-symfony-5
Updated to support Symfony 5.0 & Twig 3.0
2 parents 51cebfd + 8ff49d5 commit 661438c

11 files changed

+64
-45
lines changed

.travis.yml

100644100755
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ matrix:
1212
- php: 7.2
1313
env: DEPENDENCIES=beta SYMFONY_REQUIRE="3.4.*"
1414
- php: 7.2
15-
env: DEPENDENCIES=beta SYMFONY_REQUIRE="4.3.*"
15+
env: DEPENDENCIES=beta SYMFONY_REQUIRE="4.4.*"
16+
- php: 7.2
17+
env: DEPENDENCIES=beta SYMFONY_REQUIRE="5.0.*"
1618
- php: 7.3
1719
env: DEPENDENCIES=beta SYMFONY_REQUIRE="3.4.*"
1820
- php: 7.3
19-
env: DEPENDENCIES=beta SYMFONY_REQUIRE="4.3.*"
21+
env: DEPENDENCIES=beta SYMFONY_REQUIRE="4.4.*"
22+
- php: 7.3
23+
env: DEPENDENCIES=beta SYMFONY_REQUIRE="5.0.*"
2024
- php: hhvm
2125
allow_failures:
2226
- php: hhvm

Controller/DatatableController.php

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
use DateTime;
1515
use Doctrine\DBAL\Types\Type;
1616
use Exception;
17-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
17+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1818
use Symfony\Component\HttpFoundation\Request;
1919
use Symfony\Component\HttpFoundation\Response;
2020
use Symfony\Component\PropertyAccess\PropertyAccess;
2121
use Symfony\Component\PropertyAccess\PropertyAccessor;
2222
use Symfony\Component\Routing\Annotation\Route;
2323
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
2424

25-
class DatatableController extends Controller
25+
class DatatableController extends AbstractController
2626
{
2727
//-------------------------------------------------
2828
// Actions

Datatable/AbstractDatatable.php

100644100755
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
use Symfony\Component\Routing\RouterInterface;
2020
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
2121
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
22-
use Symfony\Component\Translation\TranslatorInterface;
23-
use Twig_Environment;
22+
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
23+
use Symfony\Contracts\Translation\TranslatorInterface;
24+
use Twig\Environment;
2425

2526
abstract class AbstractDatatable implements DatatableInterface
2627
{
@@ -62,7 +63,7 @@ abstract class AbstractDatatable implements DatatableInterface
6263
/**
6364
* The Twig Environment.
6465
*
65-
* @var Twig_Environment
66+
* @var Environment
6667
*/
6768
protected $twig;
6869

@@ -151,10 +152,10 @@ abstract class AbstractDatatable implements DatatableInterface
151152
public function __construct(
152153
AuthorizationCheckerInterface $authorizationChecker,
153154
TokenStorageInterface $securityToken,
154-
TranslatorInterface $translator,
155+
$translator,
155156
RouterInterface $router,
156157
EntityManagerInterface $em,
157-
Twig_Environment $twig
158+
Environment $twig
158159
) {
159160
$this->validateName();
160161

@@ -166,6 +167,10 @@ public function __construct(
166167

167168
$this->authorizationChecker = $authorizationChecker;
168169
$this->securityToken = $securityToken;
170+
171+
if (!($translator instanceof LegacyTranslatorInterface) && !($translator instanceof TranslatorInterface)) {
172+
throw new \InvalidArgumentException(sprintf('The $translator argument of %s must be an instance of %s or %s, a %s was given.', static::class, LegacyTranslatorInterface::class, TranslatorInterface::class, get_class($translator)));
173+
}
169174
$this->translator = $translator;
170175
$this->router = $router;
171176
$this->em = $em;

Datatable/Column/AbstractColumn.php

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Sg\DatatablesBundle\Datatable\OptionsTrait;
2020
use Symfony\Component\OptionsResolver\OptionsResolver;
2121
use Symfony\Component\Routing\RouterInterface;
22-
use Twig_Environment;
22+
use Twig\Environment;
2323

2424
abstract class AbstractColumn implements ColumnInterface
2525
{
@@ -915,7 +915,7 @@ public function getTwig()
915915
/**
916916
* @return $this
917917
*/
918-
public function setTwig(Twig_Environment $twig)
918+
public function setTwig(Environment $twig)
919919
{
920920
$this->twig = $twig;
921921

Datatable/Column/ColumnBuilder.php

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Exception;
1818
use Sg\DatatablesBundle\Datatable\Factory;
1919
use Symfony\Component\Routing\RouterInterface;
20-
use Twig_Environment;
20+
use Twig\Environment;
2121

2222
class ColumnBuilder
2323
{
@@ -88,7 +88,7 @@ class ColumnBuilder
8888
/**
8989
* @param string $datatableName
9090
*/
91-
public function __construct(ClassMetadata $metadata, Twig_Environment $twig, RouterInterface $router, $datatableName, EntityManagerInterface $em)
91+
public function __construct(ClassMetadata $metadata, Environment $twig, RouterInterface $router, $datatableName, EntityManagerInterface $em)
9292
{
9393
$this->metadata = $metadata;
9494
$this->twig = $twig;

Datatable/DatatableFactory.php

100644100755
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
use Symfony\Component\Routing\RouterInterface;
1717
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1818
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
19-
use Symfony\Component\Translation\TranslatorInterface;
20-
use Twig_Environment;
19+
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
20+
use Symfony\Contracts\Translation\TranslatorInterface;
21+
use Twig\Environment;
2122

2223
class DatatableFactory
2324
{
@@ -66,13 +67,17 @@ class DatatableFactory
6667
public function __construct(
6768
AuthorizationCheckerInterface $authorizationChecker,
6869
TokenStorageInterface $securityToken,
69-
TranslatorInterface $translator,
70+
object $translator,
7071
RouterInterface $router,
7172
EntityManagerInterface $em,
72-
Twig_Environment $twig
73+
Environment $twig
7374
) {
7475
$this->authorizationChecker = $authorizationChecker;
7576
$this->securityToken = $securityToken;
77+
78+
if (!($translator instanceof LegacyTranslatorInterface) && !($translator instanceof TranslatorInterface)) {
79+
throw new \InvalidArgumentException(sprintf('The $translator argument of %s must be an instance of %s or %s, a %s was given.', static::class, LegacyTranslatorInterface::class, TranslatorInterface::class, get_class($translator)));
80+
}
7681
$this->translator = $translator;
7782
$this->router = $router;
7883
$this->em = $em;

Tests/Column/ArrayColumnTest.php

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testArrayToString()
3131
$arrayColumn = new ArrayColumn();
3232
$result = $this->callMethod($arrayColumn, 'arrayToString', [['a', 'b' => ['d' => new \DateTime()]]]);
3333
static::assertNotEmpty($result);
34-
static::assertInternalType('string', $result);
34+
static::assertIsString($result);
3535
}
3636

3737
/**

Tests/DatatableTest.php

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
use Symfony\Component\Routing\RouterInterface;
1717
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1818
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
19-
use Symfony\Component\Translation\TranslatorInterface;
20-
use Twig_Environment;
19+
use Symfony\Contracts\Translation\TranslatorInterface;
20+
use Twig\Environment;
2121

2222
/**
2323
* @internal
@@ -38,7 +38,7 @@ public function testCreate()
3838
/** @noinspection PhpUndefinedMethodInspection */
3939
$router = $this->createMock(RouterInterface::class);
4040
/** @noinspection PhpUndefinedMethodInspection */
41-
$twig = $this->createMock(Twig_Environment::class);
41+
$twig = $this->createMock(Environment::class);
4242

4343
/** @noinspection PhpUndefinedMethodInspection */
4444
$em = $this->getMockBuilder(EntityManager::class)

Tests/Response/DatatableQueryBuilderTest.php

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ final class DatatableQueryBuilderTest extends \PHPUnit\Framework\TestCase
6767
/**
6868
* {@inheritdoc}
6969
*/
70-
protected function setUp()
70+
protected function setUp(): void
7171
{
7272
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
7373
$this->classMetadataFactory = $this->prophesize(ClassMetadataFactory::class);

Twig/DatatableTwigExtension.php

100644100755
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
use Sg\DatatablesBundle\Datatable\Filter\FilterInterface;
1919
use Symfony\Component\PropertyAccess\PropertyAccess;
2020
use Symfony\Component\PropertyAccess\PropertyAccessor;
21-
use Twig_Environment;
22-
use Twig_Extension;
23-
use Twig_SimpleFilter;
24-
use Twig_SimpleFunction;
21+
use Twig\Environment;
22+
use Twig\Extension\AbstractExtension;
23+
use Twig\TwigFilter;
24+
use Twig\TwigFunction;
2525

26-
class DatatableTwigExtension extends Twig_Extension
26+
class DatatableTwigExtension extends AbstractExtension
2727
{
2828
/**
2929
* The PropertyAccessor.
@@ -55,27 +55,27 @@ public function getName()
5555
public function getFunctions()
5656
{
5757
return [
58-
new Twig_SimpleFunction(
58+
new TwigFunction(
5959
'sg_datatables_render',
6060
[$this, 'datatablesRender'],
6161
['is_safe' => ['html'], 'needs_environment' => true]
6262
),
63-
new Twig_SimpleFunction(
63+
new TwigFunction(
6464
'sg_datatables_render_html',
6565
[$this, 'datatablesRenderHtml'],
6666
['is_safe' => ['html'], 'needs_environment' => true]
6767
),
68-
new Twig_SimpleFunction(
68+
new TwigFunction(
6969
'sg_datatables_render_js',
7070
[$this, 'datatablesRenderJs'],
7171
['is_safe' => ['html'], 'needs_environment' => true]
7272
),
73-
new Twig_SimpleFunction(
73+
new TwigFunction(
7474
'sg_datatables_render_filter',
7575
[$this, 'datatablesRenderFilter'],
7676
['is_safe' => ['html'], 'needs_environment' => true]
7777
),
78-
new Twig_SimpleFunction(
78+
new TwigFunction(
7979
'sg_datatables_render_multiselect_actions',
8080
[$this, 'datatablesRenderMultiselectActions'],
8181
['is_safe' => ['html'], 'needs_environment' => true]
@@ -89,7 +89,7 @@ public function getFunctions()
8989
public function getFilters()
9090
{
9191
return [
92-
new Twig_SimpleFilter('sg_datatables_bool_var', [$this, 'boolVar']),
92+
new TwigFilter('sg_datatables_bool_var', [$this, 'boolVar']),
9393
];
9494
}
9595

@@ -102,7 +102,7 @@ public function getFilters()
102102
*
103103
* @return string
104104
*/
105-
public function datatablesRender(Twig_Environment $twig, DatatableInterface $datatable)
105+
public function datatablesRender(Environment $twig, DatatableInterface $datatable)
106106
{
107107
return $twig->render(
108108
'@SgDatatables/datatable/datatable.html.twig',
@@ -117,7 +117,7 @@ public function datatablesRender(Twig_Environment $twig, DatatableInterface $dat
117117
*
118118
* @return string
119119
*/
120-
public function datatablesRenderHtml(Twig_Environment $twig, DatatableInterface $datatable)
120+
public function datatablesRenderHtml(Environment $twig, DatatableInterface $datatable)
121121
{
122122
return $twig->render(
123123
'@SgDatatables/datatable/datatable_html.html.twig',
@@ -132,7 +132,7 @@ public function datatablesRenderHtml(Twig_Environment $twig, DatatableInterface
132132
*
133133
* @return string
134134
*/
135-
public function datatablesRenderJs(Twig_Environment $twig, DatatableInterface $datatable)
135+
public function datatablesRenderJs(Environment $twig, DatatableInterface $datatable)
136136
{
137137
return $twig->render(
138138
'@SgDatatables/datatable/datatable_js.html.twig',
@@ -149,7 +149,7 @@ public function datatablesRenderJs(Twig_Environment $twig, DatatableInterface $d
149149
*
150150
* @return string
151151
*/
152-
public function datatablesRenderFilter(Twig_Environment $twig, DatatableInterface $datatable, ColumnInterface $column, $position)
152+
public function datatablesRenderFilter(Environment $twig, DatatableInterface $datatable, ColumnInterface $column, $position)
153153
{
154154
/** @var FilterInterface $filter */
155155
$filter = $this->accessor->getValue($column, 'filter');
@@ -181,7 +181,7 @@ public function datatablesRenderFilter(Twig_Environment $twig, DatatableInterfac
181181
*
182182
* @return string
183183
*/
184-
public function datatablesRenderMultiselectActions(Twig_Environment $twig, ColumnInterface $multiselectColumn, $pipeline)
184+
public function datatablesRenderMultiselectActions(Environment $twig, ColumnInterface $multiselectColumn, $pipeline)
185185
{
186186
$parameters = [];
187187
$values = [];

0 commit comments

Comments
 (0)