<?php
namespace App\Service\CpanelApi;
class CpanelApiResponse implements \ArrayAccess, \Countable {
private array $response;
public function __construct($response_data)
{
$this->response = $response_data;
}
/**
* Return DATA part of response
*
* @return mixed
*/
public function getData(): mixed
{
return $this->response['data'];
}
/**
* Return STATUS part of response
*
* @return bool
*/
public function getStatus(): bool
{
return !empty($this->response['status']);
}
/**
* Return ERRORS part of response
*
* @return array
*/
public function getErrors(): array
{
return (array)$this->response['errors'];
}
/**
* Return MESSAGES part of response
*
* @return array
*/
public function getMessages(): array
{
return (array)$this->response['messages'];
}
public function offsetSet($offset, $value): void
{
if (is_null($offset)) {
$this->response['data'][] = $value;
} else {
$this->response['data'][$offset] = $value;
}
}
public function offsetExists($offset): bool
{
return isset($this->response['data'][$offset]);
}
public function offsetUnset($offset): void
{
unset($this->response['data'][$offset]);
}
public function offsetGet($offset): mixed
{
$data = $this->getData();
return $data[$offset] ?? null;
}
public function count(): int
{
return count($this->getData());
}
}