Created by Dan Gifford 2021-02-17 View revision File snippet.txt Added Side-by-side diff More Ignore whitespace Hide word diff + /** + * Call the setter for each property in the given + * config array, if it exists. Calls Setters in + * camel case, e.g. setPropertyNameGoesHere() + * + * @param array $config + */ + public function setConfig( array $config = null ): void + { + if( is_null( $config ) ) + { + return; + } + + foreach( $config as $name => $value ) + { + $method_a = array_merge(['set'], array_map( 'ucfirst', explode('_', $name) )); + + $method = implode('', $method_a); + + if( is_callable([$this, $method]) ) + { + $this->$method( $value ); + } + } + }