Skip to content

Commit 4e035c6

Browse files
committed
Address Symfony 4.x deprecations
1 parent 34d45cc commit 4e035c6

4 files changed

Lines changed: 87 additions & 2 deletions

File tree

DependencyInjection/Configuration.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@
2323
*/
2424
class Configuration implements ConfigurationInterface
2525
{
26+
const ROOT_NODE_NAME = 'xiidea_easy_audit';
27+
2628
/**
2729
* {@inheritdoc}
2830
*/
2931
public function getConfigTreeBuilder()
3032
{
31-
$treeBuilder = new TreeBuilder();
33+
$treeBuilder = new TreeBuilder(self::ROOT_NODE_NAME);
3234

33-
$rootNode = $treeBuilder->root('xiidea_easy_audit');
35+
$rootNode = $this->getRootNode($treeBuilder);
3436

3537
$this->addRequiredConfigs($rootNode);
3638
$this->addDefaultServices($rootNode);
@@ -204,4 +206,17 @@ private function isEmpty()
204206
return empty($v);
205207
};
206208
}
209+
210+
/**
211+
* @param TreeBuilder $treeBuilder
212+
* @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition
213+
*/
214+
protected function getRootNode($treeBuilder)
215+
{
216+
if (method_exists($treeBuilder, 'getRootNode')) {
217+
return $treeBuilder->getRootNode();
218+
}
219+
220+
return $treeBuilder->root(self::ROOT_NODE_NAME);
221+
}
207222
}

Subscriber/DoctrineSubscriber.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
1616
use Doctrine\Common\Util\ClassUtils;
1717
use Symfony\Component\EventDispatcher\EventDispatcher;
18+
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
1819
use Xiidea\EasyAuditBundle\Annotation\SubscribeDoctrineEvents;
1920
use Xiidea\EasyAuditBundle\Events\DoctrineObjectEvent;
2021
use Xiidea\EasyAuditBundle\Events\DoctrineEvents;
@@ -243,6 +244,10 @@ private function isScheduledForDelete($entity)
243244
*/
244245
public function setDispatcher($dispatcher)
245246
{
247+
if(class_exists(LegacyEventDispatcherProxy::class)) {
248+
$dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
249+
}
250+
246251
$this->dispatcher = $dispatcher;
247252
}
248253
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Xiidea\EasyAuditBundle\Tests\DependencyInjection;
4+
5+
6+
use PHPUnit\Framework\TestCase;
7+
use Xiidea\EasyAuditBundle\DependencyInjection\Configuration;
8+
use Xiidea\EasyAuditBundle\Tests\Fixtures\Common\TestableConfiguration;
9+
10+
class TreeBuilderOld {
11+
12+
public function root()
13+
{
14+
return 'ROOT_METHOD';
15+
}
16+
}
17+
18+
class TreeBuilderNew extends TreeBuilderOld {
19+
20+
public function getRootNode()
21+
{
22+
return 'GET_ROOT_NODE_METHOD';
23+
}
24+
}
25+
26+
class ConfigurationTest extends TestCase
27+
{
28+
29+
public function testGetRootNodeByCallingGetRootNodeMethodOfBuilder()
30+
{
31+
$configuration = new TestableConfiguration();
32+
33+
34+
$result = $configuration->getRootNodeOfBuilder(new TreeBuilderNew());
35+
36+
$this->assertEquals('GET_ROOT_NODE_METHOD', $result);
37+
38+
}
39+
40+
public function testGetRootNodeByCallingRootMethodOfBuilder()
41+
{
42+
$configuration = new TestableConfiguration();
43+
44+
45+
$result = $configuration->getRootNodeOfBuilder(new TreeBuilderOld());
46+
47+
$this->assertEquals('ROOT_METHOD', $result);
48+
49+
}
50+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
4+
namespace Xiidea\EasyAuditBundle\Tests\Fixtures\Common;
5+
6+
7+
use Xiidea\EasyAuditBundle\DependencyInjection\Configuration;
8+
9+
class TestableConfiguration extends Configuration
10+
{
11+
public function getRootNodeOfBuilder($builder)
12+
{
13+
return $this->getRootNode($builder);
14+
}
15+
}

0 commit comments

Comments
 (0)