Polyfill old behavior
This commit is contained in:
parent
7681ec78ca
commit
74a6edf300
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of tobyz/json-api-server.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tobyz\JsonApiServer;
|
||||
|
||||
class Context
|
||||
{
|
||||
public $query;
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ use JsonApiPhp\JsonApi\Link\PrevLink;
|
|||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Tobyz\JsonApiServer\Context;
|
||||
use Tobyz\JsonApiServer\Exception\BadRequestException;
|
||||
use Tobyz\JsonApiServer\JsonApi;
|
||||
use Tobyz\JsonApiServer\JsonApiResponse;
|
||||
|
|
@ -76,6 +77,14 @@ class Index implements RequestHandlerInterface
|
|||
$serializer->add($this->resource, $model, $include);
|
||||
}
|
||||
|
||||
$context = new Context;
|
||||
$context->query = $query;
|
||||
$documentMeta = [];
|
||||
|
||||
foreach ($schema->getDocumentMeta() as $key => $value) {
|
||||
$documentMeta[] = new Structure\Meta($key, $value($context));
|
||||
}
|
||||
|
||||
return new JsonApiResponse(
|
||||
new Structure\CompoundDocument(
|
||||
new Structure\PaginatedCollection(
|
||||
|
|
@ -86,7 +95,8 @@ class Index implements RequestHandlerInterface
|
|||
new Structure\Link\SelfLink($this->buildUrl($request)),
|
||||
new Structure\Meta('offset', $offset),
|
||||
new Structure\Meta('limit', $limit),
|
||||
...($total !== null ? [new Structure\Meta('total', $total)] : [])
|
||||
...($total !== null ? [new Structure\Meta('total', $total)] : []),
|
||||
...$documentMeta
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ final class Type
|
|||
private $updatable = false;
|
||||
private $deletable = false;
|
||||
private $deleteCallback;
|
||||
private $documentMeta = [];
|
||||
|
||||
/**
|
||||
* Set the description of the type for documentation generation.
|
||||
|
|
@ -483,4 +484,14 @@ final class Type
|
|||
{
|
||||
return $this->defaultFilter;
|
||||
}
|
||||
|
||||
public function documentMeta($key, $value)
|
||||
{
|
||||
$this->documentMeta[$key] = $value;
|
||||
}
|
||||
|
||||
public function getDocumentMeta()
|
||||
{
|
||||
return $this->documentMeta;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue