drawCounter = $drawCounter; $this->recordsTotal = $recordsTotal; $this->recordsFiltered = $recordsFiltered; $this->data = $data; } /** * @return array */ public function getResult() { $result = [ 'draw' => $this->drawCounter, 'recordsTotal' => $this->recordsTotal, 'recordsFiltered' => $this->recordsFiltered, 'data' => $this->data, ]; if ($this->debugInfo !== null) { $result['debug'] = $this->debugInfo; } if ($this->errorMessage !== null) { $result['error'] = $this->errorMessage; } return $result; } /** * @return int */ public function getDrawCounter() { return $this->drawCounter; } /** * @return int */ public function getRecordsTotal() { return $this->recordsTotal; } /** * @return int */ public function getRecordsFiltered() { return $this->recordsFiltered; } /** * @return array */ public function getData() { return $this->data; } /** * @return array|null */ public function getDebugInfo() { return $this->debugInfo; } /** * @param array $debugInfo */ public function setDebugInfo($debugInfo) { if (!is_array($debugInfo)) { throw new InvalidArgumentException(sprintf( 'Invalid argument. Debug information must be an array. Given type: %s', strtolower(gettype($debugInfo)) )); } $this->debugInfo = $debugInfo; } /** * @return bool */ public function hasError() { return $this->errorMessage !== null; } /** * @return string|null */ public function getErrorMessage() { return $this->errorMessage; } /** * @param string $errorMessage * * @throws InvalidArgumentException */ public function setErrorMessage($errorMessage) { if (!is_string($errorMessage)) { throw new InvalidArgumentException(sprintf( 'Invalid argument. Error message must be a string. Given type: %s', strtolower(gettype($errorMessage)) )); } $this->errorMessage = $errorMessage; } /** * @return array */ public function toArray() { return $this->getResult(); } /** * @return array */ public function jsonSerialize() { return $this->toArray(); } }