Skip to content

Commit

Permalink
feat: to work even if Config\Filters is not updated
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Nov 19, 2023
1 parent baeea0f commit 64d6965
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions system/Filters/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,26 +262,36 @@ private function runAfter(array $filterClasses): ResponseInterface
*/
public function runRequired(string $position = 'before')
{
if (! isset($this->config->required[$position]) || $this->config->required[$position] === []) {
return $position === 'before' ? $this->request : $this->response;
// For backward compatibility. For users who do not update Config\Filters.
if (! isset($this->config->required[$position])) {
$baseConfig = config(BaseFiltersConfig::class);
$filters = $baseConfig->required[$position];
$aliases = $baseConfig->aliases;
} else {
$filters = $this->config->required[$position];
$aliases = $this->config->aliases;
}

if ($filters === []) {
return $position === 'before' ? $this->request : $this->response;
}

// Set the toolbar filter to the last position to be executed
$this->config->required['after'] = $this->setToolbarToLast($this->config->required['after']);
if ($position === 'after') {
// Set the toolbar filter to the last position to be executed
$filters = $this->setToolbarToLast($filters);
}

$filterClasses = [];

foreach ($this->config->required[$position] as $alias) {
if (! array_key_exists($alias, $this->config->aliases)) {
foreach ($filters as $alias) {
if (! array_key_exists($alias, $aliases)) {
throw FilterException::forNoAlias($alias);
}

if (is_array($this->config->aliases[$alias])) {
$filterClasses[$position] = array_merge($filterClasses[$position], $this->config->aliases[$alias]);
if (is_array($aliases[$alias])) {
$filterClasses[$position] = array_merge($filterClasses[$position], $aliases[$alias]);
} else {
$filterClasses[$position][] = $this->config->aliases[$alias];
$filterClasses[$position][] = $aliases[$alias];
}
}

Expand Down

0 comments on commit 64d6965

Please sign in to comment.