-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathprofile.php
39 lines (28 loc) · 870 Bytes
/
profile.php
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
use alsvanzelf\jsonapi\Document;
use alsvanzelf\jsonapi\ResourceDocument;
use alsvanzelf\jsonapi\helpers\Converter;
require '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(Document::CONTENT_TYPE_OFFICIAL, [], [$profile]);
echo '<code>Content-Type: '.$contentType.'</code>'.PHP_EOL;
$options = [
'prettyPrint' => true,
];
echo '<pre>'.$document->toJson($options);