Skip to content

Commit

Permalink
Merge branch 'release/5.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lindyhopchris committed Jan 23, 2025
2 parents 63d8c4c + 1a178fe commit 846e3da
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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 846e3da

Please sign in to comment.