protected function renderAttributes(array $attributes)
{
$renderedAttributes = '';
foreach ($attributes as $attributeName => $attributeValue) {
$encodedAttributeName = htmlspecialchars($attributeName, ENT_COMPAT, 'UTF-8');
if ($attributeValue === null) {
$renderedAttributes .= ' ' . $encodedAttributeName;
} else {
if (is_array($attributeValue) || is_object($attributeValue) && !method_exists($attributeValue, '__toString')) {
throw new Exception(sprintf('Only attributes with string values can be rendered, attribute %s is of type %s', $attributeName, gettype($attributeValue)));
}
$encodedAttributeValue = htmlspecialchars((string) $attributeValue, ENT_COMPAT, 'UTF-8');
$renderedAttributes .= ' ' . $encodedAttributeName . '="' . $encodedAttributeValue . '"';
}
}
return $renderedAttributes;
}