<?php
 use PHPMailer\PHPMailer\OAuth; use League\OAuth2\Client\Token\AccessToken; class vB_Mail_Transport_PhpMailer_CachingOauth extends OAuth { use vB_Trait_NoSerialize; private $cachekey; public function __construct($options, $cachekey) { parent::__construct($options); $this->cachekey = $cachekey; $this->fetchCachedToken(); } protected function getToken() { $token = parent::getToken(); $this->cacheToken($token); return $token; } protected function cacheToken($token) { vB_Cache::instance(vB_Cache::CACHE_STD)->write($this->cachekey, $token->jsonSerialize(), $token->getExpires() - time()); } protected function fetchCachedToken() { $value = vB_Cache::instance(vB_Cache::CACHE_STD)->read($this->cachekey); if ($value) { $this->oauthToken = new AccessToken($value); } } } 