Skip to content

Commit 80da31c

Browse files
author
Jonathon Hill
committed
Better imports and exception handling
1 parent 636f305 commit 80da31c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/Handlers/RedisHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
use Compwright\PhpSession\Config;
1010
use Compwright\PhpSession\SessionId;
11-
use Exception;
1211
use MatthiasMullie\Scrapbook\Adapters\Redis as RedisKeyValueStore;
1312
use Redis;
13+
use RuntimeException;
1414

1515
/**
1616
* Redis session store.
@@ -25,7 +25,7 @@ public function __construct(Config $config)
2525
$this->sid = new SessionId($config);
2626

2727
if (!extension_loaded('redis')) {
28-
throw new Exception('Missing redis extension');
28+
throw new RuntimeException('Missing redis extension');
2929
}
3030
}
3131

src/Manager.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
namespace Compwright\PhpSession;
88

9+
use InvalidArgumentException;
10+
use RuntimeException;
11+
use SessionUpdateTimestampHandlerInterface;
12+
use Throwable;
13+
914
class Manager
1015
{
1116
protected Config $config;
@@ -87,7 +92,7 @@ public function commit(): bool
8792
public function create_id(string $prefix = "")
8893
{
8994
if ($prefix && preg_match("/^[a-zA-Z0-9,-]+$/", $prefix) === 0) {
90-
throw new \InvalidArgumentException("\$prefix contains disallowed characters");
95+
throw new InvalidArgumentException("\$prefix contains disallowed characters");
9196
}
9297

9398
$this->config->setSidPrefix($prefix);
@@ -112,7 +117,7 @@ public function decode(string $data)
112117
$serializer = $this->config->getSerializeHandler();
113118
$this->currentSession->setContents($serializer->unserialize($data));
114119
return true;
115-
} catch (\Exception $e) {
120+
} catch (Throwable $e) {
116121
return false;
117122
}
118123
}
@@ -135,7 +140,7 @@ public function encode()
135140
try {
136141
$serializer = $this->config->getSerializeHandler();
137142
return $serializer->serialize($this->currentSession->toArray());
138-
} catch (\Exception $e) {
143+
} catch (Throwable $e) {
139144
return false;
140145
}
141146
}
@@ -321,7 +326,7 @@ public function start(): bool
321326
if (
322327
!$this->currentSession
323328
|| (
324-
$handler instanceof \SessionUpdateTimestampHandlerInterface
329+
$handler instanceof SessionUpdateTimestampHandlerInterface
325330
&& !$handler->validateId($this->currentSession->getId())
326331
)
327332
) {
@@ -427,7 +432,7 @@ public function write_close(): bool
427432
$handler->destroy($id);
428433
$handler->close();
429434
$this->currentSession->close();
430-
throw new \RuntimeException("Data serialization failure");
435+
throw new RuntimeException("Data serialization failure");
431436
return false;
432437
}
433438

0 commit comments

Comments
 (0)