From 85ebe0aa03379888ac989ac5b95de42a04a0e2d4 Mon Sep 17 00:00:00 2001 From: f3ath Date: Thu, 19 Dec 2019 13:55:07 -0800 Subject: [PATCH 1/2] Fix #99 --- .travis.yml | 1 + CHANGELOG.md | 7 ++++++- src/ResourceIdentifier.php | 6 +++--- test/DataDocument/SingleResourceIdentifierTest.php | 8 ++++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index fe3c026..3261074 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ php: - '7.1' - '7.2' - '7.3' + - '7.4' before_script: - composer install diff --git a/CHANGELOG.md b/CHANGELOG.md index 9185eeb..d565111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [2.1.1] - 2019-12-19 +### Fixed +- ResourceIdentifier does not allow multiple meta members (#99) + ## [2.1.0] - 2019-02-25 ### Fixed - Relationship without data property (#92) @@ -18,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - v2 initial release -[Unreleased]: https://github.com/json-api-php/json-api/compare/2.1.0...HEAD +[Unreleased]: https://github.com/json-api-php/json-api/compare/2.1.1...HEAD +[2.2.0]: https://github.com/json-api-php/json-api/compare/2.1.0...2.1.1 [2.1.0]: https://github.com/json-api-php/json-api/compare/2.0.1...2.1.0 [2.0.1]: https://github.com/json-api-php/json-api/compare/2.0.0...2.0.1 diff --git a/src/ResourceIdentifier.php b/src/ResourceIdentifier.php index 6967856..c00d203 100644 --- a/src/ResourceIdentifier.php +++ b/src/ResourceIdentifier.php @@ -16,17 +16,17 @@ final class ResourceIdentifier implements PrimaryData */ private $id; - public function __construct(string $type, string $id, Meta $meta = null) + public function __construct(string $type, string $id, Meta ...$metas) { if (isValidName($type) === false) { throw new \DomainException("Invalid type value: $type"); } - $this->obj = (object) [ + $this->obj = (object)[ 'type' => $type, 'id' => $id, ]; - if ($meta) { + foreach ($metas as $meta) { $meta->attachTo($this->obj); } $this->type = $type; diff --git a/test/DataDocument/SingleResourceIdentifierTest.php b/test/DataDocument/SingleResourceIdentifierTest.php index 92a91d5..1d12a77 100644 --- a/test/DataDocument/SingleResourceIdentifierTest.php +++ b/test/DataDocument/SingleResourceIdentifierTest.php @@ -36,7 +36,10 @@ public function testExtendedDocument() "data": { "type": "apples", "id": "1", - "meta": {"apple_meta": "foo"} + "meta": { + "apple_meta": "foo", + "bar": [42] + } }, "links": { "self": "/apples/1" @@ -51,7 +54,8 @@ public function testExtendedDocument() new ResourceIdentifier( 'apples', '1', - new Meta('apple_meta', 'foo') + new Meta('apple_meta', 'foo'), + new Meta('bar', [42]) ), new SelfLink('/apples/1'), new JsonApi(), From 5617f0595b182597aa44ebb15520142e82dfacfc Mon Sep 17 00:00:00 2001 From: f3ath Date: Thu, 19 Dec 2019 13:58:47 -0800 Subject: [PATCH 2/2] Style --- src/ResourceIdentifier.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ResourceIdentifier.php b/src/ResourceIdentifier.php index 857485c..dff34f8 100644 --- a/src/ResourceIdentifier.php +++ b/src/ResourceIdentifier.php @@ -22,7 +22,7 @@ public function __construct(string $type, string $id, Meta ...$metas) throw new \DomainException("Invalid type value: $type"); } - $this->obj = (object)[ + $this->obj = (object) [ 'type' => $type, 'id' => $id, ];