2017 © Pedro Peláez
 

library siren-module

image

shingo-kumagai/siren-module

  • Saturday, July 18, 2015
  • by shingo-kumagai
  • Repository
  • 0 Watchers
  • 2 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

BEAR.SirenModule

WARNING: This is highly experimental stuff that isn't ready for production use yet., (*1)

Scrutinizer Code Quality Build Status, (*2)

Siren support for BEAR.Sunday, (*3)

Siren renderer, (*4)

It overrides default renderer and represents your resource in Siren format., (*5)

Siren [https://github.com/kevinswiber/siren], (*6)

Demo

Demo application using this module [https://github.com/shingo-kumagai/MyVendor.MySirenApi], (*7)

Entity

class (optional)

You can specify this optional value with @SirenClass annotation., (*8)

@SirenClass("order")

properties (optional)

Properties are the response body of the resource object., (*9)

Entities

Add sub related resource entities using @SirenEmbedResource annotation., (*10)

@SirenEmbedResource(rel="customer", src="app://self/customer?customerId={customerId}")

And then, you can embed the entity by request like below., (*11)

$this['customer']->addQuery(['customerId' => $customerId])->eager->request();

For sub related link entity use @SirenEmbedLink annotation., (*12)

@SirenEmbedLink(rel="order-items", src="app://self/order/items?orderNumber={orderNumber}")

Actions

Action can be added using @SirenAction annotation., (*13)

@SirenAction(src="app://self/order/items?orderNumber={orderNumber}", method="post")

The actual method defined as SirenAction has to be annotated like below., (*14)

    /**
     * @SirenName("add-item")
     * @SirenTitle("Add Item")
     * @SirenField(name="orderNumber", type="hidden", value="{orderNumber}")
     * @SirenField(name="productCode", type="text")
     * @SirenField(name="quantity", type="number")
     *
     * @param int $customerId
     * @return $this
     */
    public function onPost($customerId)
    {
        // do something...
        return $this;
    }

name (required)

You need to define action name using @SirenName annotation when you want to represent Action, (*15)

title (optional)

This is optional. You can specify with @SirenTitle annotation., (*16)

field (optional)

This is going to be controls of the action. You can add user control for the action with @SirenField annotation., (*17)

type (optional)

WIP, (*18)

@SirenLink(rel="previous", param="orderNumber")
@SirenLink(rel="next", param="orderNumber")

Example

Response

{
    "class": [
        "order"
    ],
    "properties": {
        "orderNumber": 42,
        "itemCount": 3,
        "status": "pending"
    },
    "entities": [
        {
            "href": "/customer?customerId=pj123",
            "rel": [
                "customer"
            ],
            "class": [
                "info",
                "customer"
            ],
            "properties": {
                "customerId": "pj123",
                "name": "Peter Joseph"
            }
        },
        {
            "href": "/orderitems?orderNumber=42",
            "rel": [
                "order-items"
            ],
            "class": [
                "items",
                "collection"
            ]
        }
    ],
    "actions": [
        {
            "name": "add-item",
            "href": "/orderitems?orderNumber=42",
            "method": "POST",
            "title": "Add Item",
            "type": "application/x-www-form-urlencoded",
            "fields": [
                {
                    "name": "orderNumber",
                    "type": "hidden",
                    "value": "42"
                },
                {
                    "name": "productCode",
                    "type": "text"
                },
                {
                    "name": "quantity",
                    "type": "number"
                }
            ]
        }
    ],
    "links": [
        {
            "rel": [
                "self"
            ],
            "href": "/orders?orderNumber=42"
        },
        {
            "rel": [
                "previous"
            ],
            "href": "/orders?orderNumber=41"
        },
        {
            "rel": [
                "next"
            ],
            "href": "/orders?orderNumber=43"
        }
    ]
}

The Versions

18/07 2015

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

by Shingo Kumagai

29/06 2015

1.x-dev

1.9999999.9999999.9999999-dev

  Sources   Download

MIT

The Requires

 

by Shingo Kumagai