@@ -31,7 +31,7 @@ class Builder
3131 private $ where = array ();
3232 private $ maxLevel = 0 ;
3333 private $ multiple = false ;
34- private $ select = 0 ;
34+ private $ select = ' main ' ;
3535 private $ hideEmpty = false ;
3636 private $ count = 0 ;
3737 private $ nestingSlug = false ;
@@ -302,7 +302,7 @@ public function get(string $type, int $parent = 0, ?callable $callback = null):
302302 {
303303
304304
305- if (is_null ($ this ->dom )) {
305+ // if (is_null($this->dom)) {
306306 if (is_null ($ this ->item )) {
307307 return false ;
308308 }
@@ -312,25 +312,22 @@ public function get(string $type, int $parent = 0, ?callable $callback = null):
312312 $ this ->currentID = key ($ current );
313313 }
314314
315-
316315 if ($ this ->multiple ) {
317316 if (is_null ($ this ->select )) {
318317 throw new \Exception ("When using multiple menues you also need to select which menu you want to use: @select(0)->get('nav') " , 1 );
319318 }
320319 if (empty ($ this ->item [$ this ->select ])) {
321320 throw new \Exception ("The multiple menue has wrong menu ID: @select(MENU_ID)->get('nav') " , 1 );
322321 }
323-
324322 $ items = $ this ->item [$ this ->select ];
323+
325324 } else {
326325 $ items = $ this ->item ;
327326 }
328327
329-
330328 $ this ->ulTag = $ this ->callback [$ type ]['ul ' ];
331329 $ this ->liTag = $ this ->callback [$ type ]['li ' ];
332-
333- $ this ->dom = Document::dom ($ type );
330+ $ this ->dom = Document::withDom ($ type );
334331 $ this ->level [0 ] = 0 ;
335332
336333 $ elem = $ this ->dom ->create ($ this ->ulTag );
@@ -341,16 +338,14 @@ public function get(string $type, int $parent = 0, ?callable $callback = null):
341338
342339 $ this ->ul [0 ] = $ elem ->attr ("class " , "{$ this ->ulTagClass }" );
343340 $ this ->theUL = $ this ->ul [0 ];
344-
345-
346341 if (isset ($ this ->callback [$ type ]['ulCall ' ])) {
347342 $ this ->callback [$ type ]['ulCall ' ]($ this ->theUL , false , false , 1 );
348343 }
349344 $ this ->iterateView ($ items , $ type , $ parent );
350345 // Reset
351346 $ this ->level = array ();
352347 $ this ->liTag = $ this ->ulTag = null ;
353- }
348+ // }
354349
355350 return $ this ->dom ->execute ($ callback );
356351 }
@@ -405,14 +400,14 @@ private function iterateView(array $items, string $type, int $parent, int $level
405400
406401 /**
407402 * Iterate and build a structure
408- * @param int|false $mid
409- * @param int $parent
410- * @param callable $callback
411- * @param bool|boolean $zeroParent
412- * @param int|null &$count
403+ * @param int|string| false $mid
404+ * @param int $parent
405+ * @param callable $callback
406+ * @param bool|boolean $zeroParent
407+ * @param int|null &$count
413408 * @return void
414409 */
415- private function iterateStructure (int |false $ mid , int $ parent , callable $ callback , bool $ zeroParent = false , ?int &$ count = -1 ): void
410+ private function iterateStructure (int |string | false $ mid , int $ parent , callable $ callback , bool $ zeroParent = false , ?int &$ count = -1 ): void
416411 {
417412 $ arr = ($ mid !== false ) ? $ this ->arr [$ mid ] : $ this ->arr ;
418413 if (isset ($ arr [$ parent ])) {
@@ -478,10 +473,9 @@ private function iterateStructure(int|false $mid, int $parent, callable $callbac
478473 private function validateWhere (object $ obj ): bool
479474 {
480475 foreach ($ this ->where as $ k => $ v ) {
481- if (isset ($ obj ->{$ k })) {
482- if ((string )$ obj ->{$ k } !== (string )$ v ) {
483- return false ;
484- }
476+ $ val = ($ obj ->{$ k } ?? null );
477+ if (!is_null ($ val ) && (string )$ val !== (string )$ v ) {
478+ return false ;
485479 }
486480 }
487481 return true ;
0 commit comments