| [ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /* 3 * $Id: Domain.php 289 2005-11-27 19:13:01Z hans $ 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 please see 19 * <http://propel.phpdb.org>. 20 */ 21 22 require_once 'propel/engine/database/model/XMLElement.php'; 23 24 /** 25 * A Class for holding data about a column used in an Application. 26 * 27 * @author Hans Lellelid <hans@xmpl.org> (Propel) 28 * @author Martin Poeschl <mpoeschl@marmot.at> (Torque) 29 * @version $Revision: 289 $ 30 * @package propel.engine.database.model 31 */ 32 class Domain extends XMLElement { 33 34 private $name; 35 private $description; 36 private $size; 37 private $scale; 38 39 /** type as defined in schema.xml */ 40 private $propelType; 41 private $sqlType; 42 private $defaultValue; 43 44 /** Database object -- in the event this Domain is specified in the XML. */ 45 private $database; 46 47 /** 48 * Creates a new Domain object. 49 * If this domain needs a name, it must be specified manually. 50 * 51 * @param string $type Propel type. 52 * @param string $sqlType SQL type. 53 * @param string $size 54 * @param string $scale 55 */ 56 public function __construct($type = null, $sqlType = null, $size = null, $scale = null) 57 { 58 $this->propelType = $type; 59 $this->sqlType = ($sqlType !== null) ? $sqlType : $type; 60 $this->size = $size; 61 $this->scale = $scale; 62 } 63 64 public function copy(Domain $domain) 65 { 66 $this->defaultValue = $domain->getDefaultValue(); 67 $this->description = $domain->getDescription(); 68 $this->name = $domain->getName(); 69 $this->scale = $domain->getScale(); 70 $this->size = $domain->getSize(); 71 $this->sqlType = $domain->getSqlType(); 72 $this->propelType = $domain->getType(); 73 } 74 75 /** 76 * Sets up the Domain object based on the attributes that were passed to loadFromXML(). 77 * @see parent::loadFromXML() 78 */ 79 protected function setupObject() 80 { 81 $schemaType = strtoupper($this->getAttribute("type")); 82 $this->copy($this->getDatabase()->getPlatform()->getDomainForType($schemaType)); 83 84 //Name 85 $this->name = $this->getAttribute("name"); 86 87 //Default column value. 88 $this->defaultValue = $this->getAttribute("default"); // may need to adjust -- e.g. for boolean values 89 90 $this->size = $this->getAttribute("size"); 91 $this->scale = $this->getAttribute("scale"); 92 $this->description = $this->getAttribute("description"); 93 } 94 95 /** 96 * Sets the owning database object (if this domain is being setup via XML). 97 */ 98 public function setDatabase(Database $database) { 99 $this->database = $database; 100 } 101 102 /** 103 * Gets the owning database object (if this domain was setup via XML). 104 */ 105 public function getDatabase() { 106 return $this->database; 107 } 108 109 /** 110 * @return Returns the description. 111 */ 112 public function getDescription() 113 { 114 return $this->description; 115 } 116 117 /** 118 * @param description The description to set. 119 */ 120 public function setDescription($description) 121 { 122 $this->description = $description; 123 } 124 125 /** 126 * @return Returns the name. 127 */ 128 public function getName() 129 { 130 return $this->name; 131 } 132 133 /** 134 * @param name The name to set. 135 */ 136 public function setName($name) 137 { 138 $this->name = $name; 139 } 140 141 /** 142 * @return Returns the scale. 143 */ 144 public function getScale() 145 { 146 return $this->scale; 147 } 148 149 /** 150 * @param scale The scale to set. 151 */ 152 public function setScale($scale) 153 { 154 $this->scale = $scale; 155 } 156 157 /** 158 * Replaces the size if the new value is not null. 159 * 160 * @param value The size to set. 161 */ 162 public function replaceScale($value) 163 { 164 if ($value !== null) { 165 $this->scale = $value; 166 } 167 } 168 169 /** 170 * @return Returns the size. 171 */ 172 public function getSize() 173 { 174 return $this->size; 175 } 176 177 /** 178 * @param size The size to set. 179 */ 180 public function setSize($size) 181 { 182 $this->size = $size; 183 } 184 185 /** 186 * Replaces the size if the new value is not null. 187 * 188 * @param value The size to set. 189 */ 190 public function replaceSize($value) 191 { 192 if ($value !== null) { 193 $this->size = $value; 194 } 195 } 196 197 /** 198 * @return string Returns the propelType. 199 */ 200 public function getType() 201 { 202 return $this->propelType; 203 } 204 205 /** 206 * @param string $propelType The PropelTypes type to set. 207 */ 208 public function setType($propelType) 209 { 210 $this->propelType = $propelType; 211 } 212 213 /** 214 * Replaces the default value if the new value is not null. 215 * 216 * @param value The defaultValue to set. 217 */ 218 public function replaceType($value) 219 { 220 if ($value !== null) { 221 $this->propelType = $value; 222 } 223 } 224 225 /** 226 * Gets the "raw" default value, suitable for use in SQL. 227 * @return string Returns the defaultValue. 228 */ 229 public function getDefaultValue() 230 { 231 if ($this->defaultValue !== null) { 232 return $this->defaultValue; 233 } 234 } 235 236 /** 237 * Gets the default value, type-casted for use in PHP OM. 238 * @return mixed 239 * @see getDefaultValue() 240 */ 241 public function getPhpDefaultValue() 242 { 243 if ($this->defaultValue === null) { 244 return null; 245 } elseif ($this->propelType === PropelTypes::BOOLEAN) { 246 // convert "true" => TRUE 247 return $this->booleanValue($this->defaultValue); 248 } elseif ($this->propelType === PropelTypes::DATE || $this->propelType === PropelTypes::TIME || $this->propelType === PropelTypes::TIMESTAMP) { 249 // DATE/TIME vals need to be converted to integer timestamp 250 $ts = strtotime($this->defaultValue); 251 if ($ts === -1 || $ts === false) { // in PHP 5.1 return value changes to FALSE 252 throw new EngineException("Unable to parse default value as date/time value: " . var_export($this->defaultValue, true)); 253 } 254 return $ts; 255 } else { 256 return $this->defaultValue; 257 } 258 } 259 260 /** 261 * @param defaultValue The defaultValue to set. 262 */ 263 public function setDefaultValue($defaultValue) 264 { 265 $this->defaultValue = $defaultValue; 266 } 267 268 /** 269 * Replaces the default value if the new value is not null. 270 * 271 * @param string $value The defaultValue to set. 272 */ 273 public function replaceDefaultValue($value) 274 { 275 if ($value !== null) { 276 $this->defaultValue = $value; 277 } 278 } 279 280 /** 281 * @return Returns the sqlType. 282 */ 283 public function getSqlType() 284 { 285 return $this->sqlType; 286 } 287 288 /** 289 * @param string $sqlType The sqlType to set. 290 */ 291 public function setSqlType($sqlType) 292 { 293 $this->sqlType = $sqlType; 294 } 295 296 /** 297 * Return the size and scale in brackets for use in an sql schema. 298 * 299 * @return size and scale or an empty String if there are no values 300 * available. 301 */ 302 public function printSize() 303 { 304 if ($this->size !== null && $this->scale !== null) { 305 return '(' . $this->size . ',' . $this->scale . ')'; 306 } elseif ($this->size !== null) { 307 return '(' . $this->size . ')'; 308 } else { 309 return ""; 310 } 311 } 312 313 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |