Skip to content

Instantly share code, notes, and snippets.

@awartoft
Created July 15, 2012 19:00
Show Gist options
  • Save awartoft/3118172 to your computer and use it in GitHub Desktop.
Save awartoft/3118172 to your computer and use it in GitHub Desktop.
/**
* Sets one or multiple options
*
* @param array|Traversable $options Options to set
* @throws Exception\InvalidArgumentException If $options is not an array or Traversable
* @return AbstractValidator Provides fluid interface
*/
public function setOptions($options = array())
{
if (!is_array($options) && !$options instanceof Traversable) {
throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable');
}
foreach ($options as $name => $option) {
$fname = 'set' . ucfirst($name);
$fname2 = 'is' . ucfirst($name);
if (($name != 'setOptions') && method_exists($this, $name)) {
$this->{$name}($option);
} elseif (($fname != 'setOptions') && method_exists($this, $fname)) {
$this->{$fname}($option);
} elseif (($fname2 != 'setOptions') && method_exists($this, $fname2)) {
$this->{$fname2}($option);
} elseif (isset($this->options)) {
$this->options[$name] = $option;
} else {
$this->abstractOptions[$name] = $options;
}
}
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment