<?php
|
namespace JVBase\registrar\config;
|
|
use JVBase\registrar\Registrar;
|
use JVBase\utility\Features;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
|
final class Integration extends Config{
|
/**
|
* @var string Must match as defined in the JVBase\integrations namespace
|
*/
|
protected string $service_name;
|
protected string $content_type;
|
/**
|
* @var bool Whether to send to the integration on publish
|
*/
|
protected bool $initial;
|
/**
|
* @var bool Whether to sync changes with the service
|
*/
|
protected bool $update;
|
protected bool $canSchedule;
|
/**
|
* @var bool whether this is a customer role, used if this is a user-based Registrar
|
*/
|
protected bool $isCustomer;
|
|
|
|
public function __construct(string $service) {
|
if (!Features::hasIntegration($service)) {
|
error_log('Could not link with integration, as it is not enabled: '.$service);
|
return;
|
}
|
$this->service_name = $service;
|
}
|
|
public function getService_name():string
|
{
|
return $this->service_name;
|
}
|
|
/**
|
* @param string $content must match what integration expects
|
* @return self
|
*/
|
public function setContent_type(string $content):self
|
{
|
$allowed = JVB()->connect($this->service_name)->allowedContent();
|
if (!in_array($content, $allowed)) {
|
error_log($this->service_name.' Connection does not support this content: '.$content);
|
return $this;
|
}
|
$this->content_type = $content;
|
return $this;
|
}
|
|
public function getContentType():string
|
{
|
return $this->content_type;
|
}
|
|
public function setInitial(bool $set):self
|
{
|
$this->initial = $set;
|
return $this;
|
}
|
public function getInitial():bool|null
|
{
|
return $this->initial??null;
|
}
|
|
public function setUpdate(bool $set):self
|
{
|
$this->update = $set;
|
return $this;
|
}
|
public function getUpdate():bool|null
|
{
|
return $this->update ?? null;
|
}
|
|
public function setCustomer(bool $set):self
|
{
|
$this->isCustomer = $set;
|
return $this;
|
}
|
public function isCustomer():bool
|
{
|
return $this->isCustomer??false;
|
}
|
|
|
public function setCanSchedule(bool $set):self
|
{
|
$this->canSchedule = $set;
|
return $this;
|
}
|
public function getCanSchedule():bool|null
|
{
|
return $this->canSchedule??null;
|
}
|
|
public function getConfig(): array
|
{
|
$config = [];
|
if (isset($this->content_type)) {
|
$config['content_type'] = $this->content_type;
|
}
|
if (isset($this->initial)) {
|
$config['initial'] = $this->initial;
|
}
|
if (isset($this->update)) {
|
$config['update'] = $this->update;
|
}
|
|
return $config;
|
}
|
}
|