-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ongoing refactoring to use JsonApi Objects throughout codebase.
- Loading branch information
Showing
10 changed files
with
1,062 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,268 @@ | ||
<?php | ||
/** | ||
* Error.php | ||
* | ||
* Error class | ||
* | ||
* php 7.4+ | ||
* | ||
* @category None | ||
* @package Floor9design\JsonApiFormatter\Models | ||
* @author Rick Morice <rick@floor9design.com> | ||
* @copyright Floor9design Ltd | ||
* @license MIT | ||
* @version 1.0 | ||
* @link https://www.floor9design.com | ||
* @since File available since Release 1.0 | ||
* | ||
*/ | ||
|
||
namespace Floor9design\JsonApiFormatter\Models; | ||
|
||
/** | ||
* Class Error | ||
* | ||
* Class to offer methods/properties to prepare data for an Error | ||
* These are set to the v1.0 specification, defined at https://jsonapi.org/format/ | ||
* | ||
* @category None | ||
* @package Floor9design\JsonApiFormatter\Models | ||
* @author Rick Morice <rick@floor9design.com> | ||
* @copyright Floor9design Ltd | ||
* @license MIT | ||
* @version 1.0 | ||
* @link https://www.floor9design.com | ||
* @link https://jsonapi.org/ | ||
* @link https://jsonapi-validator.herokuapp.com/ | ||
* @since File available since Release 1.0 | ||
* @see https://jsonapi.org/format/ | ||
*/ | ||
class Error | ||
{ | ||
// Properties | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
var ?string $id = null; | ||
|
||
/** | ||
* @var Links|null | ||
*/ | ||
var ?Links $links = null; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
var ?string $status = null; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
var ?string $code = null; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
var ?string $title = null; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
var ?string $detail = null; | ||
|
||
/** | ||
* @var object|null | ||
*/ | ||
var ?object $source = null; | ||
|
||
// accessors | ||
|
||
/** | ||
* @return string|null | ||
* @see $id | ||
*/ | ||
public function getId(): ?string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @param string|null $id | ||
* @return Error | ||
* @see $id | ||
*/ | ||
public function setId(?string $id): Error | ||
{ | ||
$this->id = $id; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return Links|null | ||
* @see $links | ||
*/ | ||
public function getLinks(): ?Links | ||
{ | ||
return $this->links; | ||
} | ||
|
||
/** | ||
* @param Links|null $links | ||
* @return Error | ||
* @see $links | ||
*/ | ||
public function setLinks(?Links $links): Error | ||
{ | ||
$this->links = $links; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
* @see $status | ||
*/ | ||
public function getStatus(): ?string | ||
{ | ||
return $this->status; | ||
} | ||
|
||
/** | ||
* @param string|null $status | ||
* @return Error | ||
* @see $status | ||
*/ | ||
public function setStatus(?string $status): Error | ||
{ | ||
$this->status = $status; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
* @see $code | ||
*/ | ||
public function getCode(): ?string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
/** | ||
* @param string|null $code | ||
* @return Error | ||
* @see $code | ||
*/ | ||
public function setCode(?string $code): Error | ||
{ | ||
$this->code = $code; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
* @see $title | ||
*/ | ||
public function getTitle(): ?string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
/** | ||
* @param string|null $title | ||
* @return Error | ||
* @see $title | ||
*/ | ||
public function setTitle(?string $title): Error | ||
{ | ||
$this->title = $title; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
* @see $detail | ||
*/ | ||
public function getDetail(): ?string | ||
{ | ||
return $this->detail; | ||
} | ||
|
||
/** | ||
* @param string|null $detail | ||
* @return Error | ||
* @see $detail | ||
*/ | ||
public function setDetail(?string $detail): Error | ||
{ | ||
$this->detail = $detail; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return object|null | ||
* @see $source | ||
*/ | ||
public function getSource(): ?object | ||
{ | ||
return $this->source; | ||
} | ||
|
||
/** | ||
* @param object|null $source | ||
* @return Error | ||
* @see $source | ||
*/ | ||
public function setSource(?object $source): Error | ||
{ | ||
$this->source = $source; | ||
return $this; | ||
} | ||
|
||
// constructor | ||
|
||
/** | ||
* Error constructor. | ||
* @param string|null $id | ||
* @param Links|null $links | ||
* @param string|null $status | ||
* @param string|null $code | ||
* @param string|null $title | ||
* @param string|null $detail | ||
* @param string|null $source | ||
*/ | ||
public function __construct( | ||
?string $id = null, | ||
?Links $links = null, | ||
?string $status = null, | ||
?string $code = null, | ||
?string $title = null, | ||
?string $detail = null, | ||
?object $source = null | ||
) { | ||
$this | ||
->setId($id) | ||
->setLinks($links) | ||
->setStatus($status) | ||
->setCode($code) | ||
->setTitle($title) | ||
->setDetail($detail) | ||
->setSource($source); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'id' => $this->getId(), | ||
'links' => $this->getLinks(), | ||
'status' => $this->getStatus(), | ||
'code' => $this->getCode(), | ||
'title' => $this->getTitle(), | ||
'detail' => $this->getDetail(), | ||
'source' => $this->getSource(), | ||
]; | ||
} | ||
|
||
} |
Oops, something went wrong.