-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from indjeto/fix-for-dbal-versions
Fix for ConnectionMiddleware to support DBAL 3 and DBAL 4 connection …
- Loading branch information
Showing
4 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |