Skip to content

Commit ded2f5b

Browse files
committed
RC4
1 parent be5070e commit ded2f5b

File tree

90 files changed

+3715
-1745
lines changed

Some content is hidden

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

90 files changed

+3715
-1745
lines changed

README.md

Lines changed: 16 additions & 404 deletions
Large diffs are not rendered by default.

sample/README.md

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
11
## Neomerx JSON API sample application
22

3-
### Basic usage
3+
### Install
44

5-
```php
6-
$encoder = Encoder::instance([
7-
Author::class => AuthorSchema::class,
8-
], new JsonEncodeOptions(JSON_PRETTY_PRINT));
5+
Via Composer
96

10-
echo $encoder->encode($author) . PHP_EOL;
7+
```
8+
$ composer install
119
```
1210

13-
will output
11+
### Run sample
1412

15-
```json
16-
{
17-
"data": {
18-
"type": "people",
19-
"id": "123",
20-
"attributes": {
21-
"first_name": "John",
22-
"last_name": "Dow"
23-
},
24-
"links": {
25-
"self": "http:\/\/example.com\/people\/123"
26-
}
27-
}
28-
}
2913
```
14+
$ php sample.php
15+
```
16+
17+
The application will output a few encoding results for
3018

31-
For more details see [this sample file](sample.php)
19+
* a resource with no relationships
20+
* a resource with included relationships
21+
* sparse and field set filters usage sample
22+
* top level links and meta information usage sample
3223

33-
## Neomerx JSON API performance test
24+
For more details see [the app source code](sample.php)
25+
26+
## Performance test
3427

3528
This application includes performance test as well. It can be run with default parameters
3629

@@ -41,7 +34,7 @@ $ php sample.php -t
4134
or with execution time measurement and specified number of iterations
4235

4336
```
44-
$ php time sample.php -t=10000
37+
$ time php sample.php -t=10000
4538
```
4639

4740
If your system has debug assertions enabled it is recommended to turn them off. Just to give you an idea that debug assert are not free here is the execution time comparison
@@ -50,11 +43,3 @@ If your system has debug assertions enabled it is recommended to turn them off.
5043
|---------------------|--------------------------------------------------|--------------|
5144
|Enabled |```$ php -d assert.active=1 sample.php -t=10000```|7.589s |
5245
|Disabled |```$ php -d assert.active=0 sample.php -t=10000```|2.884s |
53-
54-
The following command could be used for performance profiling with [blackfire.io](https://blackfire.io/)
55-
56-
```
57-
$ blackfire --slot <slot number here> --samples 1 run php -d assert.active=0 sample.php -t=100
58-
```
59-
60-
Are you in a mood to optimize performance? You can start from this [performance baseline profile](https://blackfire.io/profiles/a25af07b-b0c2-4a80-ae0b-8e64222b1e10/graph).

sample/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
},
1717
"minimum-stability": "dev",
1818
"require": {
19-
"neomerx/json-api": "0.3.0"
19+
"neomerx/json-api": "0.4.0"
2020
}
2121
}

sample/sample.php

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

19+
use \Neomerx\JsonApi\Schema\Link;
1920
use \Neomerx\JsonApi\Encoder\Encoder;
2021
use \Neomerx\JsonApi\Document\DocumentLinks;
2122
use \Neomerx\JsonApi\Encoder\JsonEncodeOptions;
@@ -85,7 +86,7 @@ private function showSparseAndFieldSetsExample()
8586
$site = Site::instance('1', 'JSON API Samples', [$post]);
8687

8788
$options = new EncodingParameters(
88-
['posts.author'], // Paths to be included. Note neither 'posts' nor 'posts.comments' will be shown.
89+
['posts.author'], // Paths to be included. Note 'posts.comments' will not be shown.
8990
[
9091
// Attributes and links that should be shown
9192
'sites' => ['name'],
@@ -120,10 +121,10 @@ private function showTopLevelMetaAndLinksExample()
120121
];
121122
$links = new DocumentLinks(
122123
null,
123-
'http://example.com/people?first',
124-
'http://example.com/people?last',
125-
'http://example.com/people?prev',
126-
'http://example.com/people?next'
124+
new Link('http://example.com/people?first'),
125+
new Link('http://example.com/people?last'),
126+
new Link('http://example.com/people?prev'),
127+
new Link('http://example.com/people?next')
127128
);
128129

129130
$encoder = Encoder::instance([
@@ -167,7 +168,7 @@ private function runPerformanceTest($iterations)
167168

168169
$encoder->encode(
169170
$site,
170-
new DocumentLinks('http://example.com/sites/1?' . $rand),
171+
new DocumentLinks(new Link('http://example.com/sites/1?' . $rand)),
171172
['some' => ['meta' => 'information' . $rand]],
172173
$options
173174
);

sample/schemas/CommentSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getAttributes($comment)
4242
];
4343
}
4444

45-
public function getLinks($comment)
45+
public function getRelationships($comment)
4646
{
4747
/** @var Comment $comment */
4848
return [

sample/schemas/PostSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getAttributes($post)
4141
];
4242
}
4343

44-
public function getLinks($post)
44+
public function getRelationships($post)
4545
{
4646
/** @var Post $post */
4747
return [

sample/schemas/SiteSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getAttributes($site)
4040
];
4141
}
4242

43-
public function getLinks($site)
43+
public function getRelationships($site)
4444
{
4545
/** @var Site $site */
4646
return [

src/Codec/CodecContainer.php

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)