Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/Database/Database.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -348,6 +348,11 @@ class Database

protected bool $filter = true;

/**
* @var array<string, bool>|null
*/
protected ?array $disabledFilters = [];

protected bool $validate = true;

protected bool $preserveDates = false;
Expand DownExpand Up@@ -813,17 +818,35 @@ public function disableFilters(): static
*
* @template T
* @param callable(): T $callback
* @param array<string>|null $filters
* @return T
*/
public function skipFilters(callable $callback): mixed
public function skipFilters(callable $callback, ?array $filters = null): mixed
{
$initial = $this->filter;
$this->disableFilters();
if (empty($filters)) {
$initial = $this->filter;
$this->disableFilters();

try {
return $callback();
} finally {
$this->filter = $initial;
}
}

$previous = $this->filter;
$previousDisabled = $this->disabledFilters;
$disabled = [];
foreach ($filters as $name) {
$disabled[$name] = true;
}
$this->disabledFilters = $disabled;

try {
return $callback();
} finally {
$this->filter = $initial;
$this->filter = $previous;
$this->disabledFilters = $previousDisabled;
}
}

Expand DownExpand Up@@ -6625,6 +6648,10 @@ protected function decodeAttribute(string $filter, mixed $value, Document $docum
return $value;
}

if (!\is_null($this->disabledFilters) && isset($this->disabledFilters[$filter])) {
return $value;
}

if (!array_key_exists($filter, self::$filters) && !array_key_exists($filter, $this->instanceFilters)) {
throw new NotFoundException("Filter \"{$filter}\" not found for attribute \"{$attribute}\"");
}
Expand Down