-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
85 lines (66 loc) · 2.26 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
require_once "vendor/autoload.php";
use Siren\Components\Entity;
use Siren\Components\Link;
use Siren\Components\Action;
use Siren\Components\Field;
use Siren\Encoders\Encoder;
$order = new Entity();
$order->addClass("order")
->setProperties(array(
"orderNumber" => 42,
"itemCount" => 3,
"status" => "pending"
));
$items = new Entity;
$items->addClass("items")
->addClass("collection")
->addRel("http://x.io/rels/order-items")
->setHref("http://api.x.io/orders/42/items");
$order->addEntity($items);
$customerInfo = new Entity;
$customerInfo->addClass("info")
->addClass("customer")
->addRel("http://x.io/rels/customer")
->setHref("http://api.x.io/customer")
->setProperties(array(
"customerId" => "pj123",
"name" => "Peter Joseph"
));
$link = new Link;
$link->addRel("self")
->setHref("http://api.x.io/customers/pj123");
$customerInfo->addLink($link);
$order->addEntity($customerInfo);
$orderNumber = new Field;
$orderNumber->setName("orderNumber")
->setType("hidden")
->setValue(42);
$productCode = new Field;
$productCode->setName("productCode");
$quantity = new Field;
$quantity->setName("quantity")
->setType("number");
$action = new Action;
$action->setName("add-item")
->setHref("http://api.x.io/orders/42/items")
->setMethod("POST")
->setTitle("Add Item")
->addField($orderNumber)
->addField($productCode)
->addField($quantity);
$order->addAction($action);
$self = new Link;
$self->addRel("self")
->setHref("http://api.x.io/orders/42");
$prev = new Link;
$prev->addRel("previous")
->setHref("http://api.x.io/orders/41");
$next = new Link;
$next->addRel("next")
->setHref( "http://api.x.io/orders/43");
$order->addLink($self);
$order->addLink($prev);
$order->addLink($next);
$response = (new Encoder)->encode($order);
print_r(json_encode($response, JSON_UNESCAPED_SLASHES));