dgmike
11/29/2011 - 12:51 PM

table specs

table specs

<?php
class Table
{


    public function setUp(array $setup)
    {
        $attributes = array();

        // HTML5 model, specs at:
        // http://www.w3.org/TR/html5/tabular-data.html#the-table-element
        $attributes['html5'] = array(
            // Global attributes:
            // http://www.w3.org/TR/html5/elements.html#global-attributes
            'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir',
            'draggable', 'dropzone', 'hidden', 'id', 'lang', 'spellcheck',
            'style', 'tabindex', 'title',
            // Table attributes:
            'border',
            // Event attributes:
            // http://www.w3.org/TR/html5/elements.html#global-attributes
            'onabort', 'onblur', 'oncanplay', 'oncanplaythrough', 'onchange',
            'onclick', 'oncontextmenu', 'oncuechange', 'ondblclick', 'ondrag',
            'ondragend', 'ondragenter', 'ondragleave', 'ondragover',
            'ondragstart', 'ondrop', 'ondurationchange', 'onemptied', 'onended',
            'onerror', 'onfocus', 'oninput', 'oninvalid', 'onkeydown',
            'onkeypress', 'onkeyup', 'onload', 'onloadeddata',
            'onloadedmetadata', 'onloadstart', 'onmousedown', 'onmousemove',
            'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onpause',
            'onplay', 'onplaying', 'onprogress', 'onratechange',
            'onreadystatechange', 'onreset', 'onscroll', 'onseeked',
            'onseeking', 'onselect', 'onshow', 'onstalled', 'onsubmit',
            'onsuspend', 'ontimeupdate', 'onvolumechange', 'onwaiting',
        );

        // XHTML model, specs at:
        // http://www.w3.org/2010/04/xhtml10-strict.html#elem_table
        $attributes['html'] = array(
            // Event Attributes
            'onmouseup', 'onmouseout', 'onkeypress', 'onkeydown', 'onmousedown',
            'onmousemove', 'onmouseover', 'onclick', 'onkeyup', 'ondblclick',
            // Style Attributes
            'style',
            // Other
            'frame', 'border', 'id', 'title', 'width', 'cellspacing', 'rules',
            'cellpadding', 'class', 'lang', 'summary', 'xml:lang', 'dir',
        );

        $attributes = self::HTML5 === $this->tableSpecs ? $attributes['html5']
                                                        : $attributes['html'];

        foreach($attributes as $attribute) {
            if (array_key_exists($attribute, $setup)) {
                $this->tableProps[$attribute] = $setup[$attribute];
            }
        }

        if (array_key_exists('caption', $setup) {
            $this->caption($setup['caption']);
        }
        return $this;
    }
}