| 1 |
<?php |
| 2 |
|
| 3 |
namespace ResponsiveMenu\Collections; |
| 4 |
|
| 5 |
class OptionsCollection implements \ArrayAccess, \Countable { |
| 6 |
|
| 7 |
private $options; |
| 8 |
|
| 9 |
public function __construct(array $options = []) { |
| 10 |
$this->options = array_map(function($o) { |
| 11 |
return is_array($o) ? json_encode($o) : $o; |
| 12 |
}, $options); |
| 13 |
} |
| 14 |
|
| 15 |
public function add(array $option) { |
| 16 |
$value = $option[key($option)]; |
| 17 |
$this->options[key($option)] = is_array($value) ? json_encode($value) : $value; |
| 18 |
} |
| 19 |
|
| 20 |
public function getActiveArrow() { |
| 21 |
if($this->options['active_arrow_image']) |
| 22 |
return '<img alt="' . $this->options['active_arrow_image_alt'] .'" src="' . $this->options['active_arrow_image'] .'" />'; |
| 23 |
|
| 24 |
return $this->options['active_arrow_shape']; |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
public function getInActiveArrow() { |
| 29 |
if($this->options['inactive_arrow_image']) |
| 30 |
return '<img alt="' . $this->options['inactive_arrow_image_alt'] .'" src="' . $this->options['inactive_arrow_image'] .'" />'; |
| 31 |
|
| 32 |
return $this->options['inactive_arrow_shape']; |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
public function getTitleImage() { |
| 37 |
if($this->options['menu_title_image']) |
| 38 |
return '<img alt="' . $this->options['menu_title_image_alt'] .'" src="' . $this->options['menu_title_image'] .'" />'; |
| 39 |
|
| 40 |
return null; |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
public function getButtonIcon() { |
| 45 |
if($this->options['button_image']) |
| 46 |
return '<img alt="' . $this->options['button_image_alt'] .'" src="' . $this->options['button_image'] .'" class="responsive-menu-button-icon responsive-menu-button-icon-active" />'; |
| 47 |
|
| 48 |
return '<span class="responsive-menu-inner"></span>'; |
| 49 |
} |
| 50 |
|
| 51 |
public function getButtonIconActive() { |
| 52 |
if($this->options['button_image']) |
| 53 |
return '<img alt="' . $this->options['button_image_alt_when_clicked'] .'" src="' . $this->options['button_image_when_clicked'] .'" class="responsive-menu-button-icon responsive-menu-button-icon-inactive" />'; |
| 54 |
} |
| 55 |
|
| 56 |
public function offsetExists($offset) { |
| 57 |
return array_key_exists($offset, $this->options); |
| 58 |
} |
| 59 |
|
| 60 |
public function offsetGet($offset) { |
| 61 |
if(isset($this->options[$offset])) |
| 62 |
return $this->options[$offset]; |
| 63 |
return null; |
| 64 |
} |
| 65 |
|
| 66 |
public function offsetSet($offset, $value) { |
| 67 |
$this->add([$offset => $value]); |
| 68 |
} |
| 69 |
|
| 70 |
public function offsetUnset($offset) { |
| 71 |
if(isset($this->options[$offset])) |
| 72 |
unset($this->options[$offset]); |
| 73 |
} |
| 74 |
|
| 75 |
public function toArray() { |
| 76 |
$array = []; |
| 77 |
foreach($this->options as $key => $val) |
| 78 |
$array[$key] = $val; |
| 79 |
return $array; |
| 80 |
} |
| 81 |
|
| 82 |
public function count() { |
| 83 |
return count($this->options); |
| 84 |
} |
| 85 |
|
| 86 |
} |
| 87 |
|