Skip to content

Commit 14e3954

Browse files
committed
Close #190
1 parent b8e0b6d commit 14e3954

File tree

180 files changed

+2615
-5559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+2615
-5559
lines changed

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
language: php
22
php:
3-
- 5.6
4-
- 7
53
- 7.1
4+
- 7.2
65
matrix:
76
include:
8-
- php: hhvm
9-
dist: trusty
10-
- php: 5.5
7+
- php: 7.1
118
script:
129
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
1310
after_script:

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/neomerx/json-api/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/neomerx/json-api/?branch=master)
33
[![Code Coverage](https://scrutinizer-ci.com/g/neomerx/json-api/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/neomerx/json-api/?branch=master)
44
[![Build Status](https://travis-ci.org/neomerx/json-api.svg?branch=master)](https://travis-ci.org/neomerx/json-api)
5-
[![HHVM](https://img.shields.io/hhvm/neomerx/json-api.svg)](https://travis-ci.org/neomerx/json-api)
65
[![License](https://img.shields.io/packagist/l/neomerx/json-api.svg)](https://packagist.org/packages/neomerx/json-api)
76

87
## Description
@@ -22,7 +21,7 @@ This framework agnostic package implements [JSON API](http://jsonapi.org/) speci
2221
* Sparse fieldsets and customized included paths
2322
* Errors
2423

25-
High code quality and **100% test coverage** with **250+ tests**. Production ready.
24+
High code quality and **100% test coverage** with **200+ tests**. Production ready.
2625

2726
**To find out more, please check out the [Wiki](https://github.com/neomerx/json-api/wiki) and [Sample App](/sample)**.
2827

@@ -42,7 +41,7 @@ The server supports
4241
- Support for such JSON API features as resource inclusion, pagination and etc.
4342

4443
<p align="center">
45-
<a href="https://github.com/limoncello-php/app" target="_blank"><img src="https://github.com/limoncello-php/app/raw/master/resources/img/screen-shot.png" alt="Demo app screen-shot" title="Limoncello App" align="middle" width="330" height="252" /></a>
44+
<a href="https://github.com/limoncello-php/app" target="_blank"><img src="https://raw.githubusercontent.com/limoncello-php/app/master/server/resources/img/screen-shot.png" alt="Demo app screen-shot" title="Limoncello App" align="middle" width="330" height="252" /></a>
4645
</p>
4746

4847
## Sample usage
@@ -78,17 +77,17 @@ will output
7877
The ```AuthorSchema``` provides information about resource's attributes and might look like
7978

8079
```php
81-
class AuthorSchema extends SchemaProvider
80+
class AuthorSchema extends BaseSchema
8281
{
8382
protected $resourceType = 'people';
8483

85-
public function getId($author)
84+
public function getId($author): ?string
8685
{
8786
/** @var Author $author */
8887
return $author->authorId;
8988
}
9089

91-
public function getAttributes($author)
90+
public function getAttributes($author, array $fieldKeysFilter = null): ?array
9291
{
9392
/** @var Author $author */
9493
return [
@@ -103,8 +102,14 @@ The first ```EncoderOptions``` parameter ```JSON_PRETTY_PRINT``` is a PHP predef
103102

104103
The second ```EncoderOptions``` parameter ```http://example.com/api/v1``` is a URL prefix that will be applied to all encoded links unless they have ```$treatAsHref``` flag set to ```true```.
105104

105+
A sample program with encoding of multiple, nested, filtered objects and more is [here](sample).
106+
106107
**For more advanced usage please check out the [Wiki](https://github.com/neomerx/json-api/wiki)**.
107108

109+
## Versions
110+
111+
Current version is 2.x (PHP 7.1+) for older PHP versions (PHP 5.5 - 7.0, HHVM) please use version 1.x.
112+
108113
## Questions?
109114

110115
Do not hesitate to check [issues](https://github.com/neomerx/json-api/issues) or post a new one.
@@ -117,8 +122,6 @@ Are you planning to add JSON API and need help? We'd love to talk to you [sales@
117122

118123
If you have spotted any specification changes that are not reflected in this package please post an [issue](https://github.com/neomerx/json-api/issues). Pull requests for documentation and code improvements are welcome.
119124

120-
Current tasks are managed with [Waffle.io](https://waffle.io/neomerx/json-api).
121-
122125
There are 2 ways to send pull requests
123126
- small pull requests should be sent to `develop` branch as **1 commit**
124127
- for bigger pull requests (e.g. new features) it's recommended to create an `issue` requesting a new branch for that feature. When a new branch named `feature/issueXX` is created (where `XX` is the issue number) you should post pull requests to this branch. When the feature is completed the branch will be squashed and merged to `develop` and then to `master` branches.

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,24 @@
2121
}
2222
],
2323
"require": {
24-
"php": ">=5.5.0",
24+
"php": ">=7.1.0",
2525
"psr/http-message": "^1.0",
2626
"psr/log": "^1.0"
2727
},
2828
"require-dev": {
29-
"phpunit/phpunit": "^4.6 || ^5.0 || ^6.0",
30-
"mockery/mockery": "~0.9.4",
31-
"scrutinizer/ocular": "^1.3",
32-
"squizlabs/php_codesniffer": "^2.5",
33-
"monolog/monolog": "^1.18",
29+
"phpunit/phpunit": "^6.5",
30+
"mockery/mockery": "^1.0",
31+
"scrutinizer/ocular": "^1.4",
32+
"squizlabs/php_codesniffer": "^3.1",
33+
"monolog/monolog": "^1.23",
3434
"phpmd/phpmd": "^2.6"
3535
},
3636
"minimum-stability": "stable",
3737
"autoload": {
3838
"psr-4": {
3939
"Neomerx\\JsonApi\\": "src/"
40-
}
40+
},
41+
"files": ["src/I18n/translate.php"]
4142
},
4243
"autoload-dev": {
4344
"psr-4": {
@@ -52,7 +53,6 @@
5253
"test-cs": "./vendor/bin/phpcs -p -s --standard=PSR2 ./src ./tests",
5354
"test-md": "./vendor/bin/phpmd ./src text codesize,controversial,cleancode,design,unusedcode,naming",
5455

55-
"perf-php": "docker-compose run --rm cli_php php /app/sample/sample.php -t=10000",
56-
"perf-hhvm": "docker-compose run --rm cli_hhvm hhvm /app/sample/sample.php -t=10000"
56+
"perf-test": "docker-compose run --rm cli_7_1_php php /app/sample/sample.php -t=10000"
5757
}
5858
}

docker-compose.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@
2121
# Performance test
2222
# $ cd /app/sample/ && time php sample.php -t=10000
2323

24-
cli_php:
25-
image: php:cli
24+
cli_7_1_php:
25+
image: php:7.1-cli
26+
container_name: cli_php_json_api
27+
volumes:
28+
- .:/app
29+
working_dir: /app
30+
tty: true
31+
32+
cli_7_2_php:
33+
image: php:7.2-cli
2634
container_name: cli_php_json_api
2735
volumes:
2836
- .:/app

sample/Application/EncodeSamples.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
* limitations under the License.
1717
*/
1818

19-
use \Closure;
20-
use \Neomerx\JsonApi\Document\Link;
21-
use \Neomerx\JsonApi\Encoder\Encoder;
22-
use \Neomerx\Samples\JsonApi\Models\Post;
23-
use \Neomerx\Samples\JsonApi\Models\Site;
24-
use \Neomerx\Samples\JsonApi\Models\Author;
25-
use \Neomerx\Samples\JsonApi\Models\Comment;
26-
use \Neomerx\JsonApi\Encoder\EncoderOptions;
27-
use \Neomerx\Samples\JsonApi\Schemas\PostSchema;
28-
use \Neomerx\Samples\JsonApi\Schemas\SiteSchema;
29-
use \Neomerx\Samples\JsonApi\Schemas\AuthorSchema;
30-
use \Neomerx\Samples\JsonApi\Schemas\CommentSchema;
31-
use \Neomerx\JsonApi\Encoder\Parameters\EncodingParameters;
19+
use Closure;
20+
use Neomerx\JsonApi\Document\Link;
21+
use Neomerx\JsonApi\Encoder\Encoder;
22+
use Neomerx\JsonApi\Encoder\EncoderOptions;
23+
use Neomerx\JsonApi\Encoder\Parameters\EncodingParameters;
24+
use Neomerx\Samples\JsonApi\Models\Author;
25+
use Neomerx\Samples\JsonApi\Models\Comment;
26+
use Neomerx\Samples\JsonApi\Models\Post;
27+
use Neomerx\Samples\JsonApi\Models\Site;
28+
use Neomerx\Samples\JsonApi\Schemas\AuthorSchema;
29+
use Neomerx\Samples\JsonApi\Schemas\CommentSchema;
30+
use Neomerx\Samples\JsonApi\Schemas\PostSchema;
31+
use Neomerx\Samples\JsonApi\Schemas\SiteSchema;
3232

3333
/**
3434
* @package Neomerx\Samples\JsonApi
@@ -106,7 +106,7 @@ public function getSparseAndFieldSetsExample()
106106
]);
107107

108108
SiteSchema::$isShowCustomLinks = false;
109-
$encoder = Encoder::instance([
109+
$encoder = Encoder::instance([
110110
Author::class => AuthorSchema::class,
111111
Comment::class => CommentSchema::class,
112112
Post::class => PostSchema::class,
@@ -167,10 +167,10 @@ public function getDynamicSchemaExample()
167167
], new EncoderOptions(JSON_PRETTY_PRINT));
168168

169169
SiteSchema::$isShowCustomLinks = false;
170-
$noLinksResult = $encoder->encodeData($site);
170+
$noLinksResult = $encoder->encodeData($site);
171171

172172
SiteSchema::$isShowCustomLinks = true;
173-
$withLinksResult = $encoder->encodeData($site);
173+
$withLinksResult = $encoder->encodeData($site);
174174

175175
return [
176176
$noLinksResult,

sample/Schemas/AuthorSchema.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,32 @@
1616
* limitations under the License.
1717
*/
1818

19-
use \Neomerx\JsonApi\Schema\SchemaProvider;
19+
use Neomerx\JsonApi\Schema\BaseSchema;
20+
use Neomerx\Samples\JsonApi\Models\Author;
2021

2122
/**
2223
* @package Neomerx\Samples\JsonApi
2324
*/
24-
class AuthorSchema extends SchemaProvider
25+
class AuthorSchema extends BaseSchema
2526
{
27+
/**
28+
* @inheritdoc
29+
*/
2630
protected $resourceType = 'people';
2731

28-
public function getId($author)
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function getId($author): ?string
2936
{
3037
/** @var Author $author */
3138
return $author->authorId;
3239
}
3340

34-
public function getAttributes($author)
41+
/**
42+
* @inheritdoc
43+
*/
44+
public function getAttributes($author, array $fieldKeysFilter = null): ? array
3545
{
3646
/** @var Author $author */
3747
return [

sample/Schemas/CommentSchema.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,48 @@
1616
* limitations under the License.
1717
*/
1818

19-
use \Neomerx\JsonApi\Schema\SchemaProvider;
19+
use Neomerx\JsonApi\Schema\BaseSchema;
20+
use Neomerx\Samples\JsonApi\Models\Comment;
2021

2122
/**
2223
* @package Neomerx\Samples\JsonApi
2324
*/
24-
class CommentSchema extends SchemaProvider
25+
class CommentSchema extends BaseSchema
2526
{
27+
/**
28+
* @inheritdoc
29+
*/
2630
protected $resourceType = 'comments';
2731

32+
/**
33+
* @inheritdoc
34+
*/
2835
protected $isShowSelfInIncluded = true;
2936

30-
public function getId($comment)
37+
/**
38+
* @inheritdoc
39+
*/
40+
public function getId($comment): ?string
3141
{
3242
/** @var Comment $comment */
3343
return $comment->commentId;
3444
}
3545

36-
public function getAttributes($comment)
46+
/**
47+
* @inheritdoc
48+
*/
49+
public function getAttributes($comment, array $fieldKeysFilter = null): ?array
3750
{
3851
/** @var Comment $comment */
3952
return [
4053
'body' => $comment->body,
4154
];
4255
}
4356

44-
public function getRelationships($comment, $isPrimary, array $includeList)
57+
/**
58+
* @inheritdoc
59+
*/
60+
public function getRelationships($comment, bool $isPrimary, array $includeRelationships): ?array
4561
{
4662
/** @var Comment $comment */
4763
return [

sample/Schemas/PostSchema.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,32 @@
1616
* limitations under the License.
1717
*/
1818

19-
use \Neomerx\JsonApi\Schema\SchemaProvider;
19+
use Neomerx\JsonApi\Schema\BaseSchema;
20+
use Neomerx\Samples\JsonApi\Models\Post;
2021

2122
/**
2223
* @package Neomerx\Samples\JsonApi
2324
*/
24-
class PostSchema extends SchemaProvider
25+
class PostSchema extends BaseSchema
2526
{
27+
/**
28+
* @inheritdoc
29+
*/
2630
protected $resourceType = 'posts';
2731

28-
public function getId($post)
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function getId($post): ?string
2936
{
3037
/** @var Post $post */
3138
return $post->postId;
3239
}
3340

34-
public function getAttributes($post)
41+
/**
42+
* @inheritdoc
43+
*/
44+
public function getAttributes($post, array $fieldKeysFilter = null): ?array
3545
{
3646
/** @var Post $post */
3747
return [
@@ -40,7 +50,10 @@ public function getAttributes($post)
4050
];
4151
}
4252

43-
public function getRelationships($post, $isPrimary, array $includeList)
53+
/**
54+
* @inheritdoc
55+
*/
56+
public function getRelationships($post, bool $isPrimary, array $includeRelationships): ?array
4457
{
4558
/** @var Post $post */
4659
return [

0 commit comments

Comments
 (0)