Pass models to events by reference and document Show endpoint
This commit is contained in:
parent
9846de5267
commit
497cd364a6
|
|
@ -39,6 +39,7 @@ module.exports = {
|
|||
collapsable: false,
|
||||
children: [
|
||||
'list',
|
||||
'show',
|
||||
'create',
|
||||
'update',
|
||||
'delete',
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ $type->newModel(function (Context $context) {
|
|||
Run before the model is saved.
|
||||
|
||||
```php
|
||||
$type->onCreating(function ($model, Context $context) {
|
||||
$type->onCreating(function (&$model, Context $context) {
|
||||
// do something
|
||||
});
|
||||
```
|
||||
|
|
@ -39,7 +39,7 @@ $type->onCreating(function ($model, Context $context) {
|
|||
Run after the model is saved.
|
||||
|
||||
```php
|
||||
$type->onCreated(function ($model, Context $context) {
|
||||
$type->onCreated(function (&$model, Context $context) {
|
||||
$context->meta('foo', 'bar');
|
||||
});
|
||||
```
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ $type->deletable(function (Context $context) {
|
|||
Run before the model is deleted.
|
||||
|
||||
```php
|
||||
$type->onDeleting(function ($model, Context $context) {
|
||||
$type->onDeleting(function (&$model, Context $context) {
|
||||
// do something
|
||||
});
|
||||
```
|
||||
|
|
@ -29,7 +29,7 @@ $type->onDeleting(function ($model, Context $context) {
|
|||
Run after the model is deleted.
|
||||
|
||||
```php
|
||||
$type->onDeleted(function ($model, Context $context) {
|
||||
$type->onDeleted(function (&$model, Context $context) {
|
||||
// do something
|
||||
});
|
||||
```
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
# Showing Resources
|
||||
|
||||
For each resource type, a `GET /{type}/{id}` endpoint is exposed to show an individual resource.
|
||||
|
||||
## Events
|
||||
|
||||
### `onShow`
|
||||
|
||||
Run after models and relationships have been retrieved, but before they are serialized into a JSON:API document.
|
||||
|
||||
```php
|
||||
$type->onShow(function (&$model, Context $context) {
|
||||
// do something
|
||||
});
|
||||
```
|
||||
|
|
@ -19,7 +19,7 @@ $type->updatable(function (Context $context) {
|
|||
Run before the model is saved.
|
||||
|
||||
```php
|
||||
$type->onUpdating(function ($model, Context $context) {
|
||||
$type->onUpdating(function (&$model, Context $context) {
|
||||
// do something
|
||||
});
|
||||
```
|
||||
|
|
@ -29,7 +29,7 @@ $type->onUpdating(function ($model, Context $context) {
|
|||
Run after the model is saved.
|
||||
|
||||
```php
|
||||
$type->onUpdated(function ($model, Context $context) {
|
||||
$type->onUpdated(function (&$model, Context $context) {
|
||||
// do something
|
||||
});
|
||||
```
|
||||
|
|
|
|||
|
|
@ -54,11 +54,11 @@ class Create
|
|||
$this->assertDataValid($data, $model, $context, true);
|
||||
$this->setValues($data, $model, $context);
|
||||
|
||||
run_callbacks($schema->getListeners('creating'), [$model, $context]);
|
||||
run_callbacks($schema->getListeners('creating'), [&$model, $context]);
|
||||
|
||||
$this->save($data, $model, $context);
|
||||
|
||||
run_callbacks($schema->getListeners('created'), [$model, $context]);
|
||||
run_callbacks($schema->getListeners('created'), [&$model, $context]);
|
||||
|
||||
return (new Show($this->api, $this->resource, $model))
|
||||
->handle($context)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class Delete
|
|||
throw new ForbiddenException;
|
||||
}
|
||||
|
||||
run_callbacks($schema->getListeners('deleting'), [$this->model, $context]);
|
||||
run_callbacks($schema->getListeners('deleting'), [&$this->model, $context]);
|
||||
|
||||
if ($deleteCallback = $schema->getDeleteCallback()) {
|
||||
$deleteCallback($this->model, $context);
|
||||
|
|
@ -52,7 +52,7 @@ class Delete
|
|||
$this->resource->getAdapter()->delete($this->model);
|
||||
}
|
||||
|
||||
run_callbacks($schema->getListeners('deleted'), [$this->model, $context]);
|
||||
run_callbacks($schema->getListeners('deleted'), [&$this->model, $context]);
|
||||
|
||||
return new Response(204);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class Show
|
|||
|
||||
$this->loadRelationships([$this->model], $include, $context);
|
||||
|
||||
run_callbacks($this->resource->getSchema()->getListeners('show'), [$this->model, $context]);
|
||||
run_callbacks($this->resource->getSchema()->getListeners('show'), [&$this->model, $context]);
|
||||
|
||||
$serializer = new Serializer($this->api, $context);
|
||||
$serializer->add($this->resource, $this->model, $include);
|
||||
|
|
|
|||
|
|
@ -52,11 +52,11 @@ class Update
|
|||
$this->assertDataValid($data, $this->model, $context, false);
|
||||
$this->setValues($data, $this->model, $context);
|
||||
|
||||
run_callbacks($schema->getListeners('updating'), [$this->model, $context]);
|
||||
run_callbacks($schema->getListeners('updating'), [&$this->model, $context]);
|
||||
|
||||
$this->save($data, $this->model, $context);
|
||||
|
||||
run_callbacks($schema->getListeners('updated'), [$this->model, $context]);
|
||||
run_callbacks($schema->getListeners('updated'), [&$this->model, $context]);
|
||||
|
||||
return (new Show($this->api, $this->resource, $this->model))
|
||||
->handle($context);
|
||||
|
|
|
|||
Loading…
Reference in New Issue