Skip to content

Commit ebe5363

Browse files
committed
Rewrite locker API
1 parent 6d6ef31 commit ebe5363

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

src/Locker/AdvisoryLockSessionLevel.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use Cog\DbLocker\LockId\PostgresLockId;
1717
use PDO;
1818

19+
/**
20+
* @internal
21+
*/
1922
final class AdvisoryLockSessionLevel
2023
{
2124
private bool $isReleased = false;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of PHP DB Locker.
5+
*
6+
* (c) Anton Komarev <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Cog\DbLocker\Locker;
15+
16+
/**
17+
* @internal
18+
*/
19+
final class AdvisoryLockTransactionLevel
20+
{
21+
public function __construct(
22+
public readonly bool $wasAcquired,
23+
) {}
24+
}

src/Locker/PostgresAdvisoryLocker.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,29 @@
2020
final class PostgresAdvisoryLocker
2121
{
2222
/**
23-
* Acquire a transaction-level advisory lock with a configurable acquisition type and mode.
23+
* Acquire a transaction-level advisory lock with configurable wait and access modes.
24+
*
25+
* TODO: Cover with tests
26+
*/
27+
public function acquireTransactionLevelLockHandler(
28+
PDO $dbConnection,
29+
PostgresLockId $postgresLockId,
30+
PostgresAdvisoryLockWaitModeEnum $waitMode = PostgresAdvisoryLockWaitModeEnum::NonBlocking,
31+
PostgresLockAccessModeEnum $accessMode = PostgresLockAccessModeEnum::Exclusive,
32+
): AdvisoryLockTransactionLevel {
33+
return new AdvisoryLockTransactionLevel(
34+
wasAcquired: $this->acquireLock(
35+
$dbConnection,
36+
$postgresLockId,
37+
PostgresAdvisoryLockLevelEnum::Transaction,
38+
$waitMode,
39+
$accessMode,
40+
),
41+
);
42+
}
43+
44+
/**
45+
* Acquire a transaction-level advisory lock with configurable wait and access modes.
2446
*/
2547
public function acquireTransactionLevelLock(
2648
PDO $dbConnection,
@@ -38,7 +60,7 @@ public function acquireTransactionLevelLock(
3860
}
3961

4062
/**
41-
* Acquire a session-level advisory lock with a configurable wait & access modes.
63+
* Acquire a session-level advisory lock with configurable wait and access modes.
4264
*
4365
* TODO: Write that transaction-level is recommended.
4466
* TODO: Cover with tests
@@ -65,7 +87,7 @@ public function acquireSessionLevelLockHandler(
6587
}
6688

6789
/**
68-
* Acquire a session-level advisory lock with a configurable wait & access modes.
90+
* Acquire a session-level advisory lock with configurable wait and access modes.
6991
*
7092
* TODO: Write that transaction-level is recommended.
7193
*/

0 commit comments

Comments
 (0)