Example #1
0
 /**
  * Add a new sub-item to the current item.
  *
  * @param  string          $name
  * @param  string|Closure  $attributes
  * @param  Closure         $callback
  * @return void
  */
 public function add($name, $attributes = null, $callback = null)
 {
     $item = new Item();
     // Set the new item's parents.
     if (!is_null($this->menu)) {
         $item->setMenu($this->menu);
     }
     $item->setParent($this);
     // Set the new item's attributes.
     $item->name = $name;
     if (!is_null($attributes)) {
         // If the attributes is just a string, then it is the  URL
         // for the menu item.
         if (is_string($attributes)) {
             $item->url = $attributes;
         } elseif ($attributes instanceof Closure) {
             $attributes($item);
         } else {
             throw new \InvalidArgumentException();
         }
     }
     if ($callback instanceof Closure) {
         $callback($item);
     }
     $this->items[$name] = $item;
 }