Skip to content

Releases: bearsunday/BEAR.Resource

1.7.2

05 Aug 11:42
Compare
Choose a tag to compare
  • [ADD] @Link title as comment #117

1.7.1

29 Jul 10:57
Compare
Choose a tag to compare

Example:

Resource class

use BEAR\Resource\Annotation\JsonSchema;
use BEAR\Resource\ResourceObject;

class User extends ResourceObject
{
    /**
     * User
     *
     * Returns a variety of information about the user specified by the required $id parameter
     *
     * @param string $id User ID
     *
     * @JsonSchema(schema="user.json")
     */
    public function onGet($id)
    {
       // $this->body = '$user;

        return $this;
    }
}

Json Schema

user.json

{
  "type": "object",
  "properties": {
    "name": { "$ref": "name.json#/definitions/name"},
    "age": {
      "description": "Age in years",
      "type": "integer",
      "minimum": 20
    }
  },
  "required": ["name", "age"]
}

name.json

{
  "title": "Name",
  "definitions": {
    "name": {
      "type": "object",
      "properties": {
        "firstName": {"type": "string"},
        "lastName": {"type": "string"}
      },
      "required": ["firstName", "lastName"]
    }
  }
}

Request

OPTIONS /user

Response includes request and response meta information .

{
    "GET": {
        "summary": "User",
        "description": "Returns a variety of information about the user specified by the required $id parameter",
        "request": {
            "parameters": {
                "id": {
                    "type": "string",
                    "description": "User ID"
                }
            },
            "required": [
                "id"
            ]
        },
        "schema": {
            "type": "object",
            "properties": {
                "name": {
                    "$ref": "name.json#/definitions/name"
                },
                "age": {
                    "type": "integer",
                    "description": "Age in years",
                    "minimum": 20
                }
            },
            "required": [
                "name",
                "age"
            ]
        }
    }
}

Install

$this->install(JsonSchemalModule($jsonSchemaDir, $jsonValidateDir))

1.7.0

28 Jul 04:57
Compare
Choose a tag to compare
  • [ADD] json-schema index key #111
  • [ADD] json-schema request parameter validation #112

1.6.2

21 Jul 08:39
Compare
Choose a tag to compare
  • bug #109 conflict for phpdocumentor/reflection-docblock 3.2

1.6.1

12 Jun 06:07
Compare
Choose a tag to compare

This release fix bug #107

1.6.0

07 Jun 03:00
Compare
Choose a tag to compare
  • [NEW] @JsonSchema validation #106
  • [UPDATE] Web context parameters needs no more null default and performance improved #105 ]
  • [UPDATE] "assisted parameter" like web context or Ray.Di assisted injection can not override parameter #104
  • OPTION method allow parameter are capitalized. (GET, POST)

1.5.3

26 May 02:09
Compare
Choose a tag to compare

This release update nocarrier/hal package ^0.9.12 to support curries.

1.5.1

20 May 22:12
Compare
Choose a tag to compare

This release fix #103 "Allow" ucword.

1.5.0

19 May 21:25
Compare
Choose a tag to compare
  • [ADD] RFC 2616 OPTIONS method payload #95 #99
  • [ADD] OptionsMethodModule #96
  • [ADD] @ResourceParam template URI support #97
  • [ADD] http constant package koriym/http-constant
  • [FIX] Disallow @ResourceParam and @assisted parameter by withQuery() query #98

RFC 2616 - HTTP/1.1 specification section 9.2 page 51 OPTIONS

The response body, if any, SHOULD also include information about the communication options. The format for such a body is not defined by this specification, but might be defined by future extensions to HTTP.

The payload of OPTIONS method is generated from method signature and PHPDOC. You would not need extra work to provide specifications.

    /**
     * Todos list
     *
     * Returns the todos list specified by status
     *
     * @param string $status todo status
     */
    public function onGet(string $status = null) : ResourceObject
    {
        // ....
    }

    /**
     * Create todo
     *
     * Create todo and add to todos list
     *
     * @param string $title todo title
     *
     */    
    public function onPost(string $title) : ResourceObject
    {
        // ....
    }

The result of http OPTIONS method request.

curl -i -X OPTIONS http://127.0.0.1:8080/

HTTP/1.1 200 OK
Host: 127.0.0.1:8080
Date: Tue, 16 May 2017 03:48:50 +0200
Connection: close
X-Powered-By: PHP/7.1.0
Content-Type: application/json
allow: GET, POST

200 OK
Content-Type: application/json
allow: GET, POST

{
    "GET": {
        "summary": "Todos list",
        "description": "Returns the todos list specified by status",
        "parameters": {
            "status": {
                "description": "todo status",
                "type": "string"
            }
        }
    },
    "POST": {
        "summary": "Create todo",
        "description": "Create todo and add to todos list",
        "parameters": {
            "title": {
                "description": "todo title",
                "type": "string"
            }
        },
        "required": [
            "title"
        ]
    }
}

An options command works in console as well as web.

php bootstrap/web.php options /

200 OK
Content-Type: application/json
allow: GET, POST

{
    "GET": {

@ResourceParam supports uri template.

The result of resource request app://self/rparam/login{?name}#nickname is injected to theid parameter.

    /**
     * @ResourceParam(param="id", uri="app://self/rparam/login{?name}#nickname", templated=true)
     */
    public function onPost($id, $name)
    {

1.4.7

01 May 07:33
Compare
Choose a tag to compare

This release fix the issue #94

class Holder extends ResourceObject
{
    public function __construct(ResourceInterface $resource)
    {
        $resource->get->uri('app://self/author?id=1')->eager->request();
    }
    public function onPost()
    {
        return true;
    }
}

When constructor has another resource request, request method was shared with two resource request client because it is injected as a singleton. This PR fix the issue.

This issue is appeared when the form which has resource request in init() injected resource client.