-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathprofile.php
More file actions
41 lines (29 loc) · 934 Bytes
/
profile.php
File metadata and controls
41 lines (29 loc) · 934 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
40
41
<?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 a profile to define rules for members
*/
$profile = new ExampleTimestampsProfile();
$document = new ResourceDocument('user', 42);
$document->applyProfile($profile);
$document->add('foo', 'bar');
/**
* you can apply the rules of the profile manually
* or use methods of the profile if provided
*/
$created = new \DateTime('-1 year');
$updated = new \DateTime('-1 month');
$profile->setTimestamps($document, $created, $updated);
/**
* get the json
*/
$contentType = Converter::prepareContentType(ContentTypeEnum::Official, extensions: [], profiles: [$profile]);
echo '<code>Content-Type: '.$contentType.'</code>'.PHP_EOL;
$options = [
'prettyPrint' => true,
];
echo '<pre>'.$document->toJson($options);