Utility function to add prefix to placeholder & optionally wrap it with markers, because I was writing it out so many times

This commit is contained in:
nathan 2021-09-27 10:52:39 -06:00
parent f6b7dc1474
commit 47cf12869b

View File

@ -1654,6 +1654,30 @@ abstract class Merge
return $replacements;
}
/**
* Prefix a placeholder, taking care of $$ or {{}} markers
*
* @param string $prefix Placeholder prefix
* @param string $placeholder Placeholder, with or without {{...}} or $$...$$ markers
* @param null|string $wrap "{" or "$" to add markers, omit to exclude markers
* @return string
*/
protected function prefix($prefix, $placeholder, $wrap = null)
{
$marker = ['', ''];
if($placeholder[0] == '{' && is_null($wrap) || $wrap[0] == '{')
{
$marker = ['{{', '}}'];
}
elseif($placeholder[0] == '$' && is_null($wrap) || $wrap[0] == '$')
{
$marker = ['$$', '$$'];
}
$placeholder = str_replace(['{{', '}}', '$$'], '', $placeholder);
return $marker[0] . ($prefix ? $prefix . '/' : '') . $placeholder . $marker[1];
}
/**
* Process special flags, such as IF or NELF
*