Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for ConnectionMiddleware to support DBAL 3 and DBAL 4 connection … #106

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"symfony/phpunit-bridge": "^6.4"
},
"autoload": {
"files": [
"src/aliases.php"
],
"psr-4": {
"DataDog\\AuditBundle\\": "src"
}
Expand Down
35 changes: 35 additions & 0 deletions src/DBAL/Middleware/ConnectionMiddlewareForV3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace DataDog\AuditBundle\DBAL\Middleware;

use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;

class ConnectionMiddlewareForV3 extends AbstractConnectionMiddleware
{
public function __construct(
Connection $wrappedConnection,
private readonly AuditFlushMiddleware $auditFlushMiddleware
)
{
parent::__construct($wrappedConnection);
}

/**
* Override of the commit method
*
* @throws Exception
*/
public function commit()
{
// Call the flusher callback if it's available.
if ($this->auditFlushMiddleware->flushHandler !== null) {
($this->auditFlushMiddleware->flushHandler)();
$this->auditFlushMiddleware->flushHandler = null;
}

// Call the parent's commit method
return parent::commit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;

class ConnectionMiddleware extends AbstractConnectionMiddleware
class ConnectionMiddlewareForV4 extends AbstractConnectionMiddleware
{
public function __construct(
Connection $wrappedConnection,
Expand Down
18 changes: 18 additions & 0 deletions src/aliases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace DataDog\AuditBundle;

use DataDog\AuditBundle\DBAL\Middleware\ConnectionMiddleware;
use DataDog\AuditBundle\DBAL\Middleware\ConnectionMiddlewareForV3;
use DataDog\AuditBundle\DBAL\Middleware\ConnectionMiddlewareForV4;
use Doctrine\DBAL\VersionAwarePlatformDriver;

if (!class_exists(ConnectionMiddleware::class)) {
if (!interface_exists(VersionAwarePlatformDriver::class)) {
class_alias(ConnectionMiddlewareForV4::class, ConnectionMiddleware::class);
} else {
class_alias(ConnectionMiddlewareForV3::class, ConnectionMiddleware::class);
}
}
Loading