Skip to content

Commit

Permalink
fix: toolbar does not work in globals filters
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Nov 19, 2023
1 parent 64d6965 commit 1217561
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
6 changes: 3 additions & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,6 @@ private function runRequiredAfterFilters(Filters $filters): void
{
$filters->setResponse($this->response);

// After filter debug toolbar requires 'total_execution'.
$this->totalTime = $this->benchmark->getElapsedTime('total_execution');

// Run required after filters
$this->benchmark->start('required_after_filters');
$response = $filters->runRequired('after');
Expand Down Expand Up @@ -760,6 +757,9 @@ public function cachePage(Cache $config)
*/
public function getPerformanceStats(): array
{
// After filter debug toolbar requires 'total_execution'.
$this->totalTime = $this->benchmark->getElapsedTime('total_execution');

return [
'startTime' => $this->startTime,
'totalTime' => $this->totalTime,
Expand Down
14 changes: 10 additions & 4 deletions system/Filters/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,13 @@ public function runRequired(string $position = 'before')
}

if ($position === 'after') {
// Set the toolbar filter to the last position to be executed
$filters = $this->setToolbarToLast($filters);
if (in_array('toolbar', $this->filters['after'], true)) {
// It was already run in globals filters. So remove it.
$filters = $this->setToolbarToLast($filters, true);
} else {
// Set the toolbar filter to the last position to be executed
$filters = $this->setToolbarToLast($filters);
}
}

$filterClasses = [];
Expand Down Expand Up @@ -307,8 +312,9 @@ public function runRequired(string $position = 'before')
* Set the toolbar filter to the last position to be executed.
*
* @param list<string> $filters `after` filter array
* @param bool $remove if true, remove `toolbar` filter
*/
private function setToolbarToLast(array $filters): array
private function setToolbarToLast(array $filters, bool $remove = false): array
{
$afters = [];
$found = false;
Expand All @@ -323,7 +329,7 @@ private function setToolbarToLast(array $filters): array
$afters[] = $alias;
}

if ($found) {
if ($found && ! $remove) {
$afters[] = 'toolbar';
}

Expand Down

0 comments on commit 1217561

Please sign in to comment.