public function addTemplateDir($template_dir, $key = null)
{
// make sure we're dealing with an array
$this->template_dir = (array) $this->template_dir;
if (is_array($template_dir)) {
foreach ($template_dir as $k => $v) {
$v = str_replace(array('//', '\\\\'), DS, rtrim($v, '/\\')) . DS;
if (is_int($k)) {
// indexes are not merged but appended
$this->template_dir[] = $v;
} else {
// string indexes are overridden
$this->template_dir[$k] = $v;
}
}
} else {
$v = str_replace(array('//', '\\\\'), DS, rtrim($template_dir, '/\\')) . DS;
if ($key !== null) {
// override directory at specified index
$this->template_dir[$key] = $v;
} else {
// append new directory
$this->template_dir[] = $v;
}
}
$this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir);
return $this;
}