Created
July 15, 2012 19:00
-
-
Save awartoft/3118172 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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