Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Wazabii committed Jan 1, 2024
1 parent 136a800 commit 0a35343
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Builder
private $where = array();
private $maxLevel = 0;
private $multiple = false;
private $select = 0;
private $select = 'main';
private $hideEmpty = false;
private $count = 0;
private $nestingSlug = false;
Expand Down Expand Up @@ -302,7 +302,7 @@ public function get(string $type, int $parent = 0, ?callable $callback = null):
{


if (is_null($this->dom)) {
//if (is_null($this->dom)) {
if (is_null($this->item)) {
return false;
}
Expand All @@ -312,25 +312,22 @@ public function get(string $type, int $parent = 0, ?callable $callback = null):
$this->currentID = key($current);
}


if ($this->multiple) {
if (is_null($this->select)) {
throw new \Exception("When using multiple menues you also need to select which menu you want to use: @select(0)->get('nav')", 1);
}
if (empty($this->item[$this->select])) {
throw new \Exception("The multiple menue has wrong menu ID: @select(MENU_ID)->get('nav')", 1);
}

$items = $this->item[$this->select];

} else {
$items = $this->item;
}


$this->ulTag = $this->callback[$type]['ul'];
$this->liTag = $this->callback[$type]['li'];

$this->dom = Document::dom($type);
$this->dom = Document::withDom($type);
$this->level[0] = 0;

$elem = $this->dom->create($this->ulTag);
Expand All @@ -341,16 +338,14 @@ public function get(string $type, int $parent = 0, ?callable $callback = null):

$this->ul[0] = $elem->attr("class", "{$this->ulTagClass}");
$this->theUL = $this->ul[0];


if (isset($this->callback[$type]['ulCall'])) {
$this->callback[$type]['ulCall']($this->theUL, false, false, 1);
}
$this->iterateView($items, $type, $parent);
// Reset
$this->level = array();
$this->liTag = $this->ulTag = null;
}
//}

return $this->dom->execute($callback);
}
Expand Down Expand Up @@ -405,14 +400,14 @@ private function iterateView(array $items, string $type, int $parent, int $level

/**
* Iterate and build a structure
* @param int|false $mid
* @param int $parent
* @param callable $callback
* @param bool|boolean $zeroParent
* @param int|null &$count
* @param int|string|false $mid
* @param int $parent
* @param callable $callback
* @param bool|boolean $zeroParent
* @param int|null &$count
* @return void
*/
private function iterateStructure(int|false $mid, int $parent, callable $callback, bool $zeroParent = false, ?int &$count = -1): void
private function iterateStructure(int|string|false $mid, int $parent, callable $callback, bool $zeroParent = false, ?int &$count = -1): void
{
$arr = ($mid !== false) ? $this->arr[$mid] : $this->arr;
if (isset($arr[$parent])) {
Expand Down Expand Up @@ -478,10 +473,9 @@ private function iterateStructure(int|false $mid, int $parent, callable $callbac
private function validateWhere(object $obj): bool
{
foreach ($this->where as $k => $v) {
if (isset($obj->{$k})) {
if ((string)$obj->{$k} !== (string)$v) {
return false;
}
$val = ($obj->{$k} ?? null);
if (!is_null($val) && (string)$val !== (string)$v) {
return false;
}
}
return true;
Expand Down

0 comments on commit 0a35343

Please sign in to comment.