<?php

class Goweb_Chart_Styles_Application {
    
    // ------------------------------------------------ //
    // PROPERTIES -------------------------- PROPERTIES //
    // ------------------------------------------------ //
    
    private $_apply = array();
    private $_options = array();
    private $_applyElement = array();
    
    // ------------------------------------------------ //
    // METHODS -------------------------------- METHODS //
    // ------------------------------------------------ //
    public function __construct() {
        $this->_options = array('toObject', 'styles');
    }
    
    public function add() {
        $applyInput = '<apply ';
        foreach ($this->_apply as $key => $value) {
            $applyInput .= $key . "='" . $value . "' ";
        }
        $applyInput .= ' />';
        $this->_applyElement[] = $applyInput;
        
        $this->_clearOptions();
    }
    
    public function render() {
        if (count($this->_applyElement) > 0) {
            $applyInputs = '';
            $applyInputs .= '<application>';
            foreach ($this->_applyElement as $applyElement) {
                $applyInputs .= $applyElement;
            }
            $applyInputs .= '</application>';
            return $applyInputs;
        } else {
            return "";
        }
    }
    
    public function __set($key, $value) {
        if (in_array($key, $this->_options)) {
            $this->_apply[$key] = $value;
        }
    }
    
    private function _clearOptions() {
        $this->_apply = array();
    }
    
}

?>
