Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error objects: source objects may refer to a header #24

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions src/Core/Document/ErrorSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class ErrorSource implements Serializable
*/
private ?string $parameter;

/**
* @var string|null
*/
private ?string $header;

/**
* @param ErrorSource|array|null $value
* @return ErrorSource
Expand Down Expand Up @@ -60,7 +65,8 @@ public static function fromArray(array $source): self
{
return new self(
$source['pointer'] ?? null,
$source['parameter'] ?? null
$source['parameter'] ?? null,
$source['header'] ?? null,
);
}

Expand All @@ -69,11 +75,13 @@ public static function fromArray(array $source): self
*
* @param string|null $pointer
* @param string|null $parameter
* @param string|null $header
*/
public function __construct(?string $pointer = null, ?string $parameter = null)
public function __construct(?string $pointer = null, ?string $parameter = null, ?string $header = null)
{
$this->pointer = $pointer;
$this->parameter = $parameter;
$this->header = $header;
}

/**
Expand Down Expand Up @@ -149,12 +157,47 @@ public function withoutParameter(): self
return $this;
}

/**
* A string indicating which request header caused the error.
*
* @return string|null
*/
public function header(): ?string
{
return $this->header;
}

/**
* Add a string indicating which request header caused the error.
*
* @param string|null $header
* @return $this
*/
public function setHeader(?string $header): self
{
$this->header = $header;

return $this;
}

/**
* Remove the source header.
*
* @return $this
*/
public function withoutHeader(): self
{
$this->header = null;

return $this;
}

/**
* @return bool
*/
public function isEmpty(): bool
{
return empty($this->pointer) && empty($this->parameter);
return empty($this->pointer) && empty($this->parameter) && empty($this->header);
}

/**
Expand All @@ -173,6 +216,7 @@ public function toArray()
return array_filter([
'parameter' => $this->parameter,
'pointer' => $this->pointer,
'header' => $this->header,
]);
}

Expand Down
Loading