Overview

Namespaces

  • Menu
    • Items
      • Contents
    • Traits

Classes

  • Menu\Items\Contents\Link
  • Menu\Items\Contents\Raw
  • Menu\Items\Item
  • Menu\Items\ItemList
  • Menu\Menu
  • Menu\MenuHandler
  • Menu\MenuServiceProvider
  • Menu\Traits\Content
  • Menu\Traits\MenuObject
  • Overview
  • Namespace
  • Class
 1: <?php
 2: namespace Menu\Traits;
 3: 
 4: use HtmlObject\Traits\Tag;
 5: use Menu\Menu;
 6: use Underscore\Methods\ArraysMethods;
 7: 
 8: /**
 9:  * Allows dynamic setting and getting of attributes
10:  * on the various parts of a menu (items, ItemLists, etc)
11:  */
12: abstract class MenuObject extends Tag
13: {
14: 
15:   /**
16:    * Per-element configuration
17:    *
18:    * @var array
19:    */
20:   public $options = array();
21: 
22:   ////////////////////////////////////////////////////////////////////
23:   /////////////////////////// CONFIGURATION //////////////////////////
24:   ////////////////////////////////////////////////////////////////////
25: 
26:   /**
27:    * Replace an array of options
28:    *
29:    * @param array $options The new options
30:    *
31:    * @return MenuObject
32:    */
33:   public function replaceOptions($options)
34:   {
35:     $this->options = array();
36: 
37:     foreach($options as $key => $value) {
38:       $this->setOption($key, $value);
39:     }
40: 
41:     return $this;
42:   }
43: 
44:   /**
45:    * Set a particular option in the array
46:    *
47:    * @param string $option The option
48:    * @param mixed  $value  Its new value
49:    *
50:    * @return MenuObject
51:    */
52:   public function setOption($option, $value)
53:   {
54:     $this->options = ArraysMethods::set($this->options, $option, $value);
55: 
56:     return $this;
57:   }
58: 
59:   /**
60:    * Get a particular option in the array
61:    *
62:    * @param string $option An option
63:    *
64:    * @return mixed Its value
65:    */
66:   public function getOption($option = null)
67:   {
68:     $globalOptions = Menu::getOption();
69:     $combinedOptions = array_replace_recursive($globalOptions, $this->options);
70:     if (!$option) return $combinedOptions;
71:     return ArraysMethods::get($combinedOptions, $option);
72:   }
73: }
74: 
API documentation generated by ApiGen