Snippets

Dan Gifford setConfig

Created by Dan Gifford
	/**
	 * 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 );
			}
		}
	}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.