From 246c4e6e31191254da03f6729317acba3e82c376 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Mon, 29 Jan 2024 11:08:15 -0100 Subject: [PATCH] Fixes getter evaluation --- CHANGELOG.md | 9 ++++++++- src/Document/HttpMessageParser/LinksMemberParser.php | 2 +- .../Relationships/ToManyRelationshipParser.php | 2 -- src/Exception/InvalidResourceDocument.php | 2 +- src/MetaAwareObject.php | 4 +--- src/Object/Links.php | 1 - src/Object/ResourceCollectionSchema.php | 2 +- .../Attributes/DiscoverAttributesMethods.php | 10 +++++----- src/Object/SchemaDiscover/DecodableAttribute.php | 1 - src/Validator/SchemaDecodeValidator.php | 2 +- 10 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84a8ccb..dea29c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [v1.3.1] 2024-01-29 +### Fix +- when using a getter, the return value should be evaluated so that it can be + transformed in a usable JSON API scalar. + ## [v1.3.0] 2024-01-25 ### Adds - a formatter expression that can be used when encoding objects that have a @@ -172,7 +177,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - JsonApi Object - Meta's information object -[Unreleased]: https://github.com/slickframework/json-api/compare/v1.2.2...HEAD +[Unreleased]: https://github.com/slickframework/json-api/compare/v1.3.1...HEAD +[v1.3.1]: https://github.com/slickframework/json-api/compare/v1.3.0...v1.3.1 +[v1.3.0]: https://github.com/slickframework/json-api/compare/v1.2.2...v1.3.0 [v1.2.2]: https://github.com/slickframework/json-api/compare/v1.2.1...v1.2.2 [v1.2.1]: https://github.com/slickframework/json-api/compare/v1.2.0...v1.2.1 [v1.2.0]: https://github.com/slickframework/json-api/compare/v1.1.3...v1.2.0 diff --git a/src/Document/HttpMessageParser/LinksMemberParser.php b/src/Document/HttpMessageParser/LinksMemberParser.php index a1fd4f3..176ae75 100644 --- a/src/Document/HttpMessageParser/LinksMemberParser.php +++ b/src/Document/HttpMessageParser/LinksMemberParser.php @@ -52,4 +52,4 @@ private static function parseLinkObject(object $linkData): Link { return new Link(DocumentParser::getMandatoryProperty($linkData, 'href')); } -} \ No newline at end of file +} diff --git a/src/Document/HttpMessageParser/Relationships/ToManyRelationshipParser.php b/src/Document/HttpMessageParser/Relationships/ToManyRelationshipParser.php index e587e27..a6f9310 100644 --- a/src/Document/HttpMessageParser/Relationships/ToManyRelationshipParser.php +++ b/src/Document/HttpMessageParser/Relationships/ToManyRelationshipParser.php @@ -61,6 +61,4 @@ public function parse(): ToManyRelationship return $relationship; } - - } diff --git a/src/Exception/InvalidResourceDocument.php b/src/Exception/InvalidResourceDocument.php index 4652dcf..69bf3e2 100644 --- a/src/Exception/InvalidResourceDocument.php +++ b/src/Exception/InvalidResourceDocument.php @@ -20,4 +20,4 @@ final class InvalidResourceDocument extends InvalidArgumentException implements JsonApiException { -} \ No newline at end of file +} diff --git a/src/MetaAwareObject.php b/src/MetaAwareObject.php index 4dfb78b..62fc39f 100644 --- a/src/MetaAwareObject.php +++ b/src/MetaAwareObject.php @@ -36,6 +36,4 @@ public function meta(): ?Meta; * @return MetaAwareObject|Document */ public function withMeta(Meta $meta): MetaAwareObject; - - -} \ No newline at end of file +} diff --git a/src/Object/Links.php b/src/Object/Links.php index eedfaa4..2d1ee9c 100644 --- a/src/Object/Links.php +++ b/src/Object/Links.php @@ -199,5 +199,4 @@ public function toArray(): array { return $this->links->toArray(); } - } diff --git a/src/Object/ResourceCollectionSchema.php b/src/Object/ResourceCollectionSchema.php index 23ea061..7f60218 100644 --- a/src/Object/ResourceCollectionSchema.php +++ b/src/Object/ResourceCollectionSchema.php @@ -17,4 +17,4 @@ interface ResourceCollectionSchema extends ResourceSchema { -} \ No newline at end of file +} diff --git a/src/Object/SchemaDiscover/Attributes/DiscoverAttributesMethods.php b/src/Object/SchemaDiscover/Attributes/DiscoverAttributesMethods.php index b4a4c6c..c94dfdf 100644 --- a/src/Object/SchemaDiscover/Attributes/DiscoverAttributesMethods.php +++ b/src/Object/SchemaDiscover/Attributes/DiscoverAttributesMethods.php @@ -114,15 +114,15 @@ private function getValue(object $object): string|int|bool|float|array|null { $value = $this->extractPropertyValue($object); + $getter = $this->getter; + if ($getter && $value) { + $value = $value->$getter(); + } + if (is_scalar($value) || is_array($value) || is_null($value)) { return $value; } - $getter = $this->getter; - if ($getter) { - return $value->$getter(); - } - $format = $this->format; if ($format && method_exists($value, 'format')) { return $value->format($format); diff --git a/src/Object/SchemaDiscover/DecodableAttribute.php b/src/Object/SchemaDiscover/DecodableAttribute.php index fc8767c..77dd303 100644 --- a/src/Object/SchemaDiscover/DecodableAttribute.php +++ b/src/Object/SchemaDiscover/DecodableAttribute.php @@ -37,5 +37,4 @@ public function assignValue(object $decodedObject, ResourceObject $resourceObjec * @param SchemaDecodeValidator $validator */ public function validate(ResourceObject $resourceObject, SchemaDecodeValidator $validator): void; - } diff --git a/src/Validator/SchemaDecodeValidator.php b/src/Validator/SchemaDecodeValidator.php index 0bdb4da..5614603 100644 --- a/src/Validator/SchemaDecodeValidator.php +++ b/src/Validator/SchemaDecodeValidator.php @@ -47,4 +47,4 @@ public function add( * @return FailedValidation|null */ public function exception(): ?FailedValidation; -} \ No newline at end of file +}