From c4d9137f0f93efde042263c21fa82b78dba329c5 Mon Sep 17 00:00:00 2001 From: Jasper Wissels Date: Fri, 9 Dec 2022 15:55:38 +0100 Subject: [PATCH 1/3] add findAttribute method --- src/helpers/RequestParser.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/helpers/RequestParser.php b/src/helpers/RequestParser.php index 14a83733..a4abbc37 100644 --- a/src/helpers/RequestParser.php +++ b/src/helpers/RequestParser.php @@ -293,6 +293,18 @@ public function getAttribute($attributeName) { return $this->document['data']['attributes'][$attributeName]; } + /** + * @param string $attributeName + * @return mixed|null + */ + public function findAttribute($attributeName) { + if ($this->hasAttribute($attributeName) === false) { + return null; + } + + return $this->getAttribute($attributeName); + } + /** * @param string $relationshipName * @return boolean From e05aaa365df3dc4983f9ca6e997d98750e44bcba Mon Sep 17 00:00:00 2001 From: Jasper Wissels Date: Mon, 24 Nov 2025 20:38:32 +0100 Subject: [PATCH 2/3] prepare for php 8.4 deprecations --- examples/bootstrap_examples.php | 2 +- src/ErrorsDocument.php | 2 +- tests/example_output/ExampleTimestampsProfile.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/bootstrap_examples.php b/examples/bootstrap_examples.php index fc4793d3..e266cb58 100644 --- a/examples/bootstrap_examples.php +++ b/examples/bootstrap_examples.php @@ -142,7 +142,7 @@ public function getOfficialLink() { * optionally helpers for the specific profile */ - public function setTimestamps(ResourceInterface $resource, \DateTimeInterface $created=null, \DateTimeInterface $updated=null) { + public function setTimestamps(ResourceInterface $resource, ?\DateTimeInterface $created=null, ?\DateTimeInterface $updated=null) { if ($resource instanceof ResourceIdentifierObject) { throw new Exception('cannot add attributes to identifier objects'); } diff --git a/src/ErrorsDocument.php b/src/ErrorsDocument.php index 025bc06c..f43abdd7 100644 --- a/src/ErrorsDocument.php +++ b/src/ErrorsDocument.php @@ -31,7 +31,7 @@ class ErrorsDocument extends Document { /** * @param ErrorObject $errorObject optional */ - public function __construct(ErrorObject $errorObject=null) { + public function __construct(?ErrorObject $errorObject=null) { parent::__construct(); if ($errorObject !== null) { diff --git a/tests/example_output/ExampleTimestampsProfile.php b/tests/example_output/ExampleTimestampsProfile.php index 56b07f5a..4426643f 100644 --- a/tests/example_output/ExampleTimestampsProfile.php +++ b/tests/example_output/ExampleTimestampsProfile.php @@ -11,7 +11,7 @@ public function getOfficialLink() { return 'https://jsonapi.org/recommendations/#authoring-profiles'; } - public function setTimestamps(ResourceInterface $resource, \DateTimeInterface $created=null, \DateTimeInterface $updated=null) { + public function setTimestamps(ResourceInterface $resource, ?\DateTimeInterface $created=null, ?\DateTimeInterface $updated=null) { if ($resource instanceof ResourceIdentifierObject) { throw new Exception('cannot add attributes to identifier objects'); } From 41b61d04f2db1aac8e151684e83af9c5e7db60e8 Mon Sep 17 00:00:00 2001 From: Jasper Wissels Date: Mon, 24 Nov 2025 20:44:47 +0100 Subject: [PATCH 3/3] Update src/ErrorsDocument.php Co-authored-by: Bart --- src/ErrorsDocument.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ErrorsDocument.php b/src/ErrorsDocument.php index f43abdd7..12f2adef 100644 --- a/src/ErrorsDocument.php +++ b/src/ErrorsDocument.php @@ -29,7 +29,7 @@ class ErrorsDocument extends Document { ]; /** - * @param ErrorObject $errorObject optional + * @param ?ErrorObject $errorObject optional */ public function __construct(?ErrorObject $errorObject=null) { parent::__construct();