add($options); } /** * Returns the option through it's shortname (without the prefix) * * @author oncletom * @since 2.0 * @version 1.0 * @param string $name * @return mixed */ public function __get($name) { $full_name = sprintf('%s%s', self::$prefix, $name); if (isset($this[$full_name])) { return $this[$full_name]; } else { throw new AWShortcodesException(sprintf('No setting is accessible through `%s` (gives %s)', $name, $full_name)); } } /** * Add one option object or an array of option objects * * @author oncletom * @since 2.0 * @version 1.0 * @param mixed $options * @return integer number of options added */ public function add($options) { $added = 0; if (!$options || empty($options)) { return $added; } if (!is_array($options)) { $options = array($options); } foreach ($options as $option) { $option->setPrefix(self::$prefix); $this[$option->getId()] = $option; $added++; } return $added; } /** * @author oncletom * @see Countable::count * @return integer */ public function count() { return count($this->options); } /** * @author oncletom * @see IteratorAggregate::getIterator * @return ArrayIterator */ public function getIterator() { $data = $this->options; return new ArrayIterator($data); } /** * Returns the keys identifiers of the options array * * @author oncletom * @since 2.0 * @version 1.0 * @return array */ public function getKeys($filter = array()) { $options = $this->options; if (is_array($filter) && !empty($filter)) { foreach ($filter as $id) { unset($options[$id], $options[self::$prefix.$id]); } } return array_keys($options); } /** * @see ArrayAccess::offsetExists * @author oncletom */ public function offsetExists($offset) { return isset($this->options[$offset]); } /** * @see ArrayAccess::offsetGet * @author oncletom */ public function offsetGet($offset) { return isset($this->options[$offset]) ? $this->options[$offset] : null; } /** * @see ArrayAccess::offsetSet * @author oncletom */ public function offsetSet($offset, $value) { if (!$value instanceof AWShortcodesConfigurationOption) { throw new AWShortcodesException(sprintf("Can't register a non-AWShortcodesConfigurationOption object [%s].", $value)); } $this->options[$offset] = $value; } /** * @see ArrayAccess::offsetUnset * @author oncletom */ public function offsetUnset($offset) { unset($this->options[$offset]); } }