Skip to content

Commit 559fe6c

Browse files
Added abstract BoltException to simplify catch of bolt expcetions
1 parent 5cd2ddd commit 559fe6c

30 files changed

+85
-88
lines changed

src/Bolt.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Bolt;
44

55
use Bolt\error\ConnectException;
6-
use Exception;
6+
use Bolt\error\BoltException;
77
use Bolt\protocol\{AProtocol, ServerState};
88
use Bolt\connection\IConnection;
99

@@ -31,7 +31,7 @@ public function __construct(private IConnection $connection)
3131

3232
/**
3333
* Connect via Connection, execute handshake on it, create and return protocol version class
34-
* @throws Exception
34+
* @throws BoltException
3535
*/
3636
public function build(): AProtocol
3737
{
@@ -80,7 +80,7 @@ public function setConnection(IConnection $connection): Bolt
8080

8181
/**
8282
* @link https://www.neo4j.com/docs/bolt/current/bolt/handshake/
83-
* @throws Exception
83+
* @throws BoltException
8484
*/
8585
private function handshake(): string
8686
{

src/connection/IConnection.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Bolt\connection;
44

5+
use Bolt\error\ConnectException;
6+
57
/**
68
* Interface IConnection
79
*
@@ -13,10 +15,19 @@ interface IConnection
1315
{
1416
public function __construct(string $ip = '127.0.0.1', int $port = 7687, float $timeout = 15);
1517

18+
/**
19+
* @throws ConnectException
20+
*/
1621
public function connect(): bool;
1722

23+
/**
24+
* @throws ConnectException
25+
*/
1826
public function write(string $buffer): void;
1927

28+
/**
29+
* @throws ConnectException
30+
*/
2031
public function read(int $length = 2048): string;
2132

2233
public function disconnect(): void;

src/connection/Socket.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ class Socket extends AConnection
2222

2323
private const POSSIBLE_TIMEOUTS_CODES = [11, 10060];
2424

25-
/**
26-
* @throws ConnectException
27-
*/
2825
public function connect(): bool
2926
{
3027
if (!extension_loaded('sockets')) {
@@ -53,9 +50,6 @@ public function connect(): bool
5350
return true;
5451
}
5552

56-
/**
57-
* @throws ConnectException
58-
*/
5953
public function write(string $buffer): void
6054
{
6155
if ($this->socket === false) {
@@ -75,9 +69,6 @@ public function write(string $buffer): void
7569
}
7670
}
7771

78-
/**
79-
* @throws ConnectException
80-
*/
8172
public function read(int $length = 2048): string
8273
{
8374
if ($this->socket === false)

src/connection/StreamSocket.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ public function setSslContextOptions(array $options): void
3232
$this->sslContextOptions = $options;
3333
}
3434

35-
/**
36-
* @throws ConnectException
37-
*/
3835
public function connect(): bool
3936
{
4037
$context = stream_context_create([
@@ -65,9 +62,6 @@ public function connect(): bool
6562
return true;
6663
}
6764

68-
/**
69-
* @throws ConnectException
70-
*/
7165
public function write(string $buffer): void
7266
{
7367
if (Bolt::$debug)
@@ -91,9 +85,6 @@ public function write(string $buffer): void
9185
}
9286
}
9387

94-
/**
95-
* @throws ConnectException
96-
*/
9788
public function read(int $length = 2048): string
9889
{
9990
$output = '';

src/error/BoltException.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Bolt\error;
4+
5+
/**
6+
* Class BoltException
7+
* @package Bolt\error
8+
*/
9+
abstract class BoltException extends \Exception
10+
{
11+
12+
}

src/error/ConnectException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
namespace Bolt\error;
44

5-
use Exception;
6-
75
/**
86
* Class ConnectException
97
*
108
* @author Michal Stefanak
119
* @link https://github.com/neo4j-php/Bolt
1210
* @package Bolt\error
1311
*/
14-
class ConnectException extends Exception
12+
class ConnectException extends BoltException
1513
{
1614

1715
}

src/error/PackException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
namespace Bolt\error;
44

5-
use Exception;
6-
75
/**
86
* Class PackException
97
*
108
* @author Michal Stefanak
119
* @link https://github.com/neo4j-php/Bolt
1210
* @package Bolt\error
1311
*/
14-
class PackException extends Exception
12+
class PackException extends BoltException
1513
{
1614

1715
}

src/error/UnpackException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
namespace Bolt\error;
44

5-
use Exception;
6-
75
/**
86
* Class UnpackException
97
*
108
* @author Michal Stefanak
119
* @link https://github.com/neo4j-php/Bolt
1210
* @package Bolt\error
1311
*/
14-
class UnpackException extends Exception
12+
class UnpackException extends BoltException
1513
{
1614

1715
}

src/packstream/IPacker.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Bolt\packstream;
44

5+
use Bolt\error\PackException;
6+
57
/**
68
* Interface IPacker
79
*
@@ -18,6 +20,7 @@ public function __construct(array $structuresLt = []);
1820

1921
/**
2022
* Pack message
23+
* @throws PackException
2124
*/
2225
public function pack(int $signature, mixed ...$params): iterable;
2326
}

src/packstream/IUnpacker.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Bolt\packstream;
44

5+
use Bolt\error\UnpackException;
6+
57
/**
68
* Interface IUnpacker
79
*
@@ -18,6 +20,7 @@ public function __construct(array $structuresLt = []);
1820

1921
/**
2022
* Unpack message
23+
* @throws UnpackException
2124
*/
2225
public function unpack(string $msg): mixed;
2326

0 commit comments

Comments
 (0)