<?php
use GoPay\Token\TokenCache;
use GoPay\Token\AccessToken;
class PrimitiveFileCache extends TokenCache
{
private $file;
public function setClient($client)
{
$this->file = __DIR__ . "/{$client}";
}
public function setAccessToken(AccessToken $t)
{
file_put_contents($this->file, serialize($t);
}
public function getAccessToken()
{
if (file_exists($this->file)) {
return unserialize(file_get_contents($this->file));
}
return $this->getExpiredToken();
}
}
<?php
use GoPay\Token\TokenCache;
use GoPay\Token\AccessToken;
class PrimitiveFileCache implements TokenCache
{
private $file;
private function setClient($client)
{
$this->file = __DIR__ . "/{$client}";
}
public function setAccessToken($client, AccessToken $t)
{
$this->setClient($client);
file_put_contents($this->file, serialize($t);
}
public function getAccessToken($client)
{
$this->setClient($client);
if (file_exists($this->file)) {
return unserialize(file_get_contents($this->file));
}
return null;
}
}