protected function sortPages() { // sort pages $order = $this->getConfig('pages_order'); $alphaSortClosure = function ($a, $b) use($order) { $aSortKey = basename($a['id']) === 'index' ? dirname($a['id']) : $a['id']; $bSortKey = basename($b['id']) === 'index' ? dirname($b['id']) : $b['id']; $cmp = strcmp($aSortKey, $bSortKey); return $cmp * ($order === 'desc' ? -1 : 1); }; if ($this->getConfig('pages_order_by') === 'date') { // sort by date uasort($this->pages, function ($a, $b) use($alphaSortClosure, $order) { if (empty($a['time']) || empty($b['time'])) { $cmp = empty($a['time']) - empty($b['time']); } else { $cmp = $b['time'] - $a['time']; } if ($cmp === 0) { // never assume equality; fallback to alphabetical order return $alphaSortClosure($a, $b); } return $cmp * ($order === 'desc' ? 1 : -1); }); } else { // sort alphabetically uasort($this->pages, $alphaSortClosure); } }