code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
protected function createResponse(?string $content, int $statusCode, array $headers = []): Response
{
return response($content, $statusCode, $headers);
}
|
Create HTTP response.
@param string|null $content
@param int $statusCode
@param array $headers
@return Response
|
createResponse
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
protected function isNoContent($resource, $links, $meta): bool
{
return is_null($resource) && empty($links) && empty($meta);
}
|
Does a no content response need to be returned?
@param $resource
@param $links
@param $meta
@return bool
|
isNoContent
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
protected function isAsync($data): bool
{
return $data instanceof AsynchronousProcess;
}
|
Does the data represent an asynchronous process?
@param $data
@return bool
|
isAsync
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
private function extractPage(PageInterface $page, $meta, $links): array
{
return [
$page->getData(),
$this->mergePageMeta($meta, $page),
$this->mergePageLinks($links, $page),
];
}
|
@param PageInterface $page
@param $meta
@param $links
@return array
|
extractPage
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
private function mergePageMeta($existing, PageInterface $page): array
{
if (!$merge = $page->getMeta()) {
return $existing;
}
$existing = (array) $existing ?: [];
if ($key = $page->getMetaKey()) {
$existing[$key] = $merge;
return $existing;
}
return array_replace($existing, (array) $merge);
}
|
@param object|array|null $existing
@param PageInterface $page
@return array
|
mergePageMeta
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
private function mergePageLinks(array $existing, PageInterface $page): array
{
return array_replace($existing, array_filter([
DocumentInterface::KEYWORD_FIRST => $page->getFirstLink(),
DocumentInterface::KEYWORD_PREV => $page->getPreviousLink(),
DocumentInterface::KEYWORD_NEXT => $page->getNextLink(),
DocumentInterface::KEYWORD_LAST => $page->getLastLink(),
]));
}
|
@param array $existing
@param PageInterface $page
@return array
|
mergePageLinks
|
php
|
cloudcreativity/laravel-json-api
|
src/Http/Responses/Responses.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Http/Responses/Responses.php
|
Apache-2.0
|
protected function createPage(Paginator $paginator, QueryParametersInterface $parameters)
{
$params = $this->buildParams($parameters);
return app(Factory::class)->createPage(
$paginator,
$this->createFirstLink($paginator, $params),
$this->createPreviousLink($paginator, $params),
$this->createNextLink($paginator, $params),
$this->createLastLink($paginator, $params),
$this->createMeta($paginator),
$this->getMetaKey()
);
}
|
@param Paginator $paginator
@param QueryParametersInterface $parameters
@return PageInterface
|
createPage
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CreatesPages.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CreatesPages.php
|
Apache-2.0
|
protected function createFirstLink(Paginator $paginator, array $params)
{
return $this->createLink(1, $paginator->perPage(), $params);
}
|
@param Paginator $paginator
@param array $params
@return LinkInterface
|
createFirstLink
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CreatesPages.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CreatesPages.php
|
Apache-2.0
|
protected function createPreviousLink(Paginator $paginator, array $params)
{
$previous = $paginator->currentPage() - 1;
return $previous ? $this->createLink($previous, $paginator->perPage(), $params) : null;
}
|
@param Paginator $paginator
@param array $params
@return LinkInterface|null
|
createPreviousLink
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CreatesPages.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CreatesPages.php
|
Apache-2.0
|
protected function createNextLink(Paginator $paginator, array $params)
{
$next = $paginator->currentPage() + 1;
if ($paginator instanceof LengthAwarePaginator && $next > $paginator->lastPage()) {
return null;
}
return $this->createLink($next, $paginator->perPage(), $params);
}
|
@param Paginator $paginator
@param array $params
@return LinkInterface|null
|
createNextLink
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CreatesPages.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CreatesPages.php
|
Apache-2.0
|
protected function createLastLink(Paginator $paginator, array $params)
{
if (!$paginator instanceof LengthAwarePaginator) {
return null;
}
return $this->createLink($paginator->lastPage(), $paginator->perPage(), $params);
}
|
@param Paginator $paginator
@param array $params
@return LinkInterface|null
|
createLastLink
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CreatesPages.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CreatesPages.php
|
Apache-2.0
|
protected function buildParams(QueryParametersInterface $parameters)
{
return array_filter([
BaseQueryParserInterface::PARAM_FILTER =>
$parameters->getFilteringParameters(),
BaseQueryParserInterface::PARAM_SORT =>
$this->buildSortParams((array) $parameters->getSortParameters())
]);
}
|
Build parameters that are to be included with pagination links.
@param QueryParametersInterface $parameters
@return array
|
buildParams
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CreatesPages.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CreatesPages.php
|
Apache-2.0
|
protected function createLink($page, $perPage, array $parameters = [], $meta = null)
{
return json_api()->links()->current($meta, array_merge($parameters, [
BaseQueryParserInterface::PARAM_PAGE => [
$this->getPageKey() => $page,
$this->getPerPageKey() => $perPage,
],
]));
}
|
@param int $page
@param int $perPage
@param array $parameters
@param array|object|null $meta
@return LinkInterface
|
createLink
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CreatesPages.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CreatesPages.php
|
Apache-2.0
|
private function buildSortParams(array $parameters)
{
$sort = array_map(function (SortParameterInterface $param) {
return (string) $param;
}, $parameters);
return !empty($sort) ? implode(',', $sort) : null;
}
|
@param SortParameterInterface[] $parameters
@return string|null
|
buildSortParams
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CreatesPages.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CreatesPages.php
|
Apache-2.0
|
public function __construct($query, $column = null, $key = null, $descending = true)
{
if (!empty($query->orders)) {
throw new RuntimeException('Cursor queries must not have an order applied.');
}
$this->query = $query;
$this->column = $column ?: $this->guessColumn();
$this->key = $key ?: $this->guessKey();
$this->descending = $descending;
}
|
CursorBuilder constructor.
@param QueryBuilder|EloquentBuilder $query
@param string $column
the column to use for the cursor.
@param string|null $key
the key column that the before/after cursors related to.
@param bool $descending
whether items are paged in descending order.
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
public function paginate(Cursor $cursor, $columns = ['*'])
{
if ($cursor->isBefore()) {
return $this->previous($cursor, $columns);
}
return $this->next($cursor, $columns);
}
|
@param Cursor $cursor
@param array $columns
@return CursorPaginator
|
paginate
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
protected function previous(Cursor $cursor, $columns)
{
$items = $this
->whereId($cursor->getBefore(), $this->descending ? '>' : '<')
->orderForPrevious()
->get($cursor->getLimit(), $columns)
->reverse()
->values();
return new CursorPaginator($items, true, $cursor, $this->key);
}
|
Get the previous page.
To get the previous page, we need to sort in the opposite direction
(i.e. ascending rather than descending), then reverse the results
so that they are in the correct page order.
The previous page always has-more items, because we know there is
at least one object ahead in the table - i.e. the one that was
provided as the before cursor.
@param Cursor $cursor
@param $columns
@return CursorPaginator
|
previous
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
protected function whereId($id, $operator)
{
/** If we are paging on the key, we only need one where clause. */
if ($this->isPagingOnKey()) {
$this->query->where($this->key, $operator, $id);
return $this;
}
$value = $this->getColumnValue($id);
$this->query->where(
$this->column, $operator . '=', $value
)->where(function ($query) use ($id, $value, $operator) {
/** @var QueryBuilder $query */
$query->where($this->column, $operator, $value)->orWhere($this->key, $operator, $id);
});
return $this;
}
|
Add a where clause for the supplied id and operator.
If we are paging on the key, then we only need one where clause - i.e.
on the key column.
If we are paging on a column that is different than the key, we do not
assume that the column is unique. Therefore we add where clauses for
both the column plus then use the key column (which we expect to be
unique) to differentiate between any items that have the same value for
the non-unique column.
@param $id
@param $operator
@return $this
@see https://stackoverflow.com/questions/38017054/mysql-cursor-based-pagination-with-multiple-columns
|
whereId
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
protected function orderForPrevious()
{
if ($this->descending) {
$this->orderAsc();
} else {
$this->orderDesc();
}
return $this;
}
|
Order items for a previous page query.
A previous page query needs to retrieve items in the opposite
order from the desired order.
@return $this
|
orderForPrevious
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
protected function orderForNext()
{
if ($this->descending) {
$this->orderDesc();
} else {
$this->orderAsc();
}
return $this;
}
|
Order items for a next page query.
@return $this
|
orderForNext
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
protected function orderDesc()
{
$this->query->orderByDesc($this->column);
if ($this->isNotPagingOnKey()) {
$this->query->orderByDesc($this->key);
}
return $this;
}
|
Order items in descending order.
@return $this
|
orderDesc
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
protected function orderAsc()
{
$this->query->orderBy($this->column);
if ($this->isNotPagingOnKey()) {
$this->query->orderBy($this->key);
}
return $this;
}
|
Order items in ascending order.
@return $this
|
orderAsc
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
protected function getColumnValue($id)
{
$value = $this
->getQuery() // we want the raw DB value, not the Model value as that can be mutated.
->where($this->key, $id)
->value($this->column);
if (is_null($value)) {
throw new \OutOfRangeException("Cursor key {$id} does not exist or has a null value.");
}
return $value;
}
|
Get the column value for the provided id.
@param $id
@return mixed
@throws \OutOfRangeException
if the id does not exist.
|
getColumnValue
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
protected function getQuery()
{
if (!$this->query instanceof QueryBuilder) {
return clone $this->query->getQuery();
}
return clone $this->query;
}
|
Get a base query builder instance.
@return QueryBuilder
|
getQuery
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
protected function isPagingOnKey()
{
return $this->column === $this->key;
}
|
Are we paging using the key column?
@return bool
|
isPagingOnKey
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
protected function isNotPagingOnKey()
{
return !$this->isPagingOnKey();
}
|
Are we not paging on the key column?
@return bool
|
isNotPagingOnKey
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
private function guessColumn()
{
if ($this->query instanceof EloquentBuilder || $this->query instanceof Relation) {
return $this->query->getModel()->getCreatedAtColumn();
}
return Model::CREATED_AT;
}
|
Guess the column to use for the cursor.
@return string
|
guessColumn
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
private function guessKey()
{
if ($this->query instanceof EloquentBuilder || $this->query instanceof Relation) {
return $this->query->getModel()->getRouteKeyName();
}
return 'id';
}
|
Guess the key to use for the cursor.
@return string
|
guessKey
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorBuilder.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorBuilder.php
|
Apache-2.0
|
public function __construct($items, $more, Cursor $cursor, $key)
{
$this->more = $more;
$this->items = collect($items);
$this->cursor = $cursor;
$this->key = $key;
}
|
CursorPaginator constructor.
@param mixed $items
@param bool $more
whether there are more items.
@param Cursor $cursor
@param string $key
the key used for the after/before identifiers.
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorPaginator.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorPaginator.php
|
Apache-2.0
|
public function withQualifiedColumn($column)
{
$parts = explode('.', $column);
if (!isset($parts[1])) {
throw new \InvalidArgumentException('Expecting a valid qualified column name.');
}
$this->withColumn($parts[1]);
return $this;
}
|
Set the cursor column.
@param $column
@return $this
@todo 2.0 pass qualified columns to the cursor builder.
|
withQualifiedColumn
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorStrategy.php
|
Apache-2.0
|
public function withColumn($column)
{
$this->column = $column;
return $this;
}
|
Set the cursor column.
@param $column
@return $this
@deprecated 2.0 use `withQualifiedColumn` instead.
|
withColumn
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorStrategy.php
|
Apache-2.0
|
public function withQualifiedKeyName($keyName)
{
$parts = explode('.', $keyName);
if (!isset($parts[1])) {
throw new \InvalidArgumentException('Expecting a valid qualified column name.');
}
$this->withIdentifierColumn($parts[1]);
return $this;
}
|
Set the column name for the resource's ID.
@param string $keyName
@return $this
@todo 2.0 pass qualified key name to the cursor builder.
|
withQualifiedKeyName
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorStrategy.php
|
Apache-2.0
|
public function withIdentifierColumn($column)
{
$this->identifier = $column;
return $this;
}
|
Set the column for the before/after identifiers.
@param string|null $column
@return $this
@deprecated 2.0 use `withQualifiedKeyName` instead.
|
withIdentifierColumn
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorStrategy.php
|
Apache-2.0
|
public function withColumns($cols)
{
$this->columns = $cols;
return $this;
}
|
Set the select columns for the query.
@param $cols
@return $this
|
withColumns
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorStrategy.php
|
Apache-2.0
|
protected function query($query)
{
return new CursorBuilder(
$query,
$this->column,
$this->identifier,
$this->descending
);
}
|
Create a new cursor query.
@param $query
@return CursorBuilder
|
query
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorStrategy.php
|
Apache-2.0
|
protected function cursor(QueryParametersInterface $parameters)
{
return Cursor::create(
(array) $parameters->getPaginationParameters(),
$this->before,
$this->after,
$this->limit
);
}
|
Extract the cursor from the provided paging parameters.
@param QueryParametersInterface $parameters
@return Cursor
|
cursor
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorStrategy.php
|
Apache-2.0
|
protected function createFirstLink(CursorPaginator $paginator, array $parameters = [])
{
return $this->createLink([
$this->limit => $paginator->getPerPage(),
], $parameters);
}
|
@param CursorPaginator $paginator
@param array $parameters
@return LinkInterface
|
createFirstLink
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorStrategy.php
|
Apache-2.0
|
protected function createNextLink(CursorPaginator $paginator, array $parameters = [])
{
if ($paginator->hasNoMore()) {
return null;
}
return $this->createLink([
$this->after => $paginator->lastItem(),
$this->limit => $paginator->getPerPage(),
], $parameters);
}
|
@param CursorPaginator $paginator
@param array $parameters
@return LinkInterface|null
|
createNextLink
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorStrategy.php
|
Apache-2.0
|
protected function createPrevLink(CursorPaginator $paginator, array $parameters = [])
{
if ($paginator->isEmpty()) {
return null;
}
return $this->createLink([
$this->before => $paginator->firstItem(),
$this->limit => $paginator->getPerPage(),
], $parameters);
}
|
@param CursorPaginator $paginator
@param array $parameters
@return LinkInterface|null
|
createPrevLink
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorStrategy.php
|
Apache-2.0
|
protected function createLink(array $page, array $parameters = [], $meta = null)
{
$parameters[BaseQueryParserInterface::PARAM_PAGE] = $page;
return json_api()->links()->current($meta, $parameters);
}
|
@param array $page
@param array $parameters
@param array|object|null $meta
@return LinkInterface
|
createLink
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorStrategy.php
|
Apache-2.0
|
protected function buildParams(QueryParametersInterface $parameters)
{
return array_filter([
BaseQueryParserInterface::PARAM_FILTER =>
$parameters->getFilteringParameters(),
]);
}
|
Build parameters that are to be included with pagination links.
@param QueryParametersInterface $parameters
@return array
|
buildParams
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/CursorStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/CursorStrategy.php
|
Apache-2.0
|
public function __construct(
$data,
?LinkInterface $first = null,
?LinkInterface $previous = null,
?LinkInterface $next = null,
?LinkInterface $last = null,
$meta = null,
?string $metaKey = null
) {
$this->data = $data;
$this->first = $first;
$this->previous = $previous;
$this->next = $next;
$this->last = $last;
$this->meta = $meta;
$this->metaKey = $metaKey;
}
|
Page constructor.
@param $data
@param LinkInterface|null $first
@param LinkInterface|null $previous
@param LinkInterface|null $next
@param LinkInterface|null $last
@param object|array|null $meta
@param string|null $metaKey
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/Page.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/Page.php
|
Apache-2.0
|
public function withQualifiedKeyName($keyName)
{
$this->primaryKey = $keyName;
return $this;
}
|
Set the qualified column name that is being used for the resource's ID.
@param $keyName
@return $this
|
withQualifiedKeyName
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/StandardStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/StandardStrategy.php
|
Apache-2.0
|
public function withMetaKey($key)
{
$this->metaKey = $key ?: null;
return $this;
}
|
Set the key for the paging meta.
Use this to 'nest' the paging meta in a sub-key of the JSON API document's top-level meta object.
A string sets the key to use for nesting. Use `null` to indicate no nesting.
@param string|null $key
@return $this
|
withMetaKey
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/StandardStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/StandardStrategy.php
|
Apache-2.0
|
protected function getDefaultPerPage($query)
{
return $query instanceof EloquentBuilder ? null : 15;
}
|
Get the default per-page value for the query.
If the query is an Eloquent builder, we can pass in `null` as the default,
which then delegates to the model to get the default. Otherwise the Laravel
standard default is 15.
@param $query
@return int|null
|
getDefaultPerPage
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/StandardStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/StandardStrategy.php
|
Apache-2.0
|
protected function defaultOrder($query)
{
if ($this->doesRequireOrdering($query)) {
$query->orderBy($this->primaryKey);
}
return $this;
}
|
Apply a deterministic order to the page.
@param QueryBuilder|EloquentBuilder|Relation $query
@return $this
@see https://github.com/cloudcreativity/laravel-json-api/issues/313
|
defaultOrder
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/StandardStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/StandardStrategy.php
|
Apache-2.0
|
protected function doesRequireOrdering($query)
{
if (!$this->primaryKey) {
return false;
}
$query = ($query instanceof Relation) ? $query->getBaseQuery() : $query->getQuery();
return !collect($query->orders ?: [])->contains(function (array $order) {
$col = $order['column'] ?? '';
return $this->primaryKey === $col;
});
}
|
Do we need to apply a deterministic order to the query?
If the primary key has not been used for a sort order already, we use it
to ensure the page has a deterministic order.
@param QueryBuilder|EloquentBuilder|Relation $query
@return bool
|
doesRequireOrdering
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/StandardStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/StandardStrategy.php
|
Apache-2.0
|
protected function query($query, Collection $pagingParameters)
{
$pageName = $this->getPageKey();
$size = $this->getPerPage($pagingParameters) ?: $this->getDefaultPerPage($query);
$cols = $this->getColumns();
return $this->willSimplePaginate($query) ?
$query->simplePaginate($size, $cols, $pageName) :
$query->paginate($size, $cols, $pageName);
}
|
@param QueryBuilder|EloquentBuilder|Relation $query
@param Collection $pagingParameters
@return mixed
|
query
|
php
|
cloudcreativity/laravel-json-api
|
src/Pagination/StandardStrategy.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Pagination/StandardStrategy.php
|
Apache-2.0
|
public function getSelfSubUrl(?object $resource = null): string
{
if (!$resource) {
return '/' . $this->getResourceType();
}
return sprintf(
'/%s/%s/%s',
$resource->getResourceType(),
$this->getResourceType(),
$this->getId($resource)
);
}
|
@param AsynchronousProcess|object|null $resource
@return string
|
getSelfSubUrl
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/AsyncSchema.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/AsyncSchema.php
|
Apache-2.0
|
protected function resolveResourceType(): string
{
$api = property_exists($this, 'api') ? $this->api : null;
return json_api($api)->getJobs()->getResource();
}
|
Get the configured resource type.
@return string
|
resolveResourceType
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/AsyncSchema.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/AsyncSchema.php
|
Apache-2.0
|
public function setApi(string $api): ClientDispatch
{
$this->api = $api;
return $this;
}
|
Set the API that the job belongs to.
@param string $api
@return ClientDispatch
|
setApi
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/ClientDispatch.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/ClientDispatch.php
|
Apache-2.0
|
public function setResource(string $type, ?string $id = null): ClientDispatch
{
$this->resourceType = $type;
$this->resourceId = $id;
return $this;
}
|
Set the resource type and id that will be created/updated by the job.
@param string $type
@param string|null $id
@return ClientDispatch
|
setResource
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/ClientDispatch.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/ClientDispatch.php
|
Apache-2.0
|
public static function client(...$args): ClientDispatch
{
return new ClientDispatch(
new static(...$args)
);
}
|
Start a client dispatch.
@param mixed ...$args
@return ClientDispatch
|
client
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/ClientDispatchable.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/ClientDispatchable.php
|
Apache-2.0
|
public function wasClientDispatched(): bool
{
return !is_null($this->clientJob);
}
|
Was the job dispatched by a client?
@return bool
|
wasClientDispatched
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/ClientDispatchable.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/ClientDispatchable.php
|
Apache-2.0
|
public function api(): ?string
{
return optional($this->clientJob)->api;
}
|
Get the JSON API that the job belongs to.
@return string|null
|
api
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/ClientDispatchable.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/ClientDispatchable.php
|
Apache-2.0
|
public function resourceType(): ?string
{
return optional($this->clientJob)->resource_type;
}
|
Get the JSON API resource type that the job relates to.
@return string|null
|
resourceType
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/ClientDispatchable.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/ClientDispatchable.php
|
Apache-2.0
|
public function resourceId(): ?string
{
return optional($this->clientJob)->resource_id;
}
|
Get the JSON API resource id that the job relates to.
@return string|null
|
resourceId
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/ClientDispatchable.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/ClientDispatchable.php
|
Apache-2.0
|
public function didCreate($resource): void
{
if ($this->wasClientDispatched()) {
$this->clientJob->setResource($resource)->save();
}
}
|
Set the resource that was created by the job.
If a job is creating a new resource, this method can be used to update
the client job with the created resource. This method does nothing if the
job was not dispatched by a client.
@param $resource
@return void
|
didCreate
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/ClientDispatchable.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/ClientDispatchable.php
|
Apache-2.0
|
public function didComplete(bool $success = true): void
{
if ($this->wasClientDispatched()) {
$this->clientJob->completed($success);
}
}
|
Mark the client job as completed.
Although our queue listeners handle this for you in most cases, there
are some scenarios where it is not possible to do this. E.g. if your
job deletes a model that is one of its properties, a `ModelNotFoundException`
will be triggered when our listener deserializes the job.
Therefore this method is provided so that you can manually mark the
client job as completed, if needed.
@param bool $success
@return void
|
didComplete
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/ClientDispatchable.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/ClientDispatchable.php
|
Apache-2.0
|
public function setResource($resource): ClientJob
{
$schema = $this->getApi()->getContainer()->getSchema($resource);
$this->fill([
'resource_type' => $schema->getResourceType(),
'resource_id' => $schema->getId($resource),
]);
return $this;
}
|
Set the resource that the client job relates to.
@param mixed $resource
@return ClientJob
|
setResource
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/ClientJob.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/ClientJob.php
|
Apache-2.0
|
public function getResource()
{
if (!$this->resource_type || !$this->resource_id) {
return null;
}
return $this->getApi()->getStore()->find(
$this->resource_type,
(string) $this->resource_id
);
}
|
Get the resource that the process relates to.
@return mixed|null
|
getResource
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/ClientJob.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/ClientJob.php
|
Apache-2.0
|
public function handle($event): void
{
if (!$job = $this->deserialize($event->job)) {
return;
}
$clientJob = $job->clientJob ?? null;
if (!$clientJob instanceof AsynchronousProcess) {
return;
}
$clientJob->processed($event->job);
}
|
Handle the event.
@param JobProcessed|JobFailed $event
@return void
|
handle
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/UpdateClientProcess.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/UpdateClientProcess.php
|
Apache-2.0
|
private function deserialize(Job $job)
{
$data = $this->payload($job)['data'] ?? [];
$command = $data['command'] ?? null;
if (!is_string($command)) {
return null;
}
try {
return unserialize($command) ?: null;
} catch (ModelNotFoundException $ex) {
return null;
}
}
|
@param Job $job
@return mixed|null
|
deserialize
|
php
|
cloudcreativity/laravel-json-api
|
src/Queue/UpdateClientProcess.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Queue/UpdateClientProcess.php
|
Apache-2.0
|
protected function resolveName($unit, $name)
{
return $this->resolve($unit, $name);
}
|
Resolve a name that is not a resource type.
@param $unit
@param $name
@return string
|
resolveName
|
php
|
cloudcreativity/laravel-json-api
|
src/Resolver/AbstractResolver.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Resolver/AbstractResolver.php
|
Apache-2.0
|
private function flip(array $resources)
{
$all = [];
foreach ($resources as $resourceType => $types) {
foreach ((array) $types as $type) {
$all[$type] = $resourceType;
}
}
return $all;
}
|
Key the resource array by domain record type.
@param array $resources
@return array
|
flip
|
php
|
cloudcreativity/laravel-json-api
|
src/Resolver/AbstractResolver.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Resolver/AbstractResolver.php
|
Apache-2.0
|
public function __construct(ResolverInterface $api, ResolverInterface ...$packages)
{
$this->api = $api;
$this->packages = $packages;
}
|
AggregateResolver constructor.
@param ResolverInterface $api
@param ResolverInterface ...$packages
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Resolver/AggregateResolver.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Resolver/AggregateResolver.php
|
Apache-2.0
|
public function attach(ResolverInterface $resolver)
{
if ($this === $resolver) {
throw new RuntimeException('Cannot attach a resolver to itself.');
}
$this->packages[] = $resolver;
}
|
Attach a package resolver.
@param ResolverInterface $resolver
|
attach
|
php
|
cloudcreativity/laravel-json-api
|
src/Resolver/AggregateResolver.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Resolver/AggregateResolver.php
|
Apache-2.0
|
public function __construct($rootNamespace, array $resources, $byResource = true)
{
parent::__construct($resources);
$this->rootNamespace = $rootNamespace;
$this->byResource = $byResource;
}
|
NamespaceResolver constructor.
@param string $rootNamespace
@param array $resources
@param bool $byResource
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Resolver/NamespaceResolver.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Resolver/NamespaceResolver.php
|
Apache-2.0
|
protected function append($string)
{
$namespace = rtrim($this->rootNamespace, '\\');
return "{$namespace}\\{$string}";
}
|
Append the string to the root namespace.
@param $string
@return string
|
append
|
php
|
cloudcreativity/laravel-json-api
|
src/Resolver/NamespaceResolver.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Resolver/NamespaceResolver.php
|
Apache-2.0
|
public function __invoke($apiName, array $config)
{
$byResource = $config['by-resource'];
if ('false-0.x' === $byResource) {
throw new RuntimeException("The 'false-0.x' resolver option is no longer supported.");
}
return new NamespaceResolver(
$config['namespace'],
(array) $config['resources'],
(bool) $byResource
);
}
|
Create a resolver.
@param string $apiName
@param array $config
@return NamespaceResolver
|
__invoke
|
php
|
cloudcreativity/laravel-json-api
|
src/Resolver/ResolverFactory.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Resolver/ResolverFactory.php
|
Apache-2.0
|
public function __construct(Registrar $routes, Api $api, array $options = [])
{
// this maintains compatibility with passing attributes and options through as a single array.
$attrs = ['content-negotiator', 'processes', 'prefix', 'id'];
$this->routes = $routes;
$this->api = $api;
$this->options = collect($options)->only($attrs)->all();
$this->attributes = collect($options)->forget($attrs)->all();
}
|
ApiRegistration constructor.
@param Registrar $routes
@param Api $api
@param array $options
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ApiRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ApiRegistration.php
|
Apache-2.0
|
public function controllerResolver(Closure $callback): self
{
$this->options['controller_resolver'] = $callback;
return $this;
}
|
Use a callback to resolve a controller name for a resource.
@param Closure $callback
@return $this
|
controllerResolver
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ApiRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ApiRegistration.php
|
Apache-2.0
|
public function singularControllers(): self
{
return $this->controllerResolver(function (string $resourceType): string {
$singular = IlluminateStr::singular($resourceType);
return Str::classify($singular) . 'Controller';
});
}
|
Use singular resource names when resolving a controller name.
@return ApiRegistration
|
singularControllers
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ApiRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ApiRegistration.php
|
Apache-2.0
|
public function defaultContentNegotiator(string $negotiator): self
{
$this->options['content-negotiator'] = $negotiator;
return $this;
}
|
Set the default content negotiator.
@param string $negotiator
@return $this
|
defaultContentNegotiator
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ApiRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ApiRegistration.php
|
Apache-2.0
|
public function authorizer(string $authorizer): self
{
return $this->middleware("json-api.auth:{$authorizer}");
}
|
Set an authorizer for the entire API.
@param string $authorizer
@return $this
|
authorizer
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ApiRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ApiRegistration.php
|
Apache-2.0
|
public function middleware(string ...$middleware): self
{
$this->attributes['middleware'] = array_merge(
Arr::wrap($this->attributes['middleware'] ?? []),
$middleware
);
return $this;
}
|
Add middleware.
@param string ...$middleware
@return $this
|
middleware
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ApiRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ApiRegistration.php
|
Apache-2.0
|
public function __construct(Registrar $router, Repository $apiRepository)
{
$this->router = $router;
$this->apiRepository = $apiRepository;
$this->attributes = [];
}
|
ResourceRegistrar constructor.
@param Registrar $router
@param Repository $apiRepository
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/JsonApiRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/JsonApiRegistrar.php
|
Apache-2.0
|
public function api(string $apiName, $options = [], ?Closure $routes = null): ApiRegistration
{
if ($options instanceof Closure) {
$routes = $options;
$options = [];
}
$api = new ApiRegistration(
$this->router,
$this->apiRepository->createApi($apiName),
$options
);
if ($routes instanceof Closure) {
$api->routes($routes);
}
return $api;
}
|
@param string $apiName
@param array|Closure $options
@param Closure|null $routes
@return ApiRegistration
|
api
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/JsonApiRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/JsonApiRegistrar.php
|
Apache-2.0
|
private function idConstraint($url): ?string
{
if (!Str::contains($url, $this->resourceIdParameter())) {
return null;
}
return $this->options['id'] ?? null;
}
|
@param string $url
@return string|null
|
idConstraint
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RegistersResources.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RegistersResources.php
|
Apache-2.0
|
private function createRoute(string $method, string $uri, array $action): Route
{
/** @var Route $route */
$route = $this->router->{$method}($uri, $action);
$route->defaults(ResourceRegistrar::PARAM_RESOURCE_TYPE, $this->resourceType);
if ($idConstraint = $this->idConstraint($uri)) {
$route->where(ResourceRegistrar::PARAM_RESOURCE_ID, $idConstraint);
}
return $route;
}
|
@param string $method
@param string $uri
@param array $action
@return Route
|
createRoute
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RegistersResources.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RegistersResources.php
|
Apache-2.0
|
private function diffActions(array $defaults, array $options): array
{
if ($only = $options['only'] ?? null) {
return collect($defaults)->intersect($only)->all();
} elseif ($except = $options['except'] ?? null) {
return collect($defaults)->diff($except)->all();
}
return $defaults;
}
|
@param array $defaults
@param array $options
@return array
|
diffActions
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RegistersResources.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RegistersResources.php
|
Apache-2.0
|
public function readOnly(): self
{
return $this->only('related', 'read');
}
|
Make the relationship read-only.
This is a shorthand for only registering the `related` and `read` actions.
@return $this
|
readOnly
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipRegistration.php
|
Apache-2.0
|
public function __construct(Registrar $router, string $resourceType, array $options = [])
{
$this->router = $router;
$this->resourceType = $resourceType;
$this->options = $options;
}
|
RelationshipsRegistrar constructor.
@param Registrar $router
@param string $resourceType
@param array $options
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipsRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipsRegistrar.php
|
Apache-2.0
|
private function add(string $field, array $options): void
{
$inverse = $options['inverse'] ?? Str::plural($field);
$this->router->group([], function () use ($field, $options, $inverse) {
foreach ($options['actions'] as $action) {
$this->route($field, $action, $inverse, $options);
}
});
}
|
@param string $field
@param array $options
@return void
|
add
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipsRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipsRegistrar.php
|
Apache-2.0
|
private function route(string $field, string $action, string $inverse, array $options): Route
{
$route = $this->createRoute(
$this->methodForAction($action),
$this->urlForAction($field, $action, $options),
$this->actionForRoute($field, $action)
);
$route->defaults(ResourceRegistrar::PARAM_RELATIONSHIP_NAME, $field);
$route->defaults(ResourceRegistrar::PARAM_RELATIONSHIP_INVERSE_TYPE, $inverse);
return $route;
}
|
@param string $field
@param string $action
@param string $inverse
the inverse resource type
@param array $options
@return Route
|
route
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipsRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipsRegistrar.php
|
Apache-2.0
|
private function relatedUrl(string $relationship, array $options): string
{
return sprintf(
'%s/%s',
$this->resourceUrl(),
$options['relationship_uri'] ?? $relationship
);
}
|
@param string $relationship
@param array $options
@return string
|
relatedUrl
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipsRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipsRegistrar.php
|
Apache-2.0
|
private function relationshipUrl(string $relationship, array $options): string
{
return sprintf(
'%s/%s/%s',
$this->resourceUrl(),
ResourceRegistrar::KEYWORD_RELATIONSHIPS,
$options['relationship_uri'] ?? $relationship
);
}
|
@param string $relationship
@param array $options
@return string
|
relationshipUrl
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipsRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipsRegistrar.php
|
Apache-2.0
|
private function urlForAction(string $field, string $action, array $options): string
{
if ('related' === $action) {
return $this->relatedUrl($field, $options);
}
return $this->relationshipUrl($field, $options);
}
|
@param string $field
@param string $action
@param array $options
@return string
|
urlForAction
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipsRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipsRegistrar.php
|
Apache-2.0
|
private function nameForAction(string $field, string $action): string
{
$name = "relationships.{$field}";
if ('related' !== $action) {
$name .= ".{$action}";
}
return $name;
}
|
@param string $field
@param string $action
@return string
|
nameForAction
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipsRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipsRegistrar.php
|
Apache-2.0
|
private function actionForRoute(string $field, string $action): array
{
return [
'as' => $this->nameForAction($field, $action),
'uses' => $this->controllerAction($action),
];
}
|
@param string $field
@param string $action
@return array
|
actionForRoute
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipsRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipsRegistrar.php
|
Apache-2.0
|
public function __construct($hasOne = [], $hasMany = [])
{
$this->hasOne = $this->normalize($hasOne);
$this->hasMany = $this->normalize($hasMany);
}
|
RelationshipsRegistration constructor.
@param string|array|null $hasOne
@param string|array|null $hasMany
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipsRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipsRegistration.php
|
Apache-2.0
|
public function hasOne(string $field, ?string $inverse = null): RelationshipRegistration
{
$rel = $this->hasOne[$field] ?? new RelationshipRegistration();
if ($inverse) {
$rel->inverse($inverse);
}
return $this->hasOne[$field] = $rel;
}
|
@param string $field
@param string|null $inverse
@return RelationshipRegistration
|
hasOne
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipsRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipsRegistration.php
|
Apache-2.0
|
public function hasMany(string $field, ?string $inverse = null): RelationshipRegistration
{
$rel = $this->hasMany[$field] ?? new RelationshipRegistration();
if ($inverse) {
$rel->inverse($inverse);
}
return $this->hasMany[$field] = $rel;
}
|
@param string $field
@param string|null $inverse
@return RelationshipRegistration
|
hasMany
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipsRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipsRegistration.php
|
Apache-2.0
|
private function normalize($value): array
{
return collect(Arr::wrap($value ?: []))->mapWithKeys(function ($value, $key) {
if (is_numeric($key)) {
$key = $value;
$value = [];
}
return [$key => new RelationshipRegistration(Arr::wrap($value))];
})->all();
}
|
@param string|array|null $value
@return array
|
normalize
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/RelationshipsRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/RelationshipsRegistration.php
|
Apache-2.0
|
public function __construct(Registrar $router, string $resourceType, array $options = [], ?Closure $group = null)
{
$this->router = $router;
$this->resourceType = $resourceType;
$this->options = $options;
$this->group = $group;
}
|
ResourceGroup constructor.
@param Registrar $router
@param string $resourceType
@param array $options
@param Closure|null $group
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ResourceRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ResourceRegistrar.php
|
Apache-2.0
|
private function registerProcesses(): void
{
$this->routeForProcess(
'get',
$this->baseProcessUrl(),
$this->actionForRoute('processes')
);
$this->routeForProcess(
'get',
$this->processUrl(),
$this->actionForRoute('process')
);
}
|
Add routes for async processes.
@return void
|
registerProcesses
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ResourceRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ResourceRegistrar.php
|
Apache-2.0
|
private function idConstraintForProcess(string $uri): ?string
{
if (!Str::contains($uri, $this->processIdParameter())) {
return null;
}
return $this->options['async_id'] ?? Uuid::VALID_PATTERN;
}
|
@param string $uri
@return string|null
|
idConstraintForProcess
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ResourceRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ResourceRegistrar.php
|
Apache-2.0
|
private function routeForProcess(string $method, string $uri, array $action): Route
{
/** @var Route $route */
$route = $this->router->{$method}($uri, $action);
$route->defaults(ResourceRegistrar::PARAM_RESOURCE_TYPE, $this->resourceType);
$route->defaults(ResourceRegistrar::PARAM_PROCESS_TYPE, $this->processType());
if ($constraint = $this->idConstraintForProcess($uri)) {
$route->where(ResourceRegistrar::PARAM_PROCESS_ID, $constraint);
}
return $route;
}
|
@param string $method
@param string $uri
@param array $action
@return Route
|
routeForProcess
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ResourceRegistrar.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ResourceRegistrar.php
|
Apache-2.0
|
public function __construct(Registrar $router, string $resourceType, array $options = [])
{
$this->router = $router;
$this->resourceType = $resourceType;
$this->registered = false;
$this->options = collect($options)
->forget(['has-one', 'has-many'])
->all();
if (isset($options['controller']) && true === $options['controller']) {
$this->controller();
}
$this->relationships = new RelationshipsRegistration(
$options['has-one'] ?? null,
$options['has-many'] ?? null
);
}
|
ResourceRegistration constructor.
@param Registrar $router
@param string $resourceType
@param array $options
|
__construct
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ResourceRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ResourceRegistration.php
|
Apache-2.0
|
public function authorizer(string $authorizer): self
{
return $this->middleware("json-api.auth:{$authorizer}");
}
|
Set an authorizer for the resource.
@param string $authorizer
@return $this
|
authorizer
|
php
|
cloudcreativity/laravel-json-api
|
src/Routing/ResourceRegistration.php
|
https://github.com/cloudcreativity/laravel-json-api/blob/master/src/Routing/ResourceRegistration.php
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.