Skip to content

Commit

Permalink
Added panel sorter
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickkusebauch committed Jun 9, 2023
1 parent 3d0b6b8 commit a479554
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Tracy/Bar/Bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
*/
class Bar
{
/** @var IBarPanel[] */
/** @var array<string, IBarPanel> */
private array $panels = [];
private bool $loaderRendered = false;

/** @var ?callable(string, string): int */
private $panelSorter;


/**
* Add custom panel.
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a479554

Please sign in to comment.