Created
March 3, 2014 16:48
-
-
Save you-think-you-are-special/9329131 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
<?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