Skip to content

Commit

Permalink
feat: add header to error source objects (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ennorehling authored Jan 23, 2025
1 parent 240d720 commit 31ea9a4
Showing 1 changed file with 47 additions and 3 deletions.
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

0 comments on commit 31ea9a4

Please sign in to comment.