$value)
{
$html .= static::listingElement($key, $type, $value);
}
$attributes = static::attributes($attributes);
return "<{$type}{$attributes}>{$html}{$type}>";
}
/**
* Create the HTML for a listing element.
*
* @param mied $key
* @param string $type
* @param string $value
* @return string
*/
protected static function listingElement($key, $type, $value)
{
if (is_array($value))
{
return static::nestedListing($key, $type, $value);
}
else
{
return '
'.e($value).'';
}
}
/**
* Create the HTML for a nested listing attribute.
*
* @param mied $key
* @param string $type
* @param string $value
* @return string
*/
protected static function nestedListing($key, $type, $value)
{
if (is_int($key))
{
return static::listing($type, $value);
}
else
{
return ''.$key.static::listing($type, $value).'';
}
}
/**
* Build an HTML attribute string from an array.
*
* @param array $attributes
* @return string
*/
public static function attributes($attributes)
{
$html = array();
// For numeric keys we will assume that the key and the value are the same
// as this will convert HTML attributes such as "required" to a correct
// form like required="required" instead of using incorrect numerics.
foreach ((array) $attributes as $key => $value)
{
$element = static::attributeElement($key, $value);
if ( ! is_null($element)) $html[] = $element;
}
return count($html) > 0 ? ' '.implode(' ', $html) : '';
}
/**
* Build a single attribute element.
*
* @param string $key
* @param string $value
* @return string
*/
protected static function attributeElement($key, $value)
{
if (is_numeric($key)) $key = $value;
if ( ! is_null($value)) return $key.'="'.e($value).'"';
}
}