Skip to content

Commit b113eda

Browse files
committed
Updated serialzation strategy
1 parent 278032d commit b113eda

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

src/Persistence/FileTokenPersistence.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function restoreToken(TokenInterface $token)
2727
return null;
2828
}
2929

30-
$data = json_decode(file_get_contents($this->filepath), true);
30+
$data = @json_decode(file_get_contents($this->filepath), true);
3131

3232
if (false === $data) {
3333
return null;
@@ -39,7 +39,7 @@ public function restoreToken(TokenInterface $token)
3939
public function deleteToken()
4040
{
4141
if (file_exists($this->filepath)) {
42-
unlink($this->filepath);
42+
@unlink($this->filepath);
4343
}
4444
}
4545
}

src/Token/RawToken.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace kamermans\OAuth2\Token;
44

5-
class RawToken implements \Serializable, TokenInterface
5+
class RawToken implements Serializable, TokenInterface
66
{
77
// Pull in serialize() and unserialize() methods
88
use TokenSerializer;

src/Token/Serializable.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace kamermans\OAuth2\Token;
4+
5+
interface Serializable
6+
{
7+
/**
8+
* Serialize object.
9+
*
10+
* @return array
11+
*/
12+
public function serialize();
13+
/**
14+
* Unserialize object.
15+
*
16+
* @param array $data
17+
*/
18+
public function unserialize(array $data);
19+
}

src/Token/TokenSerializer.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ trait TokenSerializer
3131
*/
3232
public function serialize()
3333
{
34-
return serialize([
34+
return [
3535
'access_token' => $this->accessToken,
3636
'refresh_token' => $this->refreshToken,
3737
'expires_at' => $this->expiresAt,
38-
]);
38+
];
3939
}
4040

4141
/**
@@ -44,8 +44,7 @@ public function serialize()
4444
*/
4545
public function unserialize($data)
4646
{
47-
$data = unserialize($data);
48-
if (!is_array($data) || !isset($data['access_token'])) {
47+
if (!isset($data['access_token'])) {
4948
throw new \InvalidArgumentException('Unable to create a RawToken without an "access_token"');
5049
}
5150

0 commit comments

Comments
 (0)