UPDATES
Based on KIKO Softwares comments below, this is my stab at using a setter method for the variable key/values while still allowing to set 1 by 1 or setting all my variables at once still by using an Array!
/**
* Set Variable name and values one by one or at once with an array
* @param mixed $var_name Variable name that will be replaced in the Template OR an Array or key=>values
* @param string $var_value (Optional) The value for a variable/key if not set using an Array.
*/
public function setVar($var_name, $var_value = ''){
$numargs = func_num_args();
try
{
// If a key and value are passed in, add it to our $_emailValues Array
if($numargs > 1){
if(isset($var_name) && $var_name != '' & isset($var_value) && $var_value != ''){
$this->_emailValues[$var_name] = $var_value;
}else{
throw new Exception('ERROR: Template Variable KEY and VALUE must be a string and not be empty');
}
// If only 1 argument passed in, check if it is an Array and if so loop it and add each
// key/value to $_emailValues Array
}else{
if(is_array($var_name)){
foreach ($var_name as $key => $value) {
$this->_emailValues[$key] = $value;
}
}else{
throw new Exception('ERROR: Single arguments must be an ARRAY. Pass an ARRAY or set a 2nd argument as the value.');
}
}
}
catch(Exception $e)
{
echo $e->getMessage(). ' | FILE: '.$e->getFile(). ' | LINE: '.$e->getLine();
}
}
setVar() Method USAGE
$emailValues = array(
'username' => 'My username value here',
'password' => 'my pass'
);
// Set variable key/values using an ARRAY
$emailHtml->setVar($emailValues);
// Set variable key/values 1 by 1
$emailHtml->setVar('username', 'JasonDavis');
$emailHtml->setVar('password', 'my random password value here');