Classe PHP para gerar a saída em HTML.
Pessoal, alguém poderia me dar alguma ajuda em relação a essa classe que eu criei?
Podem criticar, dar idéias, retificar... Estou realmente precisando de opiniões alheias a respeito.
<?php
class html
{
// Define as tags que serão fechadas assim: <tag /> //
private static $autoclose = array('input', 'meta', 'br', 'hr', 'input');
private function create_attr($attrs = array())
{
if( is_array($attrs) )
{
$output = '';
foreach( $attrs as $attr => $value )
{
$output .= "$attr='$value' ";
}
return $output;
}
}
public static function __callStatic( $name, $param )
{
if( strstr($name, 'open_') )
{
$name = substr($name, strlen('open_'));
if( isset($param[0]) && is_array($param[0]))
{
$attrs = self::create_attr($param[0]);
}
else{
$attrs = '';
}
return "<$name $attrs>" . PHP_EOL;
}
elseif( strstr($name, 'close_') )
{
$name = substr($name, strlen('close_'));
return "</$name>" . PHP_EOL;
}
elseif( in_array(strtolower($name), self::$autoclose) )
{
if( isset($param[0]) && is_array($param[0]))
{
$attrs = self::create_attr($param[0]);
}
else{
$attrs = '';
}
return "<$name $attrs/>";
}
else
{
if( isset($param[1]) && is_array($param[1]))
{
$attrs = self::create_attr($param[1]);
}
else{
$attrs = '';
}
$param[0] = ( ! isset($param[0])) ? null : $param[0];
return "<$name $attrs>" . $param[0] . "</$name>" . PHP_EOL;
}
}
}Uso:<?php
echo Html::open_table(array('class' => 'table table-bordered table table-striped', 'id' => 'u-teste'));
echo Html::open_tr(array('id' => 'header'));
echo Html::th('texto');
echo Html::th('texto2');
echo Html::th('texto3');
echo Html::th('texto4');
echo Html::close_tr();Discussão (13)
Carregando comentários...