68 lines
1.5 KiB
PHP
68 lines
1.5 KiB
PHP
<?php
|
|
namespace Stemcell\Customer\Model\Data;
|
|
|
|
use Stemcell\Customer\Api\Data\Http;
|
|
use Magento\Framework\DataObject;
|
|
use Magento\Framework\Serialize\Serializer\Json;
|
|
use Magento\Setup\Module\I18n\Dictionary\Phrase;
|
|
|
|
class JsonResponse extends DataObject implements Http\JsonResponse
|
|
{
|
|
protected bool $errors = false;
|
|
|
|
protected array $message = [];
|
|
|
|
protected Json $jsonSerializer;
|
|
|
|
public function __construct(
|
|
Json $jsonSerializer,
|
|
array $data = []
|
|
) {
|
|
$this->jsonSerializer = $jsonSerializer;
|
|
parent::__construct($data);
|
|
}
|
|
|
|
public function setErrors(bool $status = false): self
|
|
{
|
|
$this->errors = $status;
|
|
return $this;
|
|
}
|
|
|
|
public function setMessages(array $message): self
|
|
{
|
|
$this->message = array_merge($this->message, $message);
|
|
return $this;
|
|
}
|
|
|
|
public function setData($key, $value = null): self
|
|
{
|
|
if (is_array($key)) {
|
|
$this->_data = array_merge($this->_data, $key);
|
|
} else {
|
|
parent::setData($key, $value);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function toArray(array $keys = []): array
|
|
{
|
|
return [
|
|
'error' => $this->errors,
|
|
'message' =>array_values($this->message),
|
|
'data' => $this->_data
|
|
];
|
|
}
|
|
|
|
|
|
public function getErrors(): bool
|
|
{
|
|
return $this->errors;
|
|
}
|
|
|
|
public function getMessages(): array
|
|
{
|
|
return $this->message;
|
|
}
|
|
}
|