| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Facile\OpenIDClient\Session; |
| 6 |
|
| 7 |
use Override; |
| 8 |
|
| 9 |
use function array_filter; |
| 10 |
|
| 11 |
final class AuthSession implements AuthSessionInterface |
| 12 |
{ |
| 13 |
private ?string $state = null; |
| 14 |
|
| 15 |
private ?string $nonce = null; |
| 16 |
|
| 17 |
private ?string $codeVerifier = null; |
| 18 |
|
| 19 |
|
| 20 |
private array $customs = []; |
| 21 |
|
| 22 |
#[Override] |
| 23 |
public function getState(): ?string |
| 24 |
{ |
| 25 |
return $this->state; |
| 26 |
} |
| 27 |
|
| 28 |
#[Override] |
| 29 |
public function getNonce(): ?string |
| 30 |
{ |
| 31 |
return $this->nonce; |
| 32 |
} |
| 33 |
|
| 34 |
#[Override] |
| 35 |
public function getCodeVerifier(): ?string |
| 36 |
{ |
| 37 |
return $this->codeVerifier; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
#[Override] |
| 44 |
public function getCustoms(): array |
| 45 |
{ |
| 46 |
return $this->customs; |
| 47 |
} |
| 48 |
|
| 49 |
#[Override] |
| 50 |
public function setState(?string $state): void |
| 51 |
{ |
| 52 |
$this->state = $state; |
| 53 |
} |
| 54 |
|
| 55 |
#[Override] |
| 56 |
public function setNonce(?string $nonce): void |
| 57 |
{ |
| 58 |
$this->nonce = $nonce; |
| 59 |
} |
| 60 |
|
| 61 |
#[Override] |
| 62 |
public function setCodeVerifier(?string $codeVerifier): void |
| 63 |
{ |
| 64 |
$this->codeVerifier = $codeVerifier; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
#[Override] |
| 71 |
public function setCustoms(array $customs): void |
| 72 |
{ |
| 73 |
$this->customs = $customs; |
| 74 |
} |
| 75 |
|
| 76 |
#[Override] |
| 77 |
public static function fromArray(array $array): AuthSessionInterface |
| 78 |
{ |
| 79 |
$session = new static(); |
| 80 |
$session->setState($array['state'] ?? null); |
| 81 |
$session->setNonce($array['nonce'] ?? null); |
| 82 |
$session->setCodeVerifier($array['code_verifier'] ?? null); |
| 83 |
$session->setCustoms($array['customs'] ?? []); |
| 84 |
|
| 85 |
return $session; |
| 86 |
} |
| 87 |
|
| 88 |
#[Override] |
| 89 |
public function jsonSerialize(): array |
| 90 |
{ |
| 91 |
return array_filter([ |
| 92 |
'state' => $this->getState(), |
| 93 |
'nonce' => $this->getNonce(), |
| 94 |
'code_verifier' => $this->getCodeVerifier(), |
| 95 |
'customs' => $this->getCustoms(), |
| 96 |
]); |
| 97 |
} |
| 98 |
} |