moin,
$ta = new TableAttributs( 'id', 'class', 1, 1 );
$tcol = new TableColum( 'id', 'class', '1' );
$tset = new TableSettings( 'id', 'class', null, [ $tcol, $tcol, $tcol, $tcol ] );
$tc = new TableCell( 'foobar', $ta );
$tr = new TableRow( [ $tc, $tc, $tc, $tc ] );
$ts = new TableSection( [ $tr, $tr ], $ta );
$t = new TableConstructor( 'Foo Bar', $tset, $ts, $ts, $ts );
echo $t;
mit Template
<!-- TABLE -->
<table
<?php if( isset( $attributs->id ) and !empty( $attributs->id ) ) : ?>
id="<?php echo $attributs->id ?>"
<?php endif; ?>
<?php if( isset( $attributs->class ) and !empty( $attributs->class ) ) : ?>
class="<?php echo $attributs->class ?>"
<?php endif; ?>>
<!-- COLUMN GROUPS -->
<?php if( isset( $settings ) and !empty( $settings ) ) : ?>
<colgroup
<?php if( isset( $settings->id ) and !empty( $settings->id ) ) : ?>
id="<?php echo $settings->id ?>"
<?php endif; ?>
<?php if( isset( $settings->class ) and !empty( $settings->class ) ) : ?>
class="<?php echo $settings->class ?>"
<?php endif; ?>
<?php if( isset( $settings->span ) and !empty( $settings->span ) ) : ?>
span="<?php echo $settings->span ?>"
<?php endif; ?>
>
<?php if( isset( $settings->columns ) and !empty( $settings->columns ) ) : ?>
<?php for( $i = 0; $i < count( $settings->columns ); $i++ ) : ?>
<col
<?php if( isset( $settings->columns[ $i ]->id ) and !empty( $settings->columns[ $i ]->id ) ) : ?>
id="<?php echo $settings->columns[ $i ]->id ?>"
<?php endif; ?>
<?php if( isset( $settings->columns[ $i ]->class ) and !empty( $settings->columns[ $i ]->class ) ) : ?>
class="<?php echo $settings->columns[ $i ]->class ?>"
<?php endif; ?>
<?php if( isset( $settings->columns[ $i ]->span ) and !empty( $settings->columns[ $i ]->span ) ) : ?>
span="<?php echo $settings->columns[ $i ]->span ?>"
<?php endif; ?>>
<?php endfor ?>
<?php endif ?>
</colgroup>
<?php endif ?>
<!-- CAPTION -->
<?php if( isset( $caption ) and !empty( $caption ) ) : ?>
<caption><?php echo $caption ?></caption>
<?php endif; ?>
<!-- MATRIX -->
<?php foreach( $sections as $key => $section ) : ?>
<?php if( $section === null ) continue; // if one of section is not defined like '<tfoot>' ?>
<!-- SECTION -->
<t<?php echo $key; ?>
<?php if( isset( $section->attributs->id ) and !empty( $section->attributs->id ) ) : ?>
id="<?php echo $section->attributs->id ?>"
<?php endif; ?>
<?php if( isset( $section->attributs->class ) and !empty( $section->attributs->class ) ) : ?>
class="<?php echo $section->attributs->class ?>"
<?php endif; ?>>
<?php for( $i = 0; $i < count( $section->row ); $i++ ) : ?>
<tr
<?php if( isset( $section->row[ $i ]->attributs->id ) and !empty( $section->row[ $i ]->attributs->id ) ) : ?>
id="<?php echo $section->row[ $i ]->attributs->id ?>"
<?php endif; ?>
<?php if( isset( $section->row[ $i ]->attributs->class ) and !empty( $section->row[ $i ]->attributs->class ) ) : ?>
class="<?php echo $section->row[ $i ]->attributs->class ?>"
<?php endif; ?>>
<?php for( $j = 0; $j < count( $section->row[ $i ]->cell ); $j++ ) : ?>
<<?php if( $key === 'head' or $j === 0 and $key !== 'foot' ) :?>th<?php else: ?>td<?php endif; ?>
<?php if( isset( $section->row[ $i ]->cell[ $j ]->attributs->id ) and !empty( $section->row[ $i ]->cell[ $j ]->attributs->id ) ) : ?>
id="<?php echo $section->row[ $i ]->cell[ $j ]->attributs->id ?>"
<?php endif; ?>
<?php if( isset( $section->row[ $i ]->cell[ $j ]->attributs->class ) and !empty( $section->row[ $i ]->cell[ $j ]->attributs->class ) ) : ?>
class="<?php echo $section->row[ $i ]->cell[ $j ]->attributs->class ?>"
<?php endif; ?>
<?php if( isset( $section->row[ $i ]->cell[ $j ]->attributs->row ) and !empty( $section->row[ $i ]->cell[ $j ]->attributs->row ) ) : ?>
rowspan="<?php echo $section->row[ $i ]->cell[ $j ]->attributs->row ?>"
<?php endif; ?>
<?php if( isset( $section->row[ $i ]->cell[ $j ]->attributs->column ) and !empty( $section->row[ $i ]->cell[ $j ]->attributs->column ) ) : ?>
colspan="<?php echo $section->row[ $i ]->cell[ $j ]->attributs->column ?>"
<?php endif; ?>>
<?php echo $section->row[ $i ]->cell[ $j ]->content ?>
</<?php if( $key === 'head' or $j === 0 and $key !== 'foot' ) :?>th<?php else: ?>td<?php endif; ?>>
<?php endfor; ?>
</tr>
<?php endfor; ?>
</t<?php echo $key; ?>>
<?php endforeach; ?>
</table>
heraus kam
<table>
<!-- COLUMN GROUPS -->
<colgroup id="id" class="class">
<col id="id" class="class" span="1">
<!-- soon -->
</colgroup>
<!-- CAPTION -->
<caption>Foo Bar</caption>
<!-- MATRIX -->
<!-- SECTION -->
<thead id="id" class="class">
<tr>
<th id="id" class="class" rowspan="1" colspan="1">
foobar
</th>
<!-- soon -->
</tr>
<!-- soon -->
</thead>
<tbody>
<!-- soon -->
</tbody>
<tfoot>
<!-- soon -->
</tfoot>
</table>
Ich habs mit abstrakten Eltern Klassen gemacht und Interfaces verwendet
lgmb