private function stringifyAttributes()
{
$attributes = $this->attributes;
$attributes_string = '';
switch ($this->attributes['type']) {
case 'checkbox':
case 'radio':
$value = $this->getValue();
if ($this->attributes['value'] == $value || is_array($value) && in_array($this->attributes['value'], $value)) {
$attributes['checked'] = 'checked';
}
break;
case 'textarea':
case 'select':
unset($attributes['type']);
break;
}
if (!in_array($this->attributes['type'], ['checkbox', 'radio'])) {
unset($attributes['value']);
}
ksort($attributes);
// To make the unit testing simpler.
#if (strpos(strrev($attributes['name']), '][') === 0) {
# $attributes['name'] = substr_replace($attributes['name'], '[' . $this->index . ']', -2);
#}
foreach ($attributes as $k => $v) {
$attributes_string .= ' ' . $k . '="' . $v . '"';
}
return trim($attributes_string);
}