From 2364b28262e4078b0e4c290c92761fb8897bb50d Mon Sep 17 00:00:00 2001 From: Alex Vanderbist Date: Tue, 12 Sep 2023 10:50:09 +0200 Subject: [PATCH] Add default values for all config values This is usefull when QueryBuilder is used as a dependency in another package (without its default config includes). See #889 --- src/AllowedInclude.php | 4 ++-- src/Concerns/AddsIncludesToQuery.php | 4 ++-- src/Concerns/FiltersQuery.php | 2 +- src/Concerns/SortsQuery.php | 2 +- src/Includes/IncludedCount.php | 2 +- src/Includes/IncludedExists.php | 2 +- src/QueryBuilderRequest.php | 10 +++++----- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/AllowedInclude.php b/src/AllowedInclude.php index 8d80805a..0420d5a1 100644 --- a/src/AllowedInclude.php +++ b/src/AllowedInclude.php @@ -41,8 +41,8 @@ public static function relationship(string $name, ?string $internalName = null): ]); if (! Str::contains($relationship, '.')) { - $countSuffix = config('query-builder.count_suffix'); - $existsSuffix = config('query-builder.exists_suffix'); + $countSuffix = config('query-builder.count_suffix', 'Count'); + $existsSuffix = config('query-builder.exists_suffix', 'Exists'); $includes = $includes ->merge(self::count( diff --git a/src/Concerns/AddsIncludesToQuery.php b/src/Concerns/AddsIncludesToQuery.php index 665f9b7a..a3b5a9fa 100644 --- a/src/Concerns/AddsIncludesToQuery.php +++ b/src/Concerns/AddsIncludesToQuery.php @@ -29,11 +29,11 @@ public function allowedIncludes($includes): static return collect([$include]); } - if (Str::endsWith($include, config('query-builder.count_suffix'))) { + if (Str::endsWith($include, config('query-builder.count_suffix', 'Count'))) { return AllowedInclude::count($include); } - if (Str::endsWith($include, config('query-builder.exists_suffix'))) { + if (Str::endsWith($include, config('query-builder.exists_suffix', 'Exists'))) { return AllowedInclude::exists($include); } diff --git a/src/Concerns/FiltersQuery.php b/src/Concerns/FiltersQuery.php index 8361df06..58183421 100644 --- a/src/Concerns/FiltersQuery.php +++ b/src/Concerns/FiltersQuery.php @@ -62,7 +62,7 @@ protected function isFilterRequested(AllowedFilter $allowedFilter): bool protected function ensureAllFiltersExist() { - if (config('query-builder.disable_invalid_filter_query_exception')) { + if (config('query-builder.disable_invalid_filter_query_exception', false)) { return; } diff --git a/src/Concerns/SortsQuery.php b/src/Concerns/SortsQuery.php index c7b12878..469177ed 100644 --- a/src/Concerns/SortsQuery.php +++ b/src/Concerns/SortsQuery.php @@ -93,7 +93,7 @@ protected function findSort(string $property): ?AllowedSort protected function ensureAllSortsExist(): void { - if (config('query-builder.disable_invalid_sort_query_exception')) { + if (config('query-builder.disable_invalid_sort_query_exception', false)) { return; } diff --git a/src/Includes/IncludedCount.php b/src/Includes/IncludedCount.php index 65a3b6e9..4e2c05d6 100644 --- a/src/Includes/IncludedCount.php +++ b/src/Includes/IncludedCount.php @@ -9,6 +9,6 @@ class IncludedCount implements IncludeInterface { public function __invoke(Builder $query, string $count) { - $query->withCount(Str::before($count, config('query-builder.count_suffix'))); + $query->withCount(Str::before($count, config('query-builder.count_suffix', 'Count'))); } } diff --git a/src/Includes/IncludedExists.php b/src/Includes/IncludedExists.php index 37658909..3011998d 100644 --- a/src/Includes/IncludedExists.php +++ b/src/Includes/IncludedExists.php @@ -9,7 +9,7 @@ class IncludedExists implements IncludeInterface { public function __invoke(Builder $query, string $exists) { - $exists = Str::before($exists, config('query-builder.exists_suffix')); + $exists = Str::before($exists, config('query-builder.exists_suffix', 'Exists')); $query ->withExists($exists) diff --git a/src/QueryBuilderRequest.php b/src/QueryBuilderRequest.php index c5c71e9c..2f4d999f 100644 --- a/src/QueryBuilderRequest.php +++ b/src/QueryBuilderRequest.php @@ -34,7 +34,7 @@ public static function fromRequest(Request $request): self public function includes(): Collection { - $includeParameterName = config('query-builder.parameters.include'); + $includeParameterName = config('query-builder.parameters.include', 'include'); $includeParts = $this->getRequestData($includeParameterName); @@ -47,7 +47,7 @@ public function includes(): Collection public function appends(): Collection { - $appendParameterName = config('query-builder.parameters.append'); + $appendParameterName = config('query-builder.parameters.append', 'append'); $appendParts = $this->getRequestData($appendParameterName); @@ -60,7 +60,7 @@ public function appends(): Collection public function fields(): Collection { - $fieldsParameterName = config('query-builder.parameters.fields'); + $fieldsParameterName = config('query-builder.parameters.fields', 'fields'); $fieldsData = $this->getRequestData($fieldsParameterName); $fieldsPerTable = collect(is_string($fieldsData) ? explode(static::getFieldsArrayValueDelimiter(), $fieldsData) : $fieldsData); @@ -95,7 +95,7 @@ public function fields(): Collection public function sorts(): Collection { - $sortParameterName = config('query-builder.parameters.sort'); + $sortParameterName = config('query-builder.parameters.sort', 'sort'); $sortParts = $this->getRequestData($sortParameterName); @@ -108,7 +108,7 @@ public function sorts(): Collection public function filters(): Collection { - $filterParameterName = config('query-builder.parameters.filter'); + $filterParameterName = config('query-builder.parameters.filter', 'filter'); $filterParts = $this->getRequestData($filterParameterName, []);