Skip to content

Commit

Permalink
Fixed some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Sep 20, 2015
1 parent 7201845 commit 8e93c1b
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,30 +196,38 @@ public function getLinks()
]
);

// This is equivalent to the following:
// return Links::createRelativeWithSelf("http://example.com/api", "/books/" . $this->getResourceId());
// or:
// return Links::createAbsoluteWithSelf("http://example.com/api/books/" . $this->getResourceId());
/* This is equivalent to the following:
return Links::createRelativeWithSelf(
"http://example.com/api",
new Link("/books/" . $this->getResourceId())
);

or:

return Links::createAbsoluteWithSelf(
new Link("http://example.com/api/books/" . $this->getResourceId())
);
*/
}
```

This time, we want a self link to appear in the document. For this purpose, we utilize the `getResourceId()` method,
which is a shortcut of calling the resource transformer (which is introduced below) to obtain the ID of the
primary resource (`$this->transformer->getId($this->domainObject)`).

The only difference between `AbstractSingleResourceDocument` and `AbstractCollectionDocument` lies in the way they
The only difference between the `AbstractSingleResourceDocument` and `AbstractCollectionDocument` is the way they
regard the `domainObject`: the first one regards it as a single domain object while the latter regards it
as an iterable collection of domain objects.

###### Usage

Documents are to be transformed to HTTP responses. The easiest way to achieve this is to use the
[`JsonApi` class](#jsonapi-class) and chose the appropriate response type. Successful documents support three
[`JsonApi` class](#jsonapi-class) and choose the appropriate response type. Successful documents support three
kinds of responses:

- normal: All the top-level members can be present in the response
- meta: Only the meta top-level member will be present in the response
- relationship: Only the specified relationship object will be present in the response
- normal: All the top-level members can be present in the response (except of the "errors")
- meta: Only the "jsonApi", "links" and meta top-level member can be present in the response
- relationship: The specified relationship object will be the primary data of the response

##### Documents for error responses

Expand Down Expand Up @@ -342,10 +350,18 @@ class BookResourceTransformer extends AbstractResourceTransformer
]
);

// This is equivalent to the following:
// return Links::createRelativeWithSelf("http://example.com/api", "/books/" . $this->getResourceId());
// or:
// return Links::createAbsoluteWithSelf("http://example.com/api/books/" . $this->getResourceId());
/* This is equivalent to the following:
return Links::createRelativeWithSelf(
"http://example.com/api",
new Link("/books/" . $this->getResourceId())
);

or:

return Links::createAbsoluteWithSelf(
new Link("http://example.com/api/books/" . $this->getResourceId())
);
*/
}

/**
Expand Down

0 comments on commit 8e93c1b

Please sign in to comment.