mirror of
https://github.com/flarum/core.git
synced 2025-08-06 00:17:31 +02:00
Apply fixes from StyleCI
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
namespace Flarum\Sticky\Api;
|
namespace Flarum\Sticky\Api;
|
||||||
|
|
||||||
use Flarum\Api\Context;
|
use Flarum\Api\Context;
|
||||||
use Flarum\Api\Endpoint\Update;
|
|
||||||
use Flarum\Api\Schema;
|
use Flarum\Api\Schema;
|
||||||
use Flarum\Discussion\Discussion;
|
use Flarum\Discussion\Discussion;
|
||||||
use Flarum\Sticky\Event\DiscussionWasStickied;
|
use Flarum\Sticky\Event\DiscussionWasStickied;
|
||||||
|
@@ -136,6 +136,7 @@ class Context extends BaseContext
|
|||||||
{
|
{
|
||||||
$new = parent::withRequest($request);
|
$new = parent::withRequest($request);
|
||||||
$new->requestIncludes = null;
|
$new->requestIncludes = null;
|
||||||
|
|
||||||
return $new;
|
return $new;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +144,7 @@ class Context extends BaseContext
|
|||||||
{
|
{
|
||||||
$new = clone $this;
|
$new = clone $this;
|
||||||
$new->modelId = $id;
|
$new->modelId = $id;
|
||||||
|
|
||||||
return $new;
|
return $new;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,15 +152,16 @@ class Context extends BaseContext
|
|||||||
{
|
{
|
||||||
$new = clone $this;
|
$new = clone $this;
|
||||||
$new->requestIncludes = $requestIncludes;
|
$new->requestIncludes = $requestIncludes;
|
||||||
|
|
||||||
return $new;
|
return $new;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function extractIdFromPath(\Tobyz\JsonApiServer\Context $context): ?string
|
public function extractIdFromPath(\Tobyz\JsonApiServer\Context $context): ?string
|
||||||
{
|
{
|
||||||
$currentPath = trim($context->path(), '/');
|
$currentPath = trim($context->path(), '/');
|
||||||
$path = trim($context->collection->name() . $this->endpoint->path, '/');
|
$path = trim($context->collection->name().$this->endpoint->path, '/');
|
||||||
|
|
||||||
if (!str_contains($path, '{id}')) {
|
if (! str_contains($path, '{id}')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,15 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Endpoint\Concerns;
|
namespace Flarum\Api\Endpoint\Concerns;
|
||||||
|
|
||||||
use Flarum\Api\Resource\AbstractDatabaseResource;
|
use Flarum\Api\Resource\AbstractDatabaseResource;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Tobyz\JsonApiServer\Context;
|
use Tobyz\JsonApiServer\Context;
|
||||||
use Tobyz\JsonApiServer\Laravel\EloquentResource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is directed at eager loading relationships apart from the request includes.
|
* This is directed at eager loading relationships apart from the request includes.
|
||||||
@@ -108,7 +113,7 @@ trait HasEagerLoading
|
|||||||
|
|
||||||
foreach ($relations as $relation) {
|
foreach ($relations as $relation) {
|
||||||
if (isset($addedRelationWhere[$relation])) {
|
if (isset($addedRelationWhere[$relation])) {
|
||||||
$whereRelations[$relation] = $addedRelationWhere[$relation];;
|
$whereRelations[$relation] = $addedRelationWhere[$relation];
|
||||||
} else {
|
} else {
|
||||||
$simpleRelations[] = $relation;
|
$simpleRelations[] = $relation;
|
||||||
}
|
}
|
||||||
@@ -186,7 +191,7 @@ trait HasEagerLoading
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* From format of: 'relation' => [ ...nested ] to ['relation', 'relation.nested']
|
* From format of: 'relation' => [ ...nested ] to ['relation', 'relation.nested'].
|
||||||
*/
|
*/
|
||||||
private function stringInclude(array $include): array
|
private function stringInclude(array $include): array
|
||||||
{
|
{
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Endpoint\Concerns;
|
namespace Flarum\Api\Endpoint\Concerns;
|
||||||
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Endpoint\Concerns;
|
namespace Flarum\Api\Endpoint\Concerns;
|
||||||
|
|
||||||
trait IncludesData
|
trait IncludesData
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Endpoint\Concerns;
|
namespace Flarum\Api\Endpoint\Concerns;
|
||||||
|
|
||||||
use Illuminate\Contracts\Validation\Validator;
|
use Illuminate\Contracts\Validation\Validator;
|
||||||
@@ -105,13 +112,13 @@ trait SavesAndValidatesData
|
|||||||
{
|
{
|
||||||
$body = (array) $context->body();
|
$body = (array) $context->body();
|
||||||
|
|
||||||
if (!isset($body['data']) || !is_array($body['data'])) {
|
if (! isset($body['data']) || ! is_array($body['data'])) {
|
||||||
throw (new BadRequestException('data must be an object'))->setSource([
|
throw (new BadRequestException('data must be an object'))->setSource([
|
||||||
'pointer' => '/data',
|
'pointer' => '/data',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($body['data']['type'])) {
|
if (! isset($body['data']['type'])) {
|
||||||
if (isset($context->collection->resources()[0])) {
|
if (isset($context->collection->resources()[0])) {
|
||||||
$body['data']['type'] = $context->collection->resources()[0];
|
$body['data']['type'] = $context->collection->resources()[0];
|
||||||
} else {
|
} else {
|
||||||
@@ -140,19 +147,19 @@ trait SavesAndValidatesData
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array($body['data']['type'], $context->collection->resources())) {
|
if (! in_array($body['data']['type'], $context->collection->resources())) {
|
||||||
throw (new ConflictException(
|
throw (new ConflictException(
|
||||||
'collection does not support this resource type',
|
'collection does not support this resource type',
|
||||||
))->setSource(['pointer' => '/data/type']);
|
))->setSource(['pointer' => '/data/type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('attributes', $body['data']) && !is_array($body['data']['attributes'])) {
|
if (array_key_exists('attributes', $body['data']) && ! is_array($body['data']['attributes'])) {
|
||||||
throw (new BadRequestException('data.attributes must be an object'))->setSource([
|
throw (new BadRequestException('data.attributes must be an object'))->setSource([
|
||||||
'pointer' => '/data/attributes',
|
'pointer' => '/data/attributes',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('relationships', $body['data']) && !is_array($body['data']['relationships'])) {
|
if (array_key_exists('relationships', $body['data']) && ! is_array($body['data']['relationships'])) {
|
||||||
throw (new BadRequestException('data.relationships must be an object'))->setSource([
|
throw (new BadRequestException('data.relationships must be an object'))->setSource([
|
||||||
'pointer' => '/data/relationships',
|
'pointer' => '/data/relationships',
|
||||||
]);
|
]);
|
||||||
|
@@ -18,6 +18,7 @@ use Flarum\Database\Eloquent\Collection;
|
|||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Tobyz\JsonApiServer\Endpoint\Concerns\ShowsResources;
|
use Tobyz\JsonApiServer\Endpoint\Concerns\ShowsResources;
|
||||||
use Tobyz\JsonApiServer\Resource\Creatable;
|
use Tobyz\JsonApiServer\Resource\Creatable;
|
||||||
|
|
||||||
use function Tobyz\JsonApiServer\has_value;
|
use function Tobyz\JsonApiServer\has_value;
|
||||||
use function Tobyz\JsonApiServer\json_api_response;
|
use function Tobyz\JsonApiServer\json_api_response;
|
||||||
use function Tobyz\JsonApiServer\set_value;
|
use function Tobyz\JsonApiServer\set_value;
|
||||||
@@ -45,7 +46,7 @@ class Create extends Endpoint
|
|||||||
|
|
||||||
$collection = $context->collection;
|
$collection = $context->collection;
|
||||||
|
|
||||||
if (!$collection instanceof Creatable) {
|
if (! $collection instanceof Creatable) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
sprintf('%s must implement %s', get_class($collection), Creatable::class),
|
sprintf('%s must implement %s', get_class($collection), Creatable::class),
|
||||||
);
|
);
|
||||||
@@ -84,7 +85,7 @@ class Create extends Endpoint
|
|||||||
final protected function fillDefaultValues(Context $context, array &$data): void
|
final protected function fillDefaultValues(Context $context, array &$data): void
|
||||||
{
|
{
|
||||||
foreach ($context->fields($context->resource) as $field) {
|
foreach ($context->fields($context->resource) as $field) {
|
||||||
if (!has_value($data, $field) && ($default = $field->default)) {
|
if (! has_value($data, $field) && ($default = $field->default)) {
|
||||||
set_value($data, $field, $default($context->withField($field)));
|
set_value($data, $field, $default($context->withField($field)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,7 @@ use Nyholm\Psr7\Response;
|
|||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Tobyz\JsonApiServer\Resource\Deletable;
|
use Tobyz\JsonApiServer\Resource\Deletable;
|
||||||
use Tobyz\JsonApiServer\Schema\Concerns\HasMeta;
|
use Tobyz\JsonApiServer\Schema\Concerns\HasMeta;
|
||||||
|
|
||||||
use function Tobyz\JsonApiServer\json_api_response;
|
use function Tobyz\JsonApiServer\json_api_response;
|
||||||
|
|
||||||
class Delete extends Endpoint
|
class Delete extends Endpoint
|
||||||
@@ -39,7 +40,7 @@ class Delete extends Endpoint
|
|||||||
$resource = $context->resource($context->collection->resource($model, $context)),
|
$resource = $context->resource($context->collection->resource($model, $context)),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!$resource instanceof Deletable) {
|
if (! $resource instanceof Deletable) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
sprintf('%s must implement %s', get_class($resource), Deletable::class),
|
sprintf('%s must implement %s', get_class($resource), Deletable::class),
|
||||||
);
|
);
|
||||||
|
@@ -21,6 +21,7 @@ use Tobyz\JsonApiServer\Endpoint\Concerns\FindsResources;
|
|||||||
use Tobyz\JsonApiServer\Endpoint\Concerns\ShowsResources;
|
use Tobyz\JsonApiServer\Endpoint\Concerns\ShowsResources;
|
||||||
use Tobyz\JsonApiServer\Exception\ForbiddenException;
|
use Tobyz\JsonApiServer\Exception\ForbiddenException;
|
||||||
use Tobyz\JsonApiServer\Exception\MethodNotAllowedException;
|
use Tobyz\JsonApiServer\Exception\MethodNotAllowedException;
|
||||||
|
|
||||||
use function Tobyz\JsonApiServer\json_api_response;
|
use function Tobyz\JsonApiServer\json_api_response;
|
||||||
|
|
||||||
class Endpoint implements EndpointInterface
|
class Endpoint implements EndpointInterface
|
||||||
@@ -81,7 +82,7 @@ class Endpoint implements EndpointInterface
|
|||||||
public function route(string $method, string $path): static
|
public function route(string $method, string $path): static
|
||||||
{
|
{
|
||||||
$this->method = $method;
|
$this->method = $method;
|
||||||
$this->path = '/' . ltrim(rtrim($path, '/'), '/');
|
$this->path = '/'.ltrim(rtrim($path, '/'), '/');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -96,7 +97,7 @@ class Endpoint implements EndpointInterface
|
|||||||
public function process(Context $context): mixed
|
public function process(Context $context): mixed
|
||||||
{
|
{
|
||||||
if (! $this->action) {
|
if (! $this->action) {
|
||||||
throw new RuntimeException("No action defined for endpoint [".static::class."]");
|
throw new RuntimeException('No action defined for endpoint ['.static::class.']');
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($this->action)($context);
|
return ($this->action)($context);
|
||||||
@@ -108,7 +109,7 @@ class Endpoint implements EndpointInterface
|
|||||||
public function handle(\Tobyz\JsonApiServer\Context $context): ?Response
|
public function handle(\Tobyz\JsonApiServer\Context $context): ?Response
|
||||||
{
|
{
|
||||||
if (! isset($this->method, $this->path)) {
|
if (! isset($this->method, $this->path)) {
|
||||||
throw new RuntimeException("No route defined for endpoint [".static::class."]");
|
throw new RuntimeException('No route defined for endpoint ['.static::class.']');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strtolower($context->method()) !== strtolower($this->method)) {
|
if (strtolower($context->method()) !== strtolower($this->method)) {
|
||||||
@@ -125,7 +126,7 @@ class Endpoint implements EndpointInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->isVisible($context)) {
|
if (! $this->isVisible($context)) {
|
||||||
throw new ForbiddenException();
|
throw new ForbiddenException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,6 +29,7 @@ use Tobyz\JsonApiServer\Pagination\OffsetPagination;
|
|||||||
use Tobyz\JsonApiServer\Pagination\Pagination;
|
use Tobyz\JsonApiServer\Pagination\Pagination;
|
||||||
use Tobyz\JsonApiServer\Schema\Concerns\HasMeta;
|
use Tobyz\JsonApiServer\Schema\Concerns\HasMeta;
|
||||||
use Tobyz\JsonApiServer\Serializer;
|
use Tobyz\JsonApiServer\Serializer;
|
||||||
|
|
||||||
use function Tobyz\JsonApiServer\apply_filters;
|
use function Tobyz\JsonApiServer\apply_filters;
|
||||||
use function Tobyz\JsonApiServer\json_api_response;
|
use function Tobyz\JsonApiServer\json_api_response;
|
||||||
use function Tobyz\JsonApiServer\parse_sort_string;
|
use function Tobyz\JsonApiServer\parse_sort_string;
|
||||||
@@ -49,7 +50,7 @@ class Index extends Endpoint
|
|||||||
{
|
{
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
|
|
||||||
$this->paginationResolver = fn() => null;
|
$this->paginationResolver = fn () => null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function make(?string $name = null): static
|
public static function make(?string $name = null): static
|
||||||
@@ -111,7 +112,7 @@ class Index extends Endpoint
|
|||||||
|
|
||||||
$collection = $context->collection;
|
$collection = $context->collection;
|
||||||
|
|
||||||
if (!$collection instanceof Listable) {
|
if (! $collection instanceof Listable) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
sprintf('%s must implement %s', get_class($collection), Listable::class),
|
sprintf('%s must implement %s', get_class($collection), Listable::class),
|
||||||
);
|
);
|
||||||
@@ -144,7 +145,7 @@ class Index extends Endpoint
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
$collection instanceof Countable &&
|
$collection instanceof Countable &&
|
||||||
!is_null($total = $collection->count($query, $context))
|
! is_null($total = $collection->count($query, $context))
|
||||||
) {
|
) {
|
||||||
$meta['page']['total'] = $total;
|
$meta['page']['total'] = $total;
|
||||||
}
|
}
|
||||||
@@ -199,7 +200,7 @@ class Index extends Endpoint
|
|||||||
|
|
||||||
final protected function applySorts($query, Context $context): void
|
final protected function applySorts($query, Context $context): void
|
||||||
{
|
{
|
||||||
if (!($sortString = $context->queryParam('sort', $this->defaultSort))) {
|
if (! ($sortString = $context->queryParam('sort', $this->defaultSort))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,11 +222,11 @@ class Index extends Endpoint
|
|||||||
|
|
||||||
final protected function applyFilters($query, Context $context): void
|
final protected function applyFilters($query, Context $context): void
|
||||||
{
|
{
|
||||||
if (!($filters = $context->queryParam('filter'))) {
|
if (! ($filters = $context->queryParam('filter'))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($filters)) {
|
if (! is_array($filters)) {
|
||||||
throw (new BadRequestException('filter must be an array'))->setSource([
|
throw (new BadRequestException('filter must be an array'))->setSource([
|
||||||
'parameter' => 'filter',
|
'parameter' => 'filter',
|
||||||
]);
|
]);
|
||||||
|
@@ -42,7 +42,7 @@ class Update extends Endpoint
|
|||||||
$resource = $context->resource($context->collection->resource($model, $context)),
|
$resource = $context->resource($context->collection->resource($model, $context)),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!$resource instanceof Updatable) {
|
if (! $resource instanceof Updatable) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
sprintf('%s must implement %s', get_class($resource), Updatable::class),
|
sprintf('%s must implement %s', get_class($resource), Updatable::class),
|
||||||
);
|
);
|
||||||
|
@@ -17,13 +17,11 @@ use Laminas\Diactoros\ServerRequestFactory;
|
|||||||
use Laminas\Diactoros\Uri;
|
use Laminas\Diactoros\Uri;
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
use Tobyz\JsonApiServer\Endpoint\Endpoint;
|
|
||||||
use Tobyz\JsonApiServer\Exception\BadRequestException;
|
use Tobyz\JsonApiServer\Exception\BadRequestException;
|
||||||
use Tobyz\JsonApiServer\Exception\ResourceNotFoundException;
|
use Tobyz\JsonApiServer\Exception\ResourceNotFoundException;
|
||||||
use Tobyz\JsonApiServer\JsonApi as BaseJsonApi;
|
use Tobyz\JsonApiServer\JsonApi as BaseJsonApi;
|
||||||
use Tobyz\JsonApiServer\Resource\Collection;
|
use Tobyz\JsonApiServer\Resource\Collection;
|
||||||
use Tobyz\JsonApiServer\Resource\Resource;
|
use Tobyz\JsonApiServer\Resource\Resource;
|
||||||
use Tobyz\JsonApiServer\Schema\Field\Field;
|
|
||||||
|
|
||||||
class JsonApi extends BaseJsonApi
|
class JsonApi extends BaseJsonApi
|
||||||
{
|
{
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Resource\Contracts;
|
namespace Flarum\Api\Resource\Contracts;
|
||||||
|
|
||||||
use Tobyz\JsonApiServer\Resource\Attachable as AttachableContract;
|
use Tobyz\JsonApiServer\Resource\Attachable as AttachableContract;
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Resource\Contracts;
|
namespace Flarum\Api\Resource\Contracts;
|
||||||
|
|
||||||
use Tobyz\JsonApiServer\Context;
|
use Tobyz\JsonApiServer\Context;
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Resource\Contracts;
|
namespace Flarum\Api\Resource\Contracts;
|
||||||
|
|
||||||
use Tobyz\JsonApiServer\Resource\Creatable as CreatableContract;
|
use Tobyz\JsonApiServer\Resource\Creatable as CreatableContract;
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Resource\Contracts;
|
namespace Flarum\Api\Resource\Contracts;
|
||||||
|
|
||||||
use Tobyz\JsonApiServer\Resource\Deletable as DeletableContract;
|
use Tobyz\JsonApiServer\Resource\Deletable as DeletableContract;
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Resource\Contracts;
|
namespace Flarum\Api\Resource\Contracts;
|
||||||
|
|
||||||
use Tobyz\JsonApiServer\Resource\Findable as FindableContract;
|
use Tobyz\JsonApiServer\Resource\Findable as FindableContract;
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Resource\Contracts;
|
namespace Flarum\Api\Resource\Contracts;
|
||||||
|
|
||||||
use Tobyz\JsonApiServer\Context;
|
use Tobyz\JsonApiServer\Context;
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Resource\Contracts;
|
namespace Flarum\Api\Resource\Contracts;
|
||||||
|
|
||||||
use Tobyz\JsonApiServer\Resource\Paginatable as PaginatableContract;
|
use Tobyz\JsonApiServer\Resource\Paginatable as PaginatableContract;
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Resource\Contracts;
|
namespace Flarum\Api\Resource\Contracts;
|
||||||
|
|
||||||
use Tobyz\JsonApiServer\Resource\Updatable as UpdatableContract;
|
use Tobyz\JsonApiServer\Resource\Updatable as UpdatableContract;
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Resource;
|
namespace Flarum\Api\Resource;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
@@ -8,7 +15,6 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
use Tobyz\JsonApiServer\Context;
|
use Tobyz\JsonApiServer\Context;
|
||||||
use Tobyz\JsonApiServer\Laravel\EloquentResource;
|
|
||||||
use Tobyz\JsonApiServer\Laravel\Field\ToMany;
|
use Tobyz\JsonApiServer\Laravel\Field\ToMany;
|
||||||
use Tobyz\JsonApiServer\Laravel\Field\ToOne;
|
use Tobyz\JsonApiServer\Laravel\Field\ToOne;
|
||||||
use Tobyz\JsonApiServer\Schema\Field\Relationship;
|
use Tobyz\JsonApiServer\Schema\Field\Relationship;
|
||||||
@@ -42,13 +48,11 @@ abstract class EloquentBuffer
|
|||||||
Context $context,
|
Context $context,
|
||||||
?array $aggregate = null,
|
?array $aggregate = null,
|
||||||
): void {
|
): void {
|
||||||
if (!($models = static::getBuffer($model, $relationName, $aggregate))) {
|
if (! ($models = static::getBuffer($model, $relationName, $aggregate))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$loader = function ($relation) use (
|
$loader = function ($relation) use (
|
||||||
$model,
|
|
||||||
$relationName,
|
|
||||||
$relationship,
|
$relationship,
|
||||||
$context,
|
$context,
|
||||||
$aggregate,
|
$aggregate,
|
||||||
@@ -74,8 +78,8 @@ abstract class EloquentBuffer
|
|||||||
foreach ($resources as $resource) {
|
foreach ($resources as $resource) {
|
||||||
$modelClass = get_class($resource->newModel($context));
|
$modelClass = get_class($resource->newModel($context));
|
||||||
|
|
||||||
if ($resource instanceof AbstractDatabaseResource && !isset($constrain[$modelClass])) {
|
if ($resource instanceof AbstractDatabaseResource && ! isset($constrain[$modelClass])) {
|
||||||
$constrain[$modelClass] = function (Builder $query) use ($resource, $context, $relationship, $relation, $aggregate) {
|
$constrain[$modelClass] = function (Builder $query) use ($resource, $context, $relationship, $aggregate) {
|
||||||
if (! $aggregate) {
|
if (! $aggregate) {
|
||||||
$query
|
$query
|
||||||
->with($context->endpoint->getEagerLoadsFor($relationship->name, $context))
|
->with($context->endpoint->getEagerLoadsFor($relationship->name, $context))
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Schema\Concerns;
|
namespace Flarum\Api\Schema\Concerns;
|
||||||
|
|
||||||
use Flarum\Api\Context;
|
use Flarum\Api\Context;
|
||||||
@@ -13,7 +20,7 @@ trait FlarumField
|
|||||||
*/
|
*/
|
||||||
public function writableOnCreate(): static
|
public function writableOnCreate(): static
|
||||||
{
|
{
|
||||||
$this->writable = fn($model, Context $context) => $context->creating();
|
$this->writable = fn ($model, Context $context) => $context->creating();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -23,7 +30,7 @@ trait FlarumField
|
|||||||
*/
|
*/
|
||||||
public function writableOnUpdate(): static
|
public function writableOnUpdate(): static
|
||||||
{
|
{
|
||||||
$this->writable = fn($model, Context $context) => $context->updating();
|
$this->writable = fn ($model, Context $context) => $context->updating();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Schema\Concerns;
|
namespace Flarum\Api\Schema\Concerns;
|
||||||
|
|
||||||
trait FlarumRelationship
|
trait FlarumRelationship
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Schema\Concerns;
|
namespace Flarum\Api\Schema\Concerns;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
@@ -1,9 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Schema\Concerns;
|
namespace Flarum\Api\Schema\Concerns;
|
||||||
|
|
||||||
use Flarum\Api\Context;
|
use Flarum\Api\Context;
|
||||||
use Tobyz\JsonApiServer\Endpoint\Update;
|
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
trait HasValidationRules
|
trait HasValidationRules
|
||||||
@@ -106,12 +112,12 @@ trait HasValidationRules
|
|||||||
|
|
||||||
public function requiredWith(array $fields, bool|callable $condition): static
|
public function requiredWith(array $fields, bool|callable $condition): static
|
||||||
{
|
{
|
||||||
return $this->rule('required_with:' . implode(',', $fields), $condition);
|
return $this->rule('required_with:'.implode(',', $fields), $condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requiredWithout(array $fields, bool|callable $condition): static
|
public function requiredWithout(array $fields, bool|callable $condition): static
|
||||||
{
|
{
|
||||||
return $this->rule('required_without:' . implode(',', $fields), $condition);
|
return $this->rule('required_without:'.implode(',', $fields), $condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requiredOnCreateWith(array $fields): static
|
public function requiredOnCreateWith(array $fields): static
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Schema\Contracts;
|
namespace Flarum\Api\Schema\Contracts;
|
||||||
|
|
||||||
interface RelationAggregator
|
interface RelationAggregator
|
||||||
|
@@ -25,7 +25,7 @@ class ToOne extends BaseToOne
|
|||||||
return ($this->deserializer)($value, $context);
|
return ($this->deserializer)($value, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($value) || !array_key_exists('data', $value)) {
|
if (! is_array($value) || ! array_key_exists('data', $value)) {
|
||||||
throw new BadRequestException('relationship does not include data key');
|
throw new BadRequestException('relationship does not include data key');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
namespace Flarum\Api\Sort;
|
namespace Flarum\Api\Sort;
|
||||||
|
|
||||||
use Tobyz\JsonApiServer\Laravel\Sort\SortWithCount as BaseSortWithCount;
|
use Tobyz\JsonApiServer\Laravel\Sort\SortWithCount as BaseSortWithCount;
|
||||||
|
Reference in New Issue
Block a user