Skip to content

How it works

matteosister edited this page Dec 3, 2014 · 12 revisions

Next (Data Handler) ►

The library is a small layer of abstraction to handle patch operations. The actors are two:

  • The subject (or the subjects)
  • the operations

The subject (or the subjects) are defined by a restful resource. So it is normally deducted by the uri. It's just a php instance, or a collection of instances. The only mandatory requirement is that they should implement the Patchable interface

The operations are the core business of the patch manager, and are normally passed inside a request body content.

The format is json. Maybe in the future some other formats could be added.

for example...

PATCH /users/1

{ "op": "promote" }

Executes a promote operation on the user identified by id 1

PATCH /articles

{ "op": "tag", "tags": ["php", "open source"] }

Executes a tag operation on all the articles. In this case we are passing a tags parameter.

The operation could be easily concatenated in a json array

PATCH /books

[
  { "op": "data", "property": "in_stock", "value": true },
  { "op": "update_qty", "value": 10 },
  { "op": "start_selling" }
]

The scope of this library is to define these operations and validate them. It gives an easy point of extension to add custom operations. Also, it gives a meaning to that "operations" on data that normally do not fit really well in an api design.

Every operation needs an handler (a PHP Object) to manage the tranformations to be done on the subject/s.

Next (Data Handler) ►