<?php
namespace Claromentis\OAuth2\Repository;

$GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"] = (@$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] ?: array()) + array("_661508d434610106e6e325" . "c064c270e2" => base64_decode("c3RyOnJlZnJlc2" . "hfdG9rZW4="), "_15794357755c" . "c86f29fecc2f6" . "933f38a" => base64_decode("REVMRVRFIEZST00gb2F1dGhf" . "cmVmcmVzaF90b2tlbnMgV0hF" . "UkUgcmVmcmVzaF90b2tlbiBl" . "cTpzdHI6dG9rZW4="), "_8f808ca4543071730b22e8e23ab557" . "3a" => base64_decode("cmVmcmVzaF90b2" . "tlbg=="), "_dbc3558" . "7eab0281" . "2e4e3557" . "29e4f1e7" . "e" => base64_decode("c3RyOmFjY2" . "Vzc190b2tl" . "bg=="), "_9bc1e8c60888" . "a0c746682a510" . "e002b63" => base64_decode("aW50OmV" . "4cGlyZV" . "90aW1l"), "_679dde0044d5" . "ff3c8914e903b" . "96a6902" => base64_decode("b2F1dGhfcmVmcmVzaF90b2tlbnM" . "="), "_109785f0f72f048348651959b176a" . "2ff" => base64_decode("U0VMRUNUIDEgRlJPTSBvYXV0aF9yZWZy" . "ZXNoX3Rva2VucyBXSEVSRSByZWZyZXNo" . "X3Rva2VuIGVxOnN0cjp0b2tlbg=="), "_5f26551b0a4ad11d3a754" . "955377fd25f" => base64_decode("U0VMRUNUIHJlZnJlc2hfdG9rZW4gRlJPT" . "SBvYXV0aF9yZWZyZXNoX3Rva2VucyBXSE" . "VSRSBleHBpcmVfdGltZSA8IGludDp0aW1" . "lc3RhbXA="));
use Claromentis\Core\DAL;
use Claromentis\OAuth2\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface;
use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException;
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
class RefreshTokenRepository implements RefreshTokenRepositoryInterface
{
    
    
    protected $db;
    public function __construct(DAL\Db $db)
    {
        $this->db = $db;
    }
    
    
    
    
    
    
    public function getNewRefreshToken()
    {
        return new RefreshTokenEntity();
    }
    
    
    
    
    
    
    
    
    public function persistNewRefreshToken(RefreshTokenEntityInterface $_de11b1efcf002e5233e57c1138428bfd)
    {
        $_49ee1e842dca787e7c39f02341effb25 = new \Date($_de11b1efcf002e5233e57c1138428bfd->getExpiryDateTime());
        $data = [$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_661508d434610106e6e325c064c" . "270e2"] => $_de11b1efcf002e5233e57c1138428bfd->getIdentifier(), $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_dbc3558" . "7eab0281" . "2e4e3557" . "29e4f1e7" . "e"] => $_de11b1efcf002e5233e57c1138428bfd->getAccessToken()->getIdentifier(), $GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_9bc1e8c60888a" . "0c746682a510e0" . "02b63"] => $_49ee1e842dca787e7c39f02341effb25->getDate(DATE_FORMAT_UNIXTIME)];
        $this->db->unsafe_query = true;
        $this->db->query(new DAL\QueryInsert($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_679dde0044d5ff3c8914e903b96a" . "6902"], $data));
    }
    
    
    
    
    
    
    public function revokeRefreshToken($_57ef2eaf1b26ea90c284b644aeea25db)
    {
        $this->db->unsafe_query = true;
        $this->db->query($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_15794357755cc86f29fecc2f6933" . "f38a"], $_57ef2eaf1b26ea90c284b644aeea25db);
    }
    
    
    
    
    public function removeOldRefreshTokens()
    {
        $_c8b38c7133c2e8460c1cca42230ac6c2 = new \Date();
        $_97ea09a7faf27c52c6eff69773df1d8a = $_c8b38c7133c2e8460c1cca42230ac6c2->getDate(DATE_FORMAT_UNIXTIME);
        $_189840d11056515e52402d1412a0b6e4 = $this->db->query($GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_5f26551b0" . "a4ad11d3a7" . "54955377fd" . "25f"], $_97ea09a7faf27c52c6eff69773df1d8a);
        while ($_343a395319323dd7609bcbc465b4d034 = $_189840d11056515e52402d1412a0b6e4->fetchArray()) {
            $this->revokeRefreshToken($_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_8f808ca45" . "43071730b2" . "2e8e23ab55" . "73a"]]);
        }
    }
    
    
    
    
    
    
    
    
    public function isRefreshTokenRevoked($_57ef2eaf1b26ea90c284b644aeea25db)
    {
        $this->removeOldRefreshTokens();
        $_189840d11056515e52402d1412a0b6e4 = $this->db->query($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_109785f0f72f048348651959b176a2f" . "f"], $_57ef2eaf1b26ea90c284b644aeea25db);
        return $_189840d11056515e52402d1412a0b6e4->numRows() === 0;
    }
}