Skip to content

Commit dce9624

Browse files
committed
PHP 8.0
1 parent bd579d4 commit dce9624

File tree

9 files changed

+45
-46
lines changed

9 files changed

+45
-46
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
## Requirements
55

6-
- PHP 7.4 or later
6+
- PHP 8.0 or later
77

88
**Note :** Adapters used may have different dependencies.
99

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
],
2020
"minimum-stability": "stable",
2121
"require": {
22-
"php": ">=7.4"
22+
"php": ">=8.0"
2323
}
2424
}

src/AbstractAdapter.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,41 @@ abstract class AbstractAdapter implements Interfaces\AdapterInterface
1919
/**
2020
* @inheritDoc
2121
*/
22-
public function close()
22+
public function close(): bool
2323
{
2424
return true;
2525
}
2626

2727
/**
2828
* @inheritDoc
2929
*/
30-
abstract public function destroy($id);
30+
abstract public function destroy(string $id): bool;
3131

3232
/**
3333
* @inheritDoc
3434
*/
35-
public function gc($max_lifetime)
35+
public function gc(int $max_lifetime): int|false
3636
{
37-
return true;
37+
return $max_lifetime;
3838
}
3939

4040
/**
4141
* @inheritDoc
4242
*/
43-
public function open($path, $name)
43+
public function open(string $path, string $name): bool
4444
{
4545
return true;
4646
}
4747

4848
/**
4949
* @inheritDoc
5050
*/
51-
abstract public function read($id);
51+
abstract public function read(string $id): string|false;
5252

5353
/**
5454
* @inheritDoc
5555
*/
56-
abstract public function write($id, $data);
56+
abstract public function write(string $id, string $data): bool;
5757

5858

5959
}

src/Adapters/CookieAdapter.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,26 @@ public function __construct(array $options)
5959
/**
6060
* @inheritDoc
6161
*/
62-
public function destroy($id)
62+
public function destroy(string $id): bool
6363
{
64-
setcookie($this->name, '', (time() - 86400));
64+
return setcookie($this->name, '', (time() - 86400)) !== false;
6565
}
6666

6767
/**
6868
* @inheritDoc
6969
*/
70-
public function gc($max_lifetime)
70+
public function gc(int $max_lifetime): int|false
7171
{
72-
if (!is_int($max_lifetime) || $max_lifetime < 0) {
73-
throw new SessionException();
74-
}
7572
if ($this->ttl != $max_lifetime) {
7673
$this->ttl = $max_lifetime;
7774
}
78-
return true;
75+
return $max_lifetime;
7976
}
8077

8178
/**
8279
* @inheritDoc
8380
*/
84-
public function read($id)
81+
public function read(string $id): string|false
8582
{
8683
if(!isset($this->data)){
8784
$this->_decode();
@@ -92,11 +89,11 @@ public function read($id)
9289
/**
9390
* @inheritDoc
9491
*/
95-
public function write($id, $data)
92+
public function write(string $id, string $data): bool
9693
{
9794
$this->data = $data;
9895
$value = base64_encode($this->encrypt->encrypt($data));
99-
return setcookie($this->name, $value, (time() + $this->ttl));
96+
return setcookie($this->name, $value, (time() + $this->ttl)) !== false;
10097
}
10198

10299
private function _decode(): void

src/Adapters/FileAdapter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ public function __construct(array $options)
3434
}
3535

3636

37-
public function read($id)
37+
public function read(string $id): string|false
3838
{
3939
$id = $this->prefix . $id;
4040

4141
return (string) @file_get_contents("{$this->path}/$id");
4242
}
4343

44-
public function write($id, $data)
44+
public function write(string $id, string $data): bool
4545
{
4646
$id = $this->prefix . $id;
4747

4848
return file_put_contents("{$this->path}/$id", $data) !== false;
4949
}
5050

51-
public function destroy($id)
51+
public function destroy(string $id): bool
5252
{
5353
$id = $this->prefix . $id;
5454

@@ -60,7 +60,7 @@ public function destroy($id)
6060
return true;
6161
}
6262

63-
public function gc($max_lifetime)
63+
public function gc(int $max_lifetime): int|false
6464
{
6565
$files = glob("{$this->path}/{$this->prefix}*");
6666
$currentTime = time();
@@ -71,7 +71,7 @@ public function gc($max_lifetime)
7171
}
7272
}
7373

74-
return true;
74+
return $max_lifetime;
7575
}
7676

7777
}

