-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathextension.php
More file actions
39 lines (27 loc) · 869 Bytes
/
extension.php
File metadata and controls
39 lines (27 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types=1);
use alsvanzelf\jsonapi\ResourceDocument;
use alsvanzelf\jsonapi\enums\ContentTypeEnum;
use alsvanzelf\jsonapi\helpers\Converter;
require __DIR__.'/bootstrap_examples.php';
/**
* use an extension extend the document with new members
*/
$extension = new ExampleVersionExtension();
$document = new ResourceDocument('user', 42);
$document->applyExtension($extension);
$document->add('foo', 'bar');
/**
* you can apply the rules of the extension manually
* or use methods of the extension if provided
*/
$extension->setVersion($document, '2019');
/**
* get the json
*/
$contentType = Converter::prepareContentType(ContentTypeEnum::Official, extensions: [$extension], profiles: []);
echo '<code>Content-Type: '.$contentType.'</code>'.PHP_EOL;
$options = [
'prettyPrint' => true,
];
echo '<pre>'.$document->toJson($options);