Jake Vanderwerf
2026-08-26 ccf5e61a075c35d24befc175994b5cb8957ca322
inc/integrations/_Base.php
@@ -2,6 +2,7 @@
namespace JVBase\integrations;
use JVBase\managers\Cache;
use JVBase\managers\Errors;
use JVBase\managers\IconsManager;
if (!defined('ABSPATH')) {
@@ -31,14 +32,7 @@
   protected string $apiVersion;
   protected Cache $cache;
   protected ?string $cacheName = null;
   //Use Trait "Requests" to set this
   protected bool $hasRequests = false;
   protected ?RateLimits $requestLimiter = null;
   //Use Trait "OAuth" to set this
   protected ?RateLimits $oauthLimiter = null;
   protected bool $hasOAuth = false;
   //Use trait "Webhooks" to set this true
   protected bool $hasWebhooks = false;
   /**
    * @var array Each item in the array becomes a li element in the ordered list of instructions
@@ -61,7 +55,7 @@
    * @var bool Flag to indicate there are extra options that warrant a dedicated options page for this service
    * Usually used for default field values for syncable services
    */
   public bool $hasExtraOptions = false;
   public static bool $hasExtraOptions = false;
   public bool $hasBatchCreate = false;
   public bool $hasBatchUpdate = false;
   public bool $hasBatchDelete = false;
@@ -93,6 +87,8 @@
    */
   protected array $contentTypes = [];
   protected array $credentials;
   /**
    * Check if integration is properly configured
@@ -104,13 +100,16 @@
   public function loadCredentials():array
   {
      return Auth::getInstance()->getCredentials($this->service_name, $this->userID);
      if (!isset($this->credentials)) {
         $this->credentials = Auth::getInstance()->getCredentials($this->service_name, $this->userID);
      }
      return $this->credentials;
   }
   protected function logError(string $method, string $message, array $context = []):void
   {
      $context['service'] = $this->service_name;
      JVB()->error()->log('['.self::class.']'.$method, $message, $context);
      Errors::getInstance()->log('['.self::class.']'.$method, $message, $context);
   }
   protected function getReturnURL():string
@@ -143,13 +142,11 @@
      if (!is_null($this->userID)) {
         $key .= '_'.$this->userID;
      }
      if ($this->hasRequests && !isset($this->requestLimiter) && !is_null($this->oauthLimiter)) {
         $this->requestLimiter = new RateLimits($key);
      if (method_exists($this, 'initializeRequestLimiter')) {
         $this->initializeRequestLimiter();
      }
      if ($this->hasOAuth && !isset($this->oauthLimiter) && !is_null($this->oauthLimiter)) {
         $key .= '_oauth';
         $this->oauthLimiter = new RateLimits($key, ['s' => 1,'m' => 10, 'h' => 100]);
      if (method_exists($this, 'initializeOAuthRateLimiter')) {
         $this->initializeOAuthRateLimiter();
      }
   }
@@ -164,4 +161,14 @@
      }
      return $response;
   }
   public function getAllowedContent():array
   {
      return array_keys($this->contentTypes);
   }
   public function getServiceName():string
   {
      return $this->service_name;
   }
}