'There was a validation error', self::TYPE_INVALID_REQUEST_BODY_FORMAT => 'Invalid JSON format sent', self::TYPE_LOGICAL_ERROR => 'Invalid request due to a logic error', self::TYPE_SERVER_ERROR => 'Error on server side', self::TYPE_INVALID_DATE => 'Invalid date on request', self::TYPE_API_LIMIT => 'Reached API Limit' ); private int $statusCode; private string $type; private string $title; private array $extraData = array(); public function __construct($statusCode, $type = null) { if ($type === null) { // no type? The default is about:blank and the title should // be the standard status code message $type = 'about:blank'; $title = isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : 'Unknown status code :('; } else { if (!isset(self::$titles[$type])) { throw new \InvalidArgumentException('No title for type ' . $type); } $title = self::$titles[$type]; } $this->statusCode = $statusCode; $this->type = $type; $this->title = $title; } public function getStatusCode(): int { return $this->statusCode; } public function getTitle(): string { return $this->title; } public function setExtraData($name, $value) { $this->extraData[$name] = $value; } public function setDetails($value) { $this->extraData['details'] = $value; } public function toArray(): array { return array_merge( $this->extraData, array( 'status' => $this->statusCode, 'type' => $this->type, 'title' => $this->title, ) ); } }