Skip to content

Commit 846e3da

Browse files
committed
Merge branch 'release/5.1.0'
2 parents 63d8c4c + 1a178fe commit 846e3da

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. This projec
55

66
## Unreleased
77

8+
## [5.1.0] - 2025-01-23
9+
10+
### Added
11+
12+
- [#24](https://github.com/laravel-json-api/core/pull/24) Add `header` property to error source object.
13+
814
## [5.0.2] - 2025-01-11
915

1016
### Fixed

src/Core/Document/ErrorSource.php

+47-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class ErrorSource implements Serializable
3131
*/
3232
private ?string $parameter;
3333

34+
/**
35+
* @var string|null
36+
*/
37+
private ?string $header;
38+
3439
/**
3540
* @param ErrorSource|array|null $value
3641
* @return ErrorSource
@@ -60,7 +65,8 @@ public static function fromArray(array $source): self
6065
{
6166
return new self(
6267
$source['pointer'] ?? null,
63-
$source['parameter'] ?? null
68+
$source['parameter'] ?? null,
69+
$source['header'] ?? null,
6470
);
6571
}
6672

@@ -69,11 +75,13 @@ public static function fromArray(array $source): self
6975
*
7076
* @param string|null $pointer
7177
* @param string|null $parameter
78+
* @param string|null $header
7279
*/
73-
public function __construct(?string $pointer = null, ?string $parameter = null)
80+
public function __construct(?string $pointer = null, ?string $parameter = null, ?string $header = null)
7481
{
7582
$this->pointer = $pointer;
7683
$this->parameter = $parameter;
84+
$this->header = $header;
7785
}
7886

7987
/**
@@ -149,12 +157,47 @@ public function withoutParameter(): self
149157
return $this;
150158
}
151159

160+
/**
161+
* A string indicating which request header caused the error.
162+
*
163+
* @return string|null
164+
*/
165+
public function header(): ?string
166+
{
167+
return $this->header;
168+
}
169+
170+
/**
171+
* Add a string indicating which request header caused the error.
172+
*
173+
* @param string|null $header
174+
* @return $this
175+
*/
176+
public function setHeader(?string $header): self
177+
{
178+
$this->header = $header;
179+
180+
return $this;
181+
}
182+
183+
/**
184+
* Remove the source header.
185+
*
186+
* @return $this
187+
*/
188+
public function withoutHeader(): self
189+
{
190+
$this->header = null;
191+
192+
return $this;
193+
}
194+
152195
/**
153196
* @return bool
154197
*/
155198
public function isEmpty(): bool
156199
{
157-
return empty($this->pointer) && empty($this->parameter);
200+
return empty($this->pointer) && empty($this->parameter) && empty($this->header);
158201
}
159202

160203
/**
@@ -173,6 +216,7 @@ public function toArray()
173216
return array_filter([
174217
'parameter' => $this->parameter,
175218
'pointer' => $this->pointer,
219+
'header' => $this->header,
176220
]);
177221
}
178222

0 commit comments

Comments
 (0)