From facea7471f7af674d75eef00eda2c1a60575c746 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 29 Aug 2018 10:46:49 -0700 Subject: [PATCH 1/4] Remove the confusing statement (#86) --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 1677ff1..8e831cf 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # [JSON API](http://jsonapi.org) spec implemented in PHP 7. Immutable -**This is v2 of the implementation. For v1 click [here](https://github.com/json-api-php/json-api/tree/v1).** - The goal of this library is to ensure strict validity of JSON API documents being produced. JSON: From 0e9681a9c91ae94ab2c81a22dfdf879b017e305f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Sat, 29 Sep 2018 00:52:23 +0200 Subject: [PATCH 2/4] MetaDocumentMember should be Attachable (#87) --- src/Internal/MetaDocumentMember.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Internal/MetaDocumentMember.php b/src/Internal/MetaDocumentMember.php index daff35c..27aded5 100644 --- a/src/Internal/MetaDocumentMember.php +++ b/src/Internal/MetaDocumentMember.php @@ -5,6 +5,6 @@ /** * @internal */ -interface MetaDocumentMember +interface MetaDocumentMember extends Attachable { } From 6b9374a46c5c43bf9a6daf5e688ee417e653c5f8 Mon Sep 17 00:00:00 2001 From: Alexey Date: Mon, 31 Dec 2018 16:34:57 -0800 Subject: [PATCH 3/4] Downgrade min required php version to 7.1 (fixes #89) (#90) --- .travis.yml | 2 +- composer.json | 4 ++-- src/Attribute.php | 5 ++++- src/Error.php | 5 ++++- src/Error/Code.php | 5 ++++- src/Error/Detail.php | 5 ++++- src/Error/Id.php | 5 ++++- src/Error/SourceParameter.php | 5 ++++- src/Error/SourcePointer.php | 5 ++++- src/Error/Status.php | 5 ++++- src/Error/Title.php | 5 ++++- src/Included.php | 5 ++++- src/Internal/Attachable.php | 5 ++++- src/JsonApi.php | 5 ++++- src/Link/AboutLink.php | 5 ++++- src/Link/FirstLink.php | 5 ++++- src/Link/LastLink.php | 5 ++++- src/Link/NextLink.php | 5 ++++- src/Link/PrevLink.php | 5 ++++- src/Link/RelatedLink.php | 5 ++++- src/Link/SelfLink.php | 5 ++++- src/Meta.php | 2 +- src/NullData.php | 5 ++++- src/PaginatedCollection.php | 5 ++++- src/Pagination.php | 5 ++++- src/ResourceCollection.php | 5 ++++- src/ResourceIdentifier.php | 10 ++++++++-- src/ResourceIdentifierCollection.php | 5 ++++- src/ResourceObject.php | 15 ++++++++++++--- src/ToMany.php | 5 ++++- src/ToNull.php | 5 ++++- src/ToOne.php | 5 ++++- src/functions.php | 4 ++-- test/BaseTestCase.php | 2 +- 34 files changed, 135 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index bef7869..8ba1558 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php php: - - '7.2' + - '7.1' before_script: - composer install diff --git a/composer.json b/composer.json index 1cdeb90..50b9f32 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,11 @@ } ], "require": { - "php": ">=7.2" + "php": ">=7.1" }, "require-dev": { "phpunit/phpunit": "^7.0", - "friendsofphp/php-cs-fixer": "^2.2" + "friendsofphp/php-cs-fixer": "^2.13" }, "autoload": { "psr-4": { diff --git a/src/Attribute.php b/src/Attribute.php index 69c6621..ba1f50b 100644 --- a/src/Attribute.php +++ b/src/Attribute.php @@ -20,7 +20,10 @@ public function __construct(string $name, $val) $this->val = $val; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { child($o, 'attributes')->{$this->name} = $this->val; } diff --git a/src/Error.php b/src/Error.php index 65a012d..35b7b8d 100644 --- a/src/Error.php +++ b/src/Error.php @@ -21,7 +21,10 @@ public function __construct(ErrorMember ...$members) } } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $o->errors[] = $this->error; } diff --git a/src/Error/Code.php b/src/Error/Code.php index eafbc72..6705037 100644 --- a/src/Error/Code.php +++ b/src/Error/Code.php @@ -19,7 +19,10 @@ public function __construct(string $code) $this->code = $code; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $o->code = $this->code; } diff --git a/src/Error/Detail.php b/src/Error/Detail.php index 5950b46..dfeb86d 100644 --- a/src/Error/Detail.php +++ b/src/Error/Detail.php @@ -19,7 +19,10 @@ public function __construct(string $detail) $this->detail = $detail; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $o->detail = $this->detail; } diff --git a/src/Error/Id.php b/src/Error/Id.php index 3553f02..40eb903 100644 --- a/src/Error/Id.php +++ b/src/Error/Id.php @@ -19,7 +19,10 @@ public function __construct(string $id) $this->id = $id; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $o->id = $this->id; } diff --git a/src/Error/SourceParameter.php b/src/Error/SourceParameter.php index 613967a..05b711a 100644 --- a/src/Error/SourceParameter.php +++ b/src/Error/SourceParameter.php @@ -20,7 +20,10 @@ public function __construct(string $parameter) $this->parameter = $parameter; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { child($o, 'source')->parameter = $this->parameter; } diff --git a/src/Error/SourcePointer.php b/src/Error/SourcePointer.php index bfc6394..84815db 100644 --- a/src/Error/SourcePointer.php +++ b/src/Error/SourcePointer.php @@ -17,7 +17,10 @@ public function __construct(string $pointer) $this->pointer = $pointer; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { child($o, 'source')->pointer = $this->pointer; } diff --git a/src/Error/Status.php b/src/Error/Status.php index a61031f..0d396f6 100644 --- a/src/Error/Status.php +++ b/src/Error/Status.php @@ -19,7 +19,10 @@ public function __construct(string $status) $this->status = $status; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $o->status = $this->status; } diff --git a/src/Error/Title.php b/src/Error/Title.php index d61a706..1c18f2c 100644 --- a/src/Error/Title.php +++ b/src/Error/Title.php @@ -20,7 +20,10 @@ public function __construct(string $title) $this->title = $title; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $o->title = $this->title; } diff --git a/src/Included.php b/src/Included.php index 04c8d1c..220270b 100644 --- a/src/Included.php +++ b/src/Included.php @@ -38,7 +38,10 @@ public function validateLinkage(PrimaryData $data): void } } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { foreach ($this->resources as $resource) { $resource->attachAsIncludedTo($o); diff --git a/src/Internal/Attachable.php b/src/Internal/Attachable.php index cccd352..edd2de2 100644 --- a/src/Internal/Attachable.php +++ b/src/Internal/Attachable.php @@ -7,5 +7,8 @@ */ interface Attachable { - public function attachTo(object $o): void; + /** + * @param object $o + */ + public function attachTo($o): void; } diff --git a/src/JsonApi.php b/src/JsonApi.php index c0f2220..c895bb6 100644 --- a/src/JsonApi.php +++ b/src/JsonApi.php @@ -20,7 +20,10 @@ public function __construct(string $version = '1.0', Meta $meta = null) } } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $o->jsonapi = $this->obj; } diff --git a/src/Link/AboutLink.php b/src/Link/AboutLink.php index 31fe133..054129e 100644 --- a/src/Link/AboutLink.php +++ b/src/Link/AboutLink.php @@ -10,7 +10,10 @@ final class AboutLink implements ErrorMember { use LinkTrait; - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { child($o, 'links')->about = $this->link; } diff --git a/src/Link/FirstLink.php b/src/Link/FirstLink.php index f41ab3c..e569e86 100644 --- a/src/Link/FirstLink.php +++ b/src/Link/FirstLink.php @@ -10,7 +10,10 @@ final class FirstLink implements PaginationLink { use LinkTrait; - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { child($o, 'links')->first = $this->link; } diff --git a/src/Link/LastLink.php b/src/Link/LastLink.php index b174cb2..36a91e8 100644 --- a/src/Link/LastLink.php +++ b/src/Link/LastLink.php @@ -10,7 +10,10 @@ final class LastLink implements PaginationLink { use LinkTrait; - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { child($o, 'links')->last = $this->link; } diff --git a/src/Link/NextLink.php b/src/Link/NextLink.php index e1cce27..1b2caa1 100644 --- a/src/Link/NextLink.php +++ b/src/Link/NextLink.php @@ -10,7 +10,10 @@ final class NextLink implements PaginationLink { use LinkTrait; - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { child($o, 'links')->next = $this->link; } diff --git a/src/Link/PrevLink.php b/src/Link/PrevLink.php index 99a61c3..a02c69b 100644 --- a/src/Link/PrevLink.php +++ b/src/Link/PrevLink.php @@ -10,7 +10,10 @@ final class PrevLink implements PaginationLink { use LinkTrait; - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { child($o, 'links')->prev = $this->link; } diff --git a/src/Link/RelatedLink.php b/src/Link/RelatedLink.php index c0005ff..70ddc34 100644 --- a/src/Link/RelatedLink.php +++ b/src/Link/RelatedLink.php @@ -10,7 +10,10 @@ final class RelatedLink implements ToOneMember { use LinkTrait; - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { child($o, 'links')->related = $this->link; } diff --git a/src/Link/SelfLink.php b/src/Link/SelfLink.php index 17d96cd..f886435 100644 --- a/src/Link/SelfLink.php +++ b/src/Link/SelfLink.php @@ -12,7 +12,10 @@ final class SelfLink implements DataDocumentMember, ResourceMember, ToOneMember { use LinkTrait; - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { child($o, 'links')->self = $this->link; } diff --git a/src/Meta.php b/src/Meta.php index e186648..a267bdb 100644 --- a/src/Meta.php +++ b/src/Meta.php @@ -26,7 +26,7 @@ public function __construct(string $key, $value) $this->value = $value; } - public function attachTo(object $o): void + public function attachTo($o): void { child($o, 'meta')->{$this->key} = $this->value; } diff --git a/src/NullData.php b/src/NullData.php index 26dd8a5..03cd15e 100644 --- a/src/NullData.php +++ b/src/NullData.php @@ -6,7 +6,10 @@ final class NullData implements PrimaryData { - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $o->data = null; } diff --git a/src/PaginatedCollection.php b/src/PaginatedCollection.php index 8b8e0bd..c4a51da 100644 --- a/src/PaginatedCollection.php +++ b/src/PaginatedCollection.php @@ -22,7 +22,10 @@ public function __construct(Pagination $pagination, Collection $collection) $this->collection = $collection; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $this->collection->attachTo($o); $this->pagination->attachTo($o); diff --git a/src/Pagination.php b/src/Pagination.php index aa4f9c3..42f2ef7 100644 --- a/src/Pagination.php +++ b/src/Pagination.php @@ -18,7 +18,10 @@ public function __construct(PaginationLink ...$links) $this->links = $links; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { foreach ($this->links as $link) { $link->attachTo($o); diff --git a/src/ResourceCollection.php b/src/ResourceCollection.php index 77ac09f..e2f0c4b 100644 --- a/src/ResourceCollection.php +++ b/src/ResourceCollection.php @@ -17,7 +17,10 @@ public function __construct(ResourceObject ...$resources) $this->resources = $resources; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $o->data = []; foreach ($this->resources as $resource) { diff --git a/src/ResourceIdentifier.php b/src/ResourceIdentifier.php index 221e096..6967856 100644 --- a/src/ResourceIdentifier.php +++ b/src/ResourceIdentifier.php @@ -33,12 +33,18 @@ public function __construct(string $type, string $id, Meta $meta = null) $this->id = $id; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $o->data = $this->obj; } - public function attachToCollection(object $o): void + /** + * @param object $o + */ + public function attachToCollection($o): void { $o->data[] = $this->obj; } diff --git a/src/ResourceIdentifierCollection.php b/src/ResourceIdentifierCollection.php index d13eb11..5e87189 100644 --- a/src/ResourceIdentifierCollection.php +++ b/src/ResourceIdentifierCollection.php @@ -17,7 +17,10 @@ public function __construct(ResourceIdentifier ...$identifiers) $this->identifiers = $identifiers; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $o->data = []; foreach ($this->identifiers as $identifier) { diff --git a/src/ResourceObject.php b/src/ResourceObject.php index de0a478..bab4f25 100644 --- a/src/ResourceObject.php +++ b/src/ResourceObject.php @@ -59,17 +59,26 @@ public function registerIn(array &$registry): void $registry = array_merge($registry, $this->registry); } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $o->data = $this->obj; } - public function attachAsIncludedTo(object $o): void + /** + * @param object $o + */ + public function attachAsIncludedTo($o): void { $o->included[] = $this->obj; } - public function attachToCollection(object $o): void + /** + * @param object $o + */ + public function attachToCollection($o): void { $o->data[] = $this->obj; } diff --git a/src/ToMany.php b/src/ToMany.php index 94b873b..e4227eb 100644 --- a/src/ToMany.php +++ b/src/ToMany.php @@ -27,7 +27,10 @@ public function __construct(string $name, ResourceIdentifierCollection $collecti $this->collection = $collection; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $rel = child(child($o, 'relationships'), $this->name); $rel->data = []; diff --git a/src/ToNull.php b/src/ToNull.php index 0efaef0..4e30861 100644 --- a/src/ToNull.php +++ b/src/ToNull.php @@ -21,7 +21,10 @@ public function __construct(string $name, ToOneMember ...$members) $this->members = $members; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { $obj = combine(...$this->members); $obj->data = null; diff --git a/src/ToOne.php b/src/ToOne.php index c6d32da..dcd2e7a 100644 --- a/src/ToOne.php +++ b/src/ToOne.php @@ -26,7 +26,10 @@ public function __construct(string $name, ResourceIdentifier $identifier, ToOneM $this->identifier = $identifier; } - public function attachTo(object $o): void + /** + * @param object $o + */ + public function attachTo($o): void { child($o, 'relationships')->{$this->name} = $this->obj; } diff --git a/src/functions.php b/src/functions.php index d7c89a4..df50e2d 100644 --- a/src/functions.php +++ b/src/functions.php @@ -4,7 +4,7 @@ use JsonApiPhp\JsonApi\Internal\Attachable; -function combine(Attachable ...$members): object +function combine(Attachable ...$members) { $obj = (object) []; foreach ($members as $member) { @@ -13,7 +13,7 @@ function combine(Attachable ...$members): object return $obj; } -function child(object $o, string $name): object +function child($o, string $name) { if (!isset($o->{$name})) { $o->{$name} = (object) []; diff --git a/test/BaseTestCase.php b/test/BaseTestCase.php index 2485e47..eca3598 100644 --- a/test/BaseTestCase.php +++ b/test/BaseTestCase.php @@ -6,7 +6,7 @@ abstract class BaseTestCase extends TestCase { - public static function assertEncodesTo(string $expected, object $obj, string $message = '') + public static function assertEncodesTo(string $expected, $obj, string $message = '') { self::assertEquals( json_decode($expected), From 668ec0c9e75a44f4e72953a73d5586628c67f46c Mon Sep 17 00:00:00 2001 From: Alexey Date: Mon, 31 Dec 2018 16:44:00 -0800 Subject: [PATCH 4/4] Update CHANGELOG.md (#91) --- CHANGELOG.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bebaa62..86ca5ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] -## [2.0.0] - 2018-02-26 -V2 initial release +## [2.0.1] - 2018-12-31 +### Changed +- Downgraded min required php version to 7.1 -[Unreleased]: https://github.com/json-api-php/json-api/compare/2.0.0...HEAD +## 2.0.0 - 2018-02-26 +### Added +- v2 initial release + +[Unreleased]: https://github.com/json-api-php/json-api/compare/2.0.1...HEAD +[2.0.1]: https://github.com/json-api-php/json-api/compare/2.0.0...2.0.1