Convert class and style builder into a method of Template class

This commit is contained in:
Kijin Sung 2023-10-17 22:44:27 +09:00
parent 82b9107ca0
commit 55cafc5c33
6 changed files with 61 additions and 24 deletions

View file

@ -471,4 +471,34 @@ class Template
array_pop(self::$_loopvars);
}
}
/**
* Attribute builder for v2.
*
* @param string $attribute
* @param array $definition
* @return string
*/
protected function _v2_buildAttribute(string $attribute, array $definition = []): string
{
$delimiters = [
'class' => ' ',
'style' => '; ',
];
$values = [];
foreach ($definition as $key => $val)
{
if (is_int($key) && !empty($val))
{
$values[] = $val;
}
elseif ($val)
{
$values[] = $key;
}
}
return sprintf(' %s="%s"', $attribute, escape(implode($delimiters[$attribute], $values), false));
}
}