Skip to content

Commit 6e95c74

Browse files
committed
added begin method to connection and made timeout and database optional
1 parent 2568629 commit 6e95c74

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

src/Bolt/ServerStateRepository.php renamed to src/Bolt/StateTransitionRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* @psalm-immutable
2424
*/
25-
final class ServerStateRepository
25+
final class StateTransitionRepository
2626
{
2727
private const TRANSITIONS = [
2828
['CONNECTED', 'HELLO', null, 'SUCCESS', 'READY'],

src/Common/BoltConnection.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ final class BoltConnection implements ConnectionInterface
4747
private DriverConfiguration $driverConfiguration;
4848
private int $ownerCount = 0;
4949
private bool $hasBeenReset = false;
50+
private string $expectedState = 'READY';
5051

5152
/**
5253
* @psalm-mutation-free
@@ -172,6 +173,25 @@ public function reset(): void
172173
}
173174
}
174175

176+
/**
177+
* @param string|null $database the database to connect to
178+
* @param float|null $timeout timeout in seconds
179+
*/
180+
public function begin(?string $database, ?float $timeout): void
181+
{
182+
$params = [];
183+
if ($database) {
184+
$params['db'] = $database;
185+
}
186+
if ($timeout) {
187+
$params['tx_timeout'] = $timeout * 1000;
188+
}
189+
190+
if ($this->boltProtocol) {
191+
$this->boltProtocol->begin($params);
192+
}
193+
}
194+
175195
/**
176196
* @psalm-mutation-free
177197
*/

src/Databags/SessionConfiguration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ public function getAccessMode(): AccessMode
145145
/**
146146
* The database where the session is going to connect to.
147147
*/
148-
public function getDatabase(): string
148+
public function getDatabase(): ?string
149149
{
150-
return $this->database ?? self::DEFAULT_DATABASE;
150+
return $this->database;
151151
}
152152

153153
/**

src/Databags/TransactionConfiguration.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,29 @@ public static function default(): self
6262
/**
6363
* Get the configured transaction metadata.
6464
*
65-
* @return iterable<string, scalar|array|null>
65+
* @return iterable<string, scalar|array|null>|null
6666
*/
67-
public function getMetaData(): iterable
67+
public function getMetaData(): ?iterable
6868
{
6969
$tbr = $this->metaData;
7070
if (is_callable($tbr)) {
7171
$tbr = $tbr();
7272
}
7373

74-
return $tbr ?? [];
74+
return $tbr;
7575
}
7676

7777
/**
7878
* Get the configured transaction timeout in seconds.
7979
*/
80-
public function getTimeout(): float
80+
public function getTimeout(): ?float
8181
{
8282
$tbr = $this->timeout;
8383
if (is_callable($tbr)) {
8484
$tbr = $tbr();
8585
}
8686

87-
return $tbr ?? self::DEFAULT_TIMEOUT;
87+
return $tbr;
8888
}
8989

9090
/**

0 commit comments

Comments
 (0)