From a47955469876218df9ee2d92893de4954fb9f355 Mon Sep 17 00:00:00 2001 From: patrickkusebauch Date: Fri, 9 Jun 2023 19:35:14 +0200 Subject: [PATCH] Added panel sorter --- src/Tracy/Bar/Bar.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Tracy/Bar/Bar.php b/src/Tracy/Bar/Bar.php index 037bc3cee..5b635e379 100644 --- a/src/Tracy/Bar/Bar.php +++ b/src/Tracy/Bar/Bar.php @@ -15,10 +15,13 @@ */ class Bar { - /** @var IBarPanel[] */ + /** @var array */ private array $panels = []; private bool $loaderRendered = false; + /** @var ?callable(string, string): int */ + private $panelSorter; + /** * Add custom panel. @@ -37,6 +40,13 @@ public function addPanel(IBarPanel $panel, ?string $id = null): self return $this; } + /** + * @param callable(string, string): int $sorter + */ + public function replacePanelSorter(callable $sorter): void + { + $this->panelSorter = $sorter; + } /** * Returns panel with given id @@ -136,6 +146,10 @@ private function renderPanels(string $suffix = ''): array $obLevel = ob_get_level(); $panels = []; + if($this->panelSorter !== null) { + uksort($this->panels, $this->panelSorter); + } + foreach ($this->panels as $id => $panel) { $idHtml = preg_replace('#[^a-z0-9]+#i', '-', $id) . $suffix; try {