| 1 |
<?php |
| 2 |
|
| 3 |
// +----------------------------------------------------------------------+ |
| 4 |
// | Copyright 2013 Madpixels (email : visualizer@madpixels.net) | |
| 5 |
// +----------------------------------------------------------------------+ |
| 6 |
// | This program is free software; you can redistribute it and/or modify | |
| 7 |
// | it under the terms of the GNU General Public License, version 2, as | |
| 8 |
// | published by the Free Software Foundation. | |
| 9 |
// | | |
| 10 |
// | This program is distributed in the hope that it will be useful, | |
| 11 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 |
// | GNU General Public License for more details. | |
| 14 |
// | | |
| 15 |
// | You should have received a copy of the GNU General Public License | |
| 16 |
// | along with this program; if not, write to the Free Software | |
| 17 |
// | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, | |
| 18 |
// | MA 02110-1301 USA | |
| 19 |
// +----------------------------------------------------------------------+ |
| 20 |
// | Author: Eugene Manuilov <eugene@manuilov.org> | |
| 21 |
// +----------------------------------------------------------------------+ |
| 22 |
/** |
| 23 |
* Abstract render class implements all routine stuff required for template |
| 24 |
* rendering. |
| 25 |
* |
| 26 |
* @category Visualizer |
| 27 |
* @package Render |
| 28 |
* |
| 29 |
* @since 1.0.0 |
| 30 |
* @abstract |
| 31 |
*/ |
| 32 |
abstract class Visualizer_Render { |
| 33 |
|
| 34 |
/** |
| 35 |
* The storage of all data associated with this render. |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
* |
| 39 |
* @access protected |
| 40 |
* @var array |
| 41 |
*/ |
| 42 |
protected $_data; |
| 43 |
|
| 44 |
/** |
| 45 |
* Constructor. |
| 46 |
* |
| 47 |
* @since 1.0.0 |
| 48 |
* |
| 49 |
* @access public |
| 50 |
* @param array $data The data what has to be associated with this render. |
| 51 |
*/ |
| 52 |
public function __construct( $data = array() ) { |
| 53 |
$this->_data = $data; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Returns property associated with the render. |
| 58 |
* |
| 59 |
* @since 1.0.0 |
| 60 |
* |
| 61 |
* @access public |
| 62 |
* @param string $name The name of a property. |
| 63 |
* @return mixed Returns mixed value of a property or NULL if a property doesn't exist. |
| 64 |
*/ |
| 65 |
public function __get( $name ) { |
| 66 |
return array_key_exists( $name, $this->_data ) ? $this->_data[ $name ] : null; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Checks whether the render has specific property or not. |
| 71 |
* |
| 72 |
* @since 1.0.0 |
| 73 |
* |
| 74 |
* @access public |
| 75 |
* @param string $name The key name. |
| 76 |
* @return boolean TRUE if the property exists, otherwise FALSE. |
| 77 |
*/ |
| 78 |
public function __isset( $name ) { |
| 79 |
return array_key_exists( $name, $this->_data ); |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Associates the render with specific property. |
| 84 |
* |
| 85 |
* @since 1.0.0 |
| 86 |
* |
| 87 |
* @access public |
| 88 |
* @param string $name The name of a property to associate. |
| 89 |
* @param mixed $value The value of a property. |
| 90 |
*/ |
| 91 |
public function __set( $name, $value ) { |
| 92 |
$this->_data[ $name ] = $value; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Unassociates specific property from the render. |
| 97 |
* |
| 98 |
* @since 1.0.0 |
| 99 |
* |
| 100 |
* @access public |
| 101 |
* @param string $name The name of the property to unassociate. |
| 102 |
*/ |
| 103 |
public function __unset( $name ) { |
| 104 |
unset( $this->_data[ $name ] ); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Renders template. |
| 109 |
* |
| 110 |
* @since 1.0.0 |
| 111 |
* |
| 112 |
* @abstract |
| 113 |
* @access protected |
| 114 |
*/ |
| 115 |
protected abstract function _toHTML(); |
| 116 |
|
| 117 |
/** |
| 118 |
* Builds template and return it as string. |
| 119 |
* |
| 120 |
* @since 1.0.0 |
| 121 |
* |
| 122 |
* @access public |
| 123 |
* @return string |
| 124 |
*/ |
| 125 |
public function toHtml() { |
| 126 |
ob_start(); |
| 127 |
$this->_toHTML(); |
| 128 |
return ob_get_clean(); |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* Returns built template as string. |
| 133 |
* |
| 134 |
* @since 1.0.0 |
| 135 |
* |
| 136 |
* @access public |
| 137 |
* @return type |
| 138 |
*/ |
| 139 |
public function __toString() { |
| 140 |
return $this->toHtml(); |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Renders the template. |
| 145 |
* |
| 146 |
* @since 1.0.0 |
| 147 |
* |
| 148 |
* @access public |
| 149 |
*/ |
| 150 |
public function render() { |
| 151 |
$this->_toHTML(); |
| 152 |
} |
| 153 |
|
| 154 |
} |
| 155 |
|