src/Adapters/MemCacheAdapter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ public function __destruct()
7878
/**
7979
* @inheritDoc
8080
*/
81-
public function destroy($id)
81+
public function destroy(string $id): bool
8282
{
8383
try {
8484
$session = $this->credentials['prefix'] . $id;
8585

86-
return $this->getMemcache()->delete($session) !== FALSE;
86+
return $this->getMemcache()->delete($session) !== false;
8787
} catch (\Exception $e) {
8888
return false;
8989
}
@@ -92,7 +92,7 @@ public function destroy($id)
9292
/**
9393
* @inheritDoc
9494
*/
95-
public function read($id)
95+
public function read(string $id): string|false
9696
{
9797
try {
9898
$session = $this->credentials['prefix'] . $id;
@@ -114,7 +114,7 @@ public function read($id)
114114
/**
115115
* @inheritDoc
116116
*/
117-
public function write($id, $data)
117+
public function write(string $id, string $data): bool
118118
{
119119
try {
120120
$session = $this->credentials['prefix'] . $id;
@@ -129,7 +129,7 @@ public function write($id, $data)
129129
default:
130130
$res = false;
131131
}
132-
return $res;
132+
return $res !== false;
133133
} catch (\Exception $e) {
134134
return false;
135135
}

src/Adapters/MongoDBAdapter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(array $options)
4747
/**
4848
* @inheritDoc
4949
*/
50-
public function destroy($id)
50+
public function destroy(string $id): bool
5151
{
5252
try {
5353
$bulkWrite = new \MongoDB\Driver\BulkWrite();
@@ -65,7 +65,7 @@ public function destroy($id)
6565
/**
6666
* @inheritDoc
6767
*/
68-
public function read($id)
68+
public function read(string $id): string|false
6969
{
7070
try {
7171
$query = new \MongoDB\Driver\Query(['_id' => $id]);
@@ -84,7 +84,7 @@ public function read($id)
8484
/**
8585
* @inheritDoc
8686
*/
87-
public function write($id, $data)
87+
public function write(string $id, string $data): bool
8888
{
8989
try {
9090
$bulkWrite = new \MongoDB\Driver\BulkWrite();
@@ -95,7 +95,7 @@ public function write($id, $data)
9595

9696
unset($bulkWrite);
9797

98-
return $res->isAcknowledged() !== FALSE;
98+
return $res->isAcknowledged() !== false;
9999
} catch (\Exception $e) {
100100
return false;
101101
}

src/Adapters/PDOAdapter.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(array $options)
5151
/**
5252
* @inheritDoc
5353
*/
54-
public function destroy($id)
54+
public function destroy(string $id): bool
5555
{
5656
try {
5757
$arguments = [
@@ -64,7 +64,7 @@ public function destroy($id)
6464
}
6565

6666
$stmt = $this->query($sql, $arguments);
67-
return $stmt !== FALSE && $stmt->rowCount() > 0;
67+
return $stmt !== false && $stmt->rowCount() > 0;
6868
} catch (\Exception $e) {
6969
return false;
7070
}
@@ -73,7 +73,7 @@ public function destroy($id)
7373
/**
7474
* @inheritDoc
7575
*/
76-
public function read($id)
76+
public function read(string $id): string|false
7777
{
7878
try {
7979
$arguments = [
@@ -86,7 +86,7 @@ public function read($id)
8686
}
8787
$sql .= " LIMIT 0, 1";
8888
$stmt = $this->query($sql, $arguments);
89-
if ($stmt === FALSE) {
89+
if ($stmt === false) {
9090
return false;
9191
}
9292
if ($stmt->rowCount() < 1) {
@@ -102,7 +102,7 @@ public function read($id)
102102
/**
103103
* @inheritDoc
104104
*/
105-
public function write($id, $data)
105+
public function write(string $id, string $data): bool
106106
{
107107
try {
108108
$stmt = $this->query("REPLACE INTO " . $this->table . " (id, sess_timestamp, sess_ip_address, sess_data) VALUES (:sess_id, :sess_data, :sess_timestamp, :ip_address);", [
@@ -112,13 +112,13 @@ public function write($id, $data)
112112
':ip_address' => $this->getIP(),
113113
]);
114114

115-
return $stmt !== FALSE && $stmt->rowCount() > 0;
115+
return $stmt !== false && $stmt->rowCount() > 0;
116116
} catch (\Exception $e) {
117117
return false;
118118
}
119119
}
120120

121-
private function query(string $query, ?array $arguments = null)
121+
private function query(string $query, ?array $arguments = null): bool|\PDOStatement
122122
{
123123
$stmt = $this->pdo->prepare($query);
124124
if ($stmt === FALSE) {

src/Adapters/RedisAdapter.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public function __construct(array $options)
7373
/**
7474
* @inheritDoc
7575
*/
76-
public function destroy($id)
76+
public function destroy(string $id): bool
7777
{
7878
try {
79-
return $this->redis->del($this->prefix . $id) !== FALSE;
79+
return $this->redis->del($this->prefix . $id) !== false;
8080
} catch (\Exception $e) {
8181
return false;
8282
}
@@ -85,10 +85,12 @@ public function destroy($id)
8585
/**
8686
* @inheritDoc
8787
*/
88-
public function read($id)
88+
public function read(string $id): string|false
8989
{
9090
try {
91-
return (string)$this->redis->get($this->prefix . $id);
91+
$data = $this->redis->get($this->prefix . $id);
92+
93+
return $data !== false ? (string)$data : false;
9294
} catch (\Exception $e) {
9395
return false;
9496
}
@@ -97,11 +99,11 @@ public function read($id)
9799
/**
98100
* @inheritDoc
99101
*/
100-
public function write($id, $data)
102+
public function write(string $id, string $data): bool
101103
{
102104
try {
103105
$set = $this->redis->set($this->prefix . $id, $data);
104-
if($set === FALSE){
106+
if($set === false){
105107
return false;
106108
}
107109
$this->redis->expireAt($this->prefix . $id, time() + $this->ttl);

0 commit comments

Comments
 (0)