Skip to content

Commit 43aaba7

Browse files
committed
Merge pull request #657 from utopia-php/feat/skipfilters-optional-list
Feat/skipfilters optional list
1 parent 72c2a9c commit 43aaba7

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/Database/Database.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ class Database
344344

345345
protected bool $filter = true;
346346

347+
/**
348+
* @var array<string, bool>|null
349+
*/
350+
protected ?array $disabledFilters = [];
351+
347352
protected bool $validate = true;
348353

349354
protected bool $preserveDates = false;
@@ -809,17 +814,35 @@ public function disableFilters(): static
809814
*
810815
* @template T
811816
* @param callable(): T $callback
817+
* @param array<string>|null $filters
812818
* @return T
813819
*/
814-
public function skipFilters(callable $callback): mixed
820+
public function skipFilters(callable $callback, ?array $filters = null): mixed
815821
{
816-
$initial = $this->filter;
817-
$this->disableFilters();
822+
if (empty($filters)) {
823+
$initial = $this->filter;
824+
$this->disableFilters();
825+
826+
try {
827+
return $callback();
828+
} finally {
829+
$this->filter = $initial;
830+
}
831+
}
832+
833+
$previous = $this->filter;
834+
$previousDisabled = $this->disabledFilters;
835+
$disabled = [];
836+
foreach ($filters as $name) {
837+
$disabled[$name] = true;
838+
}
839+
$this->disabledFilters = $disabled;
818840

819841
try {
820842
return $callback();
821843
} finally {
822-
$this->filter = $initial;
844+
$this->filter = $previous;
845+
$this->disabledFilters = $previousDisabled;
823846
}
824847
}
825848

@@ -6560,6 +6583,10 @@ protected function decodeAttribute(string $filter, mixed $value, Document $docum
65606583
return $value;
65616584
}
65626585

6586+
if (!\is_null($this->disabledFilters) && isset($this->disabledFilters[$filter])) {
6587+
return $value;
6588+
}
6589+
65636590
if (!array_key_exists($filter, self::$filters) && !array_key_exists($filter, $this->instanceFilters)) {
65646591
throw new NotFoundException("Filter \"{$filter}\" not found for attribute \"{$attribute}\"");
65656592
}

0 commit comments

Comments
 (0)