Skip to content

Instantly share code, notes, and snippets.

@you-think-you-are-special
Created March 3, 2014 16:48
Show Gist options
  • Save you-think-you-are-special/9329131 to your computer and use it in GitHub Desktop.
Save you-think-you-are-special/9329131 to your computer and use it in GitHub Desktop.
<?php
trait Options {
public function setOptions(array $options)
{
// apply options
foreach ($options as $key => $value) {
$method = 'set' . $this->normalizeKey($key);
if (method_exists($this, $method)) {
$this->$method($value);
}
}
}
private function normalizeKey($key)
{
$option = str_replace('_', ' ', strtolower($key));
$option = str_replace(' ', '', ucwords($option));
return $option;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment