get('legal_empty_attributes'); $preparedAttributes = ''; foreach ($attributes as $attributeKey => $attributeValue) { $whitelisted = in_array($attributeKey, $legalEmptyAttributes ?? []); // Only set non-empty strings (ensures strlen(0) > 0) if (strlen($attributeValue ?? '') > 0 || $whitelisted) { $preparedAttributes .= sprintf( ' %s="%s"', $attributeKey, Convert::raw2att($attributeValue) ); } } // Check void element type if (in_array($tag, static::config()->get('void_elements') ?? [])) { if ($content) { throw new InvalidArgumentException("Void element \"{$tag}\" cannot have content"); } return "<{$tag}{$preparedAttributes} />"; } // Closed tag type return "<{$tag}{$preparedAttributes}>{$content}"; } }