vendor and env first commit
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\QueryBuilder\Exceptions;
|
||||
|
||||
use BadMethodCallException;
|
||||
|
||||
class AllowedFieldsMustBeCalledBeforeAllowedIncludes extends BadMethodCallException
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("The QueryBuilder's `allowedFields` method must be called before the `allowedIncludes` method.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\QueryBuilder\Exceptions;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class InvalidAppendQuery extends InvalidQuery
|
||||
{
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
public $appendsNotAllowed;
|
||||
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
public $allowedAppends;
|
||||
|
||||
public function __construct(Collection $appendsNotAllowed, Collection $allowedAppends)
|
||||
{
|
||||
$this->appendsNotAllowed = $appendsNotAllowed;
|
||||
$this->allowedAppends = $allowedAppends;
|
||||
|
||||
$appendsNotAllowed = $appendsNotAllowed->implode(', ');
|
||||
$allowedAppends = $allowedAppends->implode(', ');
|
||||
$message = "Requested append(s) `{$appendsNotAllowed}` are not allowed. Allowed append(s) are `{$allowedAppends}`.";
|
||||
|
||||
parent::__construct(Response::HTTP_BAD_REQUEST, $message);
|
||||
}
|
||||
|
||||
public static function appendsNotAllowed(Collection $appendsNotAllowed, Collection $allowedAppends)
|
||||
{
|
||||
return new static(...func_get_args());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\QueryBuilder\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Spatie\QueryBuilder\Enums\SortDirection;
|
||||
|
||||
class InvalidDirection extends Exception
|
||||
{
|
||||
public static function make(string $sort)
|
||||
{
|
||||
return new static('The direction should be either `'.SortDirection::DESCENDING.'` or `'.SortDirection::ASCENDING)."`. {$sort} given.";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\QueryBuilder\Exceptions;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class InvalidFieldQuery extends InvalidQuery
|
||||
{
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
public $unknownFields;
|
||||
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
public $allowedFields;
|
||||
|
||||
public function __construct(Collection $unknownFields, Collection $allowedFields)
|
||||
{
|
||||
$this->unknownFields = $unknownFields;
|
||||
$this->allowedFields = $allowedFields;
|
||||
|
||||
$unknownFields = $unknownFields->implode(', ');
|
||||
$allowedFields = $allowedFields->implode(', ');
|
||||
$message = "Requested field(s) `{$unknownFields}` are not allowed. Allowed field(s) are `{$allowedFields}`.";
|
||||
|
||||
parent::__construct(Response::HTTP_BAD_REQUEST, $message);
|
||||
}
|
||||
|
||||
public static function fieldsNotAllowed(Collection $unknownFields, Collection $allowedFields)
|
||||
{
|
||||
return new static(...func_get_args());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\QueryBuilder\Exceptions;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class InvalidFilterQuery extends InvalidQuery
|
||||
{
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
public $unknownFilters;
|
||||
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
public $allowedFilters;
|
||||
|
||||
public function __construct(Collection $unknownFilters, Collection $allowedFilters)
|
||||
{
|
||||
$this->unknownFilters = $unknownFilters;
|
||||
$this->allowedFilters = $allowedFilters;
|
||||
|
||||
$unknownFilters = $this->unknownFilters->implode(', ');
|
||||
$allowedFilters = $this->allowedFilters->implode(', ');
|
||||
$message = "Requested filter(s) `{$unknownFilters}` are not allowed. Allowed filter(s) are `{$allowedFilters}`.";
|
||||
|
||||
parent::__construct(Response::HTTP_BAD_REQUEST, $message);
|
||||
}
|
||||
|
||||
public static function filtersNotAllowed(Collection $unknownFilters, Collection $allowedFilters)
|
||||
{
|
||||
return new static(...func_get_args());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\QueryBuilder\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidFilterValue extends Exception
|
||||
{
|
||||
public static function make($value)
|
||||
{
|
||||
return new static("Filter value `{$value}` is invalid.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\QueryBuilder\Exceptions;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class InvalidIncludeQuery extends InvalidQuery
|
||||
{
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
public $unknownIncludes;
|
||||
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
public $allowedIncludes;
|
||||
|
||||
public function __construct(Collection $unknownIncludes, Collection $allowedIncludes)
|
||||
{
|
||||
$this->unknownIncludes = $unknownIncludes;
|
||||
$this->allowedIncludes = $allowedIncludes;
|
||||
|
||||
$unknownIncludes = $unknownIncludes->implode(', ');
|
||||
|
||||
$message = "Requested include(s) `{$unknownIncludes}` are not allowed. ";
|
||||
|
||||
if ($allowedIncludes->count()) {
|
||||
$allowedIncludes = $allowedIncludes->implode(', ');
|
||||
$message .= "Allowed include(s) are `{$allowedIncludes}`.";
|
||||
} else {
|
||||
$message .= 'There are no allowed includes.';
|
||||
}
|
||||
|
||||
parent::__construct(Response::HTTP_BAD_REQUEST, $message);
|
||||
}
|
||||
|
||||
public static function includesNotAllowed(Collection $unknownIncludes, Collection $allowedIncludes)
|
||||
{
|
||||
return new static(...func_get_args());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\QueryBuilder\Exceptions;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
abstract class InvalidQuery extends HttpException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\QueryBuilder\Exceptions;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class InvalidSortQuery extends InvalidQuery
|
||||
{
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
public $unknownSorts;
|
||||
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
public $allowedSorts;
|
||||
|
||||
public function __construct(Collection $unknownSorts, Collection $allowedSorts)
|
||||
{
|
||||
$this->unknownSorts = $unknownSorts;
|
||||
$this->allowedSorts = $allowedSorts;
|
||||
|
||||
$allowedSorts = $allowedSorts->implode(', ');
|
||||
$unknownSorts = $unknownSorts->implode(', ');
|
||||
$message = "Requested sort(s) `{$unknownSorts}` is not allowed. Allowed sort(s) are `{$allowedSorts}`.";
|
||||
|
||||
parent::__construct(Response::HTTP_BAD_REQUEST, $message);
|
||||
}
|
||||
|
||||
public static function sortsNotAllowed(Collection $unknownSorts, Collection $allowedSorts)
|
||||
{
|
||||
return new static(...func_get_args());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\QueryBuilder\Exceptions;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class InvalidSubject extends InvalidArgumentException
|
||||
{
|
||||
public static function make($subject)
|
||||
{
|
||||
return new static(
|
||||
sprintf(
|
||||
'Subject %s is invalid.',
|
||||
is_object($subject)
|
||||
? sprintf('class `%s`', get_class($subject))
|
||||
: sprintf('type `%s`', gettype($subject))
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\QueryBuilder\Exceptions;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class UnknownIncludedFieldsQuery extends InvalidQuery
|
||||
{
|
||||
/** @var \Illuminate\Support\Collection */
|
||||
public $unknownFields;
|
||||
|
||||
public function __construct(array $unknownFields)
|
||||
{
|
||||
$this->unknownFields = collect($unknownFields);
|
||||
|
||||
$unknownFields = $this->unknownFields->implode(', ');
|
||||
|
||||
$message = "Requested field(s) `{$unknownFields}` are not allowed (yet). ";
|
||||
$message .= "If you want to allow these fields, please make sure to call the QueryBuilder's `allowedFields` method before the `allowedIncludes` method.";
|
||||
|
||||
parent::__construct(Response::HTTP_BAD_REQUEST, $message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user