Skip to content

Commit

Permalink
Subscriber to Listener refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
indjeto committed Feb 2, 2024
1 parent 3b190e4 commit e654216
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions docs/labeler.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class AuditLabler
}
```

Re-define the audit subscriber service to call the `setLabler` method of the `AuditSubscriber` with the [callable](https://www.php.net/manual/en/language.types.callable.php).
Re-define the audit listener service to call the `setLabler` method of the `AuditListener` with the [callable](https://www.php.net/manual/en/language.types.callable.php).

`app/config/services.yml`

```yaml
services:
datadog.event_subscriber.audit:
class: 'DataDog\AuditBundle\EventSubscriber\AuditSubscriber'
datadog.event_listener.audit:
class: 'DataDog\AuditBundle\EventListener\AuditListener'
arguments: ['@security.token_storage']
tags:
- { name: doctrine.event_subscriber, connection: default }
Expand Down
8 changes: 4 additions & 4 deletions src/DependencyInjection/DataDogAuditExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ public function load(array $configs, ContainerBuilder $container): void
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$auditSubscriber = $container->getDefinition('datadog.event_subscriber.audit');
$auditListener = $container->getDefinition('datadog.event_listener.audit');

if (isset($config['audited_entities']) && !empty($config['audited_entities'])) {
$auditSubscriber->addMethodCall('addAuditedEntities', array($config['audited_entities']));
$auditListener->addMethodCall('addAuditedEntities', array($config['audited_entities']));
} else if (isset($config['unaudited_entities'])) {
$auditSubscriber->addMethodCall('addUnauditedEntities', array($config['unaudited_entities']));
$auditListener->addMethodCall('addUnauditedEntities', array($config['unaudited_entities']));
}

if (isset($config['blame_impersonator'])) {
$auditSubscriber->addMethodCall('setBlameImpersonator', array($config['blame_impersonator']));
$auditListener->addMethodCall('setBlameImpersonator', array($config['blame_impersonator']));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DataDog\AuditBundle\EventSubscriber;
namespace DataDog\AuditBundle\EventListener;

use DataDog\AuditBundle\DBAL\AuditLogger;
use DataDog\AuditBundle\Entity\Association;
Expand All @@ -19,7 +19,7 @@
use Symfony\Component\Security\Core\Role\SwitchUserRole;
use Symfony\Component\Security\Core\User\UserInterface;

class AuditSubscriber
class AuditListener
{
/**
* @var callable|null
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use DataDog\AuditBundle\EventSubscriber\AuditSubscriber;
use DataDog\AuditBundle\EventListener\AuditListener;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

return static function (ContainerConfigurator $container) {
// @formatter:off
$services = $container->services();
$services
->set('datadog.event_subscriber.audit', AuditSubscriber::class)->private()
->set('datadog.event_listener.audit', AuditListener::class)->private()
->arg(0, new Reference(TokenStorageInterface::class))
//->tag('doctrine.event_subscriber')
->tag('doctrine.event_listener', ['event' => 'onFlush',])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

declare(strict_types=1);

namespace DataDog\AuditBundle\Tests\EventSubscriber;
namespace DataDog\AuditBundle\Tests\EventListener;

use DataDog\AuditBundle\Entity\AuditLog;
use DataDog\AuditBundle\Tests\Entity\Post;
use DataDog\AuditBundle\Tests\Entity\Tag;
use DataDog\AuditBundle\Tests\OrmTestCase;

final class AuditSubscriberTest extends OrmTestCase
final class AuditListenerTest extends OrmTestCase
{
protected function setUp(): void
{
Expand Down

0 comments on commit e654216

Please sign in to comment.