protected function resolveToken($token, $titles, $groupLookupTable)
{
$replaceString = '';
$tokenParts = $this->tokenParts($token);
foreach ($tokenParts as $tokenPart) {
if ($this->isTokenGroup($tokenPart)) {
$replaceString = $groupLookupTable[$tokenPart];
$groupTokenArray = $this->extractTokens($replaceString);
foreach ($groupTokenArray as $groupToken) {
$replaceString = str_replace($groupToken, $this->resolveToken($groupToken, $titles, $groupLookupTable), $replaceString);
}
// We want to stop after the first matching token part / identifier is found
// <id1|id2> if id1 has a value, id2 will not be used.
// In this case id1 or id1 is a token group.
break;
} else {
if (array_key_exists($tokenPart, $titles) && $titles[$tokenPart] !== '' && $titles[$tokenPart] !== null) {
$replaceString = $titles[$tokenPart];
// We want to stop after the first matching token part / identifier is found
// <id1|id2> if id1 has a value, id2 will not be used.
break;
}
}
}
return $replaceString;
}