Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
144 additions
and
26 deletions.
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
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,36 @@ | ||
<?php | ||
|
||
namespace Doctrine\Bundle\DoctrineBundle\Middleware; | ||
|
||
use ArrayObject; | ||
use Doctrine\DBAL\Driver; | ||
use Doctrine\DBAL\Driver\Middleware; | ||
use Symfony\Bridge\Doctrine\Middleware\IdleConnection\Driver as IdleConnectionDriver; | ||
|
||
class IdleConnectionMiddleware implements Middleware, ConnectionNameAwareInterface | ||
{ | ||
private ArrayObject $connectionExpiries; | ||
/** @var array<string, int> */ | ||
private array $ttlByConnection; | ||
private string $connectionName; | ||
|
||
/** | ||
* @param ArrayObject<string, int> $connectionExpiries | ||
* @param array<string, int> $ttlByConnection | ||
*/ | ||
public function __construct(ArrayObject $connectionExpiries, array $ttlByConnection) | ||
{ | ||
$this->connectionExpiries = $connectionExpiries; | ||
$this->ttlByConnection = $ttlByConnection; | ||
} | ||
|
||
public function setConnectionName(string $name): void | ||
{ | ||
$this->connectionName = $name; | ||
} | ||
|
||
public function wrap(Driver $driver): Driver | ||
{ | ||
return new IdleConnectionDriver($driver, $this->connectionExpiries, $this->ttlByConnection[$this->connectionName], $this->connectionName); | ||
Check failure on line 34 in Middleware/IdleConnectionMiddleware.php GitHub Actions / Static Analysis with PsalmUndefinedClass
|
||
} | ||
} |
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
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,25 @@ | ||
<?php | ||
|
||
namespace Doctrine\Bundle\DoctrineBundle\Tests\Middleware; | ||
|
||
use Doctrine\Bundle\DoctrineBundle\Middleware\IdleConnectionMiddleware; | ||
use Doctrine\DBAL\Driver; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bridge\Doctrine\Middleware\IdleConnection\Driver as IdleConnectionDriver; | ||
|
||
class IdleConnectionMiddlewareTest extends TestCase | ||
{ | ||
public function testWrap() | ||
{ | ||
$connectionExpiries = new \ArrayObject(['connectionone' => time() - 30, 'connectiontwo' => time() + 40]); | ||
Check failure on line 14 in Tests/Middleware/IdleConnectionMiddlewareTest.php GitHub Actions / Coding Standards / Coding Standards (8.2)
Check failure on line 14 in Tests/Middleware/IdleConnectionMiddlewareTest.php GitHub Actions / Coding Standards / Coding Standards (8.2)
|
||
$ttlByConnection = ['connectionone' => 25, 'connectiontwo' => 60]; | ||
|
||
$middleware = new IdleConnectionMiddleware($connectionExpiries, $ttlByConnection); | ||
Check failure on line 17 in Tests/Middleware/IdleConnectionMiddlewareTest.php GitHub Actions / Static Analysis with PsalmInvalidArgument
|
||
$middleware->setConnectionName('connectionone'); | ||
|
||
$driverMock = $this->createMock(Driver::class); | ||
$wrappedDriver = $middleware->wrap($driverMock); | ||
|
||
$this->assertInstanceOf(IdleConnectionDriver::class, $wrappedDriver); | ||
Check failure on line 23 in Tests/Middleware/IdleConnectionMiddlewareTest.php GitHub Actions / Static Analysis with PsalmUndefinedClass
|
||
} | ||
} |