From 31ea9a4d14793c222db8956dcd4241e77af8043c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 23 Jan 2025 20:58:34 +0100 Subject: [PATCH 1/2] feat: add header to error source objects (#24) --- src/Core/Document/ErrorSource.php | 50 +++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/src/Core/Document/ErrorSource.php b/src/Core/Document/ErrorSource.php index 0b84555..13ae81c 100644 --- a/src/Core/Document/ErrorSource.php +++ b/src/Core/Document/ErrorSource.php @@ -31,6 +31,11 @@ class ErrorSource implements Serializable */ private ?string $parameter; + /** + * @var string|null + */ + private ?string $header; + /** * @param ErrorSource|array|null $value * @return ErrorSource @@ -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, ); } @@ -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; } /** @@ -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); } /** @@ -173,6 +216,7 @@ public function toArray() return array_filter([ 'parameter' => $this->parameter, 'pointer' => $this->pointer, + 'header' => $this->header, ]); } From 1a178fe221a234210909ef84bc9a4128af194cc5 Mon Sep 17 00:00:00 2001 From: Christopher Gammie Date: Thu, 23 Jan 2025 20:01:30 +0000 Subject: [PATCH 2/2] docs: update changelog and bump version --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9296587..ddbe220 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. This projec ## Unreleased +## [5.1.0] - 2025-01-23 + +### Added + +- [#24](https://github.com/laravel-json-api/core/pull/24) Add `header` property to error source object. + ## [5.0.2] - 2025-01-11 ### Fixed