mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
Updated some models with PHP 7 code
This commit is contained in:
parent
3fbd33f640
commit
0c3b716cf2
@ -18,9 +18,6 @@ interface ApiResponse
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Create an API response object from the HTTP response from the API server.
|
* Create an API response object from the HTTP response from the API server.
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return self
|
|
||||||
*/
|
*/
|
||||||
public static function create(array $data);
|
public static function create(array $data);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,11 @@ final class Attachment implements ApiResponse
|
|||||||
{
|
{
|
||||||
private $data;
|
private $data;
|
||||||
|
|
||||||
public static function create(array $data)
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function create(array $data): self
|
||||||
{
|
{
|
||||||
$new = new self();
|
$new = new self();
|
||||||
$new->data = $data;
|
$new->data = $data;
|
||||||
@ -28,7 +32,7 @@ final class Attachment implements ApiResponse
|
|||||||
return $new;
|
return $new;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getData()
|
public function getData(): array
|
||||||
{
|
{
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
@ -18,44 +18,21 @@ use Mailgun\Model\ApiResponse;
|
|||||||
*/
|
*/
|
||||||
abstract class AbstractDomainResponse implements ApiResponse
|
abstract class AbstractDomainResponse implements ApiResponse
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $message;
|
private $message;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Domain
|
|
||||||
*/
|
|
||||||
private $domain;
|
private $domain;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var DnsRecord[]
|
|
||||||
*/
|
|
||||||
private $inboundDnsRecords;
|
private $inboundDnsRecords;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var DnsRecord[]
|
|
||||||
*/
|
|
||||||
private $outboundDnsRecords;
|
private $outboundDnsRecords;
|
||||||
|
|
||||||
/**
|
public static function create(array $data): self
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public static function create(array $data)
|
|
||||||
{
|
{
|
||||||
$rx = [];
|
$rx = [];
|
||||||
$tx = [];
|
$tx = [];
|
||||||
$domain = null;
|
$domain = null;
|
||||||
$message = null;
|
|
||||||
|
|
||||||
if (isset($data['domain'])) {
|
if (isset($data['domain'])) {
|
||||||
$domain = Domain::create($data['domain']);
|
$domain = Domain::create($data['domain']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($data['message'])) {
|
|
||||||
$message = $data['message'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data['receiving_dns_records'])) {
|
if (isset($data['receiving_dns_records'])) {
|
||||||
foreach ($data['receiving_dns_records'] as $item) {
|
foreach ($data['receiving_dns_records'] as $item) {
|
||||||
$rx[] = DnsRecord::create($item);
|
$rx[] = DnsRecord::create($item);
|
||||||
@ -68,50 +45,41 @@ abstract class AbstractDomainResponse implements ApiResponse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new static($domain, $rx, $tx, $message);
|
$model = new static();
|
||||||
|
$model->domain = $domain;
|
||||||
|
$model->inboundDnsRecords = $rx;
|
||||||
|
$model->outboundDnsRecords = $tx;
|
||||||
|
$model->message = $data['message'] ?? null;
|
||||||
|
|
||||||
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function __construct()
|
||||||
* @param DnsRecord[] $rxRecords
|
|
||||||
* @param DnsRecord[] $txRecords
|
|
||||||
* @param string $message
|
|
||||||
*/
|
|
||||||
private function __construct(Domain $domainInfo, array $rxRecords, array $txRecords, $message)
|
|
||||||
{
|
{
|
||||||
$this->domain = $domainInfo;
|
|
||||||
$this->inboundDnsRecords = $rxRecords;
|
|
||||||
$this->outboundDnsRecords = $txRecords;
|
|
||||||
$this->message = $message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getDomain(): ?Domain
|
||||||
* @return Domain
|
|
||||||
*/
|
|
||||||
public function getDomain()
|
|
||||||
{
|
{
|
||||||
return $this->domain;
|
return $this->domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return DnsRecord[]
|
* @return DnsRecord[] tx
|
||||||
*/
|
*/
|
||||||
public function getInboundDNSRecords()
|
public function getInboundDNSRecords(): array
|
||||||
{
|
{
|
||||||
return $this->inboundDnsRecords;
|
return $this->inboundDnsRecords;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return DnsRecord[]
|
* @return DnsRecord[] tx
|
||||||
*/
|
*/
|
||||||
public function getOutboundDNSRecords()
|
public function getOutboundDNSRecords(): array
|
||||||
{
|
{
|
||||||
return $this->outboundDnsRecords;
|
return $this->outboundDnsRecords;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getMessage(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getMessage()
|
|
||||||
{
|
{
|
||||||
return $this->message;
|
return $this->message;
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,7 @@ use Mailgun\Model\ApiResponse;
|
|||||||
*/
|
*/
|
||||||
final class ConnectionResponse implements ApiResponse
|
final class ConnectionResponse implements ApiResponse
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $noVerify;
|
private $noVerify;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $requireTLS;
|
private $requireTLS;
|
||||||
|
|
||||||
public static function create(array $data): ?self
|
public static function create(array $data): ?self
|
||||||
@ -35,34 +28,31 @@ final class ConnectionResponse implements ApiResponse
|
|||||||
}
|
}
|
||||||
$connSettings = $data['connection'];
|
$connSettings = $data['connection'];
|
||||||
|
|
||||||
return new self(
|
$model = new self();
|
||||||
isset($connSettings['skip_verification']) ? $connSettings['skip_verification'] : null,
|
$model->noVerify = $connSettings['skip_verification'] ?? null;
|
||||||
isset($connSettings['require_tls']) ? $connSettings['require_tls'] : null
|
$model->requireTLS = $connSettings['require_tls'] ?? null;
|
||||||
);
|
|
||||||
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function __construct()
|
||||||
* @param bool $noVerify Disable remote TLS certificate verification
|
|
||||||
* @param bool $requireTLS Requires TLS for all outbound communication
|
|
||||||
*/
|
|
||||||
private function __construct($noVerify, $requireTLS)
|
|
||||||
{
|
{
|
||||||
$this->noVerify = $noVerify;
|
|
||||||
$this->requireTLS = $requireTLS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Disable remote TLS certificate verification.
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getSkipVerification()
|
public function getSkipVerification(): ?bool
|
||||||
{
|
{
|
||||||
return $this->noVerify;
|
return $this->noVerify;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Requires TLS for all outbound communication.
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getRequireTLS()
|
public function getRequireTLS(): ?bool
|
||||||
{
|
{
|
||||||
return $this->requireTLS;
|
return $this->requireTLS;
|
||||||
}
|
}
|
||||||
|
@ -18,31 +18,21 @@ use Mailgun\Model\ApiResponse;
|
|||||||
*/
|
*/
|
||||||
final class CreateCredentialResponse implements ApiResponse
|
final class CreateCredentialResponse implements ApiResponse
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $message;
|
private $message;
|
||||||
|
|
||||||
/**
|
private function __construct()
|
||||||
* @param string $message
|
|
||||||
*/
|
|
||||||
private function __construct($message)
|
|
||||||
{
|
{
|
||||||
$this->message = $message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function create(array $data): self
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public static function create(array $data)
|
|
||||||
{
|
{
|
||||||
return new self(isset($data['message']) ? $data['message'] : null);
|
$model = new self();
|
||||||
|
$model->message = $data['message'] ?? null;
|
||||||
|
|
||||||
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getMessage(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getMessage()
|
|
||||||
{
|
{
|
||||||
return $this->message;
|
return $this->message;
|
||||||
}
|
}
|
||||||
|
@ -18,20 +18,10 @@ use Mailgun\Model\ApiResponse;
|
|||||||
*/
|
*/
|
||||||
final class CredentialResponse implements ApiResponse
|
final class CredentialResponse implements ApiResponse
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $totalCount;
|
private $totalCount;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var CredentialResponseItem[]
|
|
||||||
*/
|
|
||||||
private $items;
|
private $items;
|
||||||
|
|
||||||
/**
|
public static function create(array $data): self
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public static function create(array $data)
|
|
||||||
{
|
{
|
||||||
$items = [];
|
$items = [];
|
||||||
if (isset($data['items'])) {
|
if (isset($data['items'])) {
|
||||||
@ -41,28 +31,23 @@ final class CredentialResponse implements ApiResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($data['total_count'])) {
|
if (isset($data['total_count'])) {
|
||||||
$count = $data['total_count'];
|
$count = (int) $data['total_count'];
|
||||||
} else {
|
} else {
|
||||||
$count = count($items);
|
$count = count($items);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new self($count, $items);
|
$model = new self();
|
||||||
|
$model->totalCount = $count;
|
||||||
|
$model->items = $items;
|
||||||
|
|
||||||
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function __construct()
|
||||||
* @param int $totalCount
|
|
||||||
* @param CredentialResponseItem[] $items
|
|
||||||
*/
|
|
||||||
private function __construct($totalCount, array $items)
|
|
||||||
{
|
{
|
||||||
$this->totalCount = $totalCount;
|
|
||||||
$this->items = $items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getTotalCount(): int
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getTotalCount()
|
|
||||||
{
|
{
|
||||||
return $this->totalCount;
|
return $this->totalCount;
|
||||||
}
|
}
|
||||||
@ -70,7 +55,7 @@ final class CredentialResponse implements ApiResponse
|
|||||||
/**
|
/**
|
||||||
* @return CredentialResponseItem[]
|
* @return CredentialResponseItem[]
|
||||||
*/
|
*/
|
||||||
public function getCredentials()
|
public function getCredentials(): array
|
||||||
{
|
{
|
||||||
return $this->items;
|
return $this->items;
|
||||||
}
|
}
|
||||||
|
@ -16,80 +16,42 @@ namespace Mailgun\Model\Domain;
|
|||||||
*/
|
*/
|
||||||
final class CredentialResponseItem
|
final class CredentialResponseItem
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var int|null
|
|
||||||
*/
|
|
||||||
private $sizeBytes;
|
private $sizeBytes;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \DateTime
|
|
||||||
*/
|
|
||||||
private $createdAt;
|
private $createdAt;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $mailbox;
|
private $mailbox;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $login;
|
private $login;
|
||||||
|
|
||||||
/**
|
public static function create(array $data): self
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public static function create(array $data)
|
|
||||||
{
|
{
|
||||||
$sizeBytes = isset($data['size_bytes']) ? $data['size_bytes'] : null;
|
$model = new self();
|
||||||
$mailbox = isset($data['mailbox']) ? $data['mailbox'] : null;
|
$model->sizeBytes = $data['size_bytes'] ?? null;
|
||||||
$login = isset($data['login']) ? $data['login'] : null;
|
$model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null;
|
||||||
$createdAt = isset($data['created_at']) ? new \DateTime($data['created_at']) : null;
|
$model->mailbox = $data['mailbox'] ?? null;
|
||||||
|
$model->login = $data['login'] ?? null;
|
||||||
|
|
||||||
return new self($sizeBytes, $createdAt, $mailbox, $login);
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function __construct()
|
||||||
* @param int $sizeBytes
|
|
||||||
* @param string $mailbox
|
|
||||||
* @param string $login
|
|
||||||
*/
|
|
||||||
private function __construct($sizeBytes, \DateTime $createdAt, $mailbox, $login)
|
|
||||||
{
|
{
|
||||||
$this->sizeBytes = $sizeBytes;
|
|
||||||
$this->createdAt = $createdAt;
|
|
||||||
$this->mailbox = $mailbox;
|
|
||||||
$this->login = $login;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getSizeBytes(): ?int
|
||||||
* @return int|null
|
|
||||||
*/
|
|
||||||
public function getSizeBytes()
|
|
||||||
{
|
{
|
||||||
return $this->sizeBytes;
|
return $this->sizeBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getCreatedAt(): ?\DateTimeImmutable
|
||||||
* @return \DateTime
|
|
||||||
*/
|
|
||||||
public function getCreatedAt()
|
|
||||||
{
|
{
|
||||||
return $this->createdAt;
|
return $this->createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getMailbox(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getMailbox()
|
|
||||||
{
|
{
|
||||||
return $this->mailbox;
|
return $this->mailbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getLogin(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getLogin()
|
|
||||||
{
|
{
|
||||||
return $this->login;
|
return $this->login;
|
||||||
}
|
}
|
||||||
|
@ -18,65 +18,35 @@ use Mailgun\Model\ApiResponse;
|
|||||||
*/
|
*/
|
||||||
final class DeleteCredentialResponse implements ApiResponse
|
final class DeleteCredentialResponse implements ApiResponse
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $message;
|
private $message;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $error;
|
private $error;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $spec;
|
private $spec;
|
||||||
|
|
||||||
/**
|
private function __construct()
|
||||||
* @param string $message
|
|
||||||
* @param string $error
|
|
||||||
* @param string $spec
|
|
||||||
*/
|
|
||||||
private function __construct($message, $error, $spec)
|
|
||||||
{
|
{
|
||||||
$this->message = $message;
|
|
||||||
$this->error = $error;
|
|
||||||
$this->spec = $spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function create(array $data): self
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public static function create(array $data)
|
|
||||||
{
|
{
|
||||||
return new self(
|
$model = new self();
|
||||||
isset($data['message']) ? $data['message'] : null,
|
$model->message = $data['message'] ?? null;
|
||||||
isset($data['error']) ? $data['error'] : null,
|
$model->error = $data['error'] ?? null;
|
||||||
isset($data['spec']) ? $data['spec'] : null
|
$model->spec = $data['spec'] ?? null;
|
||||||
);
|
|
||||||
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getMessage(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getMessage()
|
|
||||||
{
|
{
|
||||||
return $this->message;
|
return $this->message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getError(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getError()
|
|
||||||
{
|
{
|
||||||
return $this->error;
|
return $this->error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getSpec(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getSpec()
|
|
||||||
{
|
{
|
||||||
return $this->spec;
|
return $this->spec;
|
||||||
}
|
}
|
||||||
|
@ -18,49 +18,28 @@ use Mailgun\Model\ApiResponse;
|
|||||||
*/
|
*/
|
||||||
final class DeleteResponse implements ApiResponse
|
final class DeleteResponse implements ApiResponse
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $message;
|
private $message;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $error;
|
private $error;
|
||||||
|
|
||||||
/**
|
private function __construct()
|
||||||
* @param string $message
|
|
||||||
* @param string $error
|
|
||||||
*/
|
|
||||||
private function __construct($message, $error)
|
|
||||||
{
|
{
|
||||||
$this->message = $message;
|
|
||||||
$this->error = $error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function create(array $data): self
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public static function create(array $data)
|
|
||||||
{
|
{
|
||||||
return new self(
|
$model = new self();
|
||||||
isset($data['message']) ? $data['message'] : null,
|
$model->message = $data['message'] ?? null;
|
||||||
isset($data['error']) ? $data['error'] : null
|
$model->error = $data['error'] ?? null;
|
||||||
);
|
|
||||||
|
return $model;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getMessage(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getMessage()
|
|
||||||
{
|
{
|
||||||
return $this->message;
|
return $this->message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getError(): ?string
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getError()
|
|
||||||
{
|
{
|
||||||
return $this->error;
|
return $this->error;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user