1<?php 2/* 3 * $Id$ 4 * 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 * 17 * This software consists of voluntary contributions made by many individuals 18 * and is licensed under the LGPL. For more information, see 19 * <http://www.doctrine-project.org>. 20 */ 21 22/** 23 * Base abstract class for defining templates which are the base of all behaviors that can be attached 24 * to your Doctrine models 25 * 26 * @package Doctrine 27 * @subpackage Template 28 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL 29 * @link www.doctrine-project.org 30 * @since 1.0 31 * @version $Revision$ 32 * @author Konsta Vesterinen <kvesteri@cc.hut.fi> 33 */ 34abstract class Doctrine_Template extends Doctrine_Record_Abstract 35{ 36 /** 37 * @var Doctrine_Record $_invoker the record that invoked the last delegated call 38 */ 39 protected $_invoker; 40 41 /** 42 * @var Doctrine_Record_Generator $_plugin 43 */ 44 protected $_plugin; 45 46 /** 47 * @var array $_options Template options 48 */ 49 protected $_options = array(); 50 51 /** 52 * __construct 53 * 54 * @param string $array 55 * @return void 56 */ 57 public function __construct(array $options = array()) 58 { 59 $this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options); 60 } 61 62 /** 63 * Set the table object that this Template belongs to 64 * 65 * @var Doctrine_Table $table the table object this Template belongs to 66 */ 67 public function setTable(Doctrine_Table $table) 68 { 69 $this->_table = $table; 70 } 71 72 /** 73 * returns the associated table object 74 * 75 * @return Doctrine_Table the associated table object 76 */ 77 public function getTable() 78 { 79 return $this->_table; 80 } 81 82 /** 83 * sets the last used invoker 84 * 85 * @param Doctrine_Record $invoker the record that invoked the last delegated call 86 * @return Doctrine_Template this object 87 */ 88 public function setInvoker(Doctrine_Record_Abstract $invoker) 89 { 90 $this->_invoker = $invoker; 91 } 92 93 /** 94 * returns the last used invoker 95 * 96 * @return Doctrine_Record the record that invoked the last delegated call 97 */ 98 public function getInvoker() 99 { 100 return $this->_invoker; 101 } 102 103 /** 104 * Adds a plugin as a child to this plugin 105 * 106 * @param Doctrine_Template $template 107 * @return Doctrine_Template. Chainable. 108 */ 109 public function addChild(Doctrine_Template $template) 110 { 111 $this->_plugin->addChild($template); 112 113 return $this; 114 } 115 116 /** 117 * Get plugin instance 118 * 119 * @return void 120 */ 121 public function getPlugin() 122 { 123 return $this->_plugin; 124 } 125 126 /** 127 * Check if this template has a generator plugin 128 * 129 * @return boolean 130 */ 131 public function hasPlugin() 132 { 133 return isset($this->_plugin) ? true : false; 134 } 135 136 /** 137 * getOptions 138 * returns all options of this template and the associated values 139 * 140 * @return array all options and their values 141 */ 142 public function getOptions() 143 { 144 return $this->_options; 145 } 146 147 /** 148 * getOption 149 * returns the value of given option 150 * 151 * @param string $name the name of the option 152 * @param mixed $default default value if option is not found 153 * @return mixed the value of given option 154 */ 155 public function getOption($name, $default = null) 156 { 157 if (isset($this->_options[$name])) { 158 return $this->_options[$name]; 159 } 160 return $default; 161 } 162 163 /** 164 * get 165 * 166 * @param mixed $name 167 * @return void 168 */ 169 public function get($name) 170 { 171 throw new Doctrine_Exception("Templates doesn't support accessors."); 172 } 173 174 /** 175 * set 176 * 177 * @param mixed $name 178 * @param mixed $value 179 * @return void 180 */ 181 public function set($name, $value) 182 { 183 throw new Doctrine_Exception("Templates doesn't support accessors."); 184 } 185 186 /** 187 * Blank method for template setup 188 * 189 * @return void 190 */ 191 public function setUp() 192 { 193 194 } 195 196 /** 197 * Blank method for template table definition 198 * 199 * @return void 200 */ 201 public function setTableDefinition() 202 { 203 204 } 205}