| [ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * $Id: PeerBuilder.php 228 2005-10-15 10:28:42Z david $ 5 * 6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 7 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 8 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 9 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 10 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 12 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 16 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 17 * 18 * This software consists of voluntary contributions made by many individuals 19 * and is licensed under the LGPL. For more information please see 20 * <http://propel.phpdb.org>. 21 */ 22 23 require_once 'propel/engine/builder/om/OMBuilder.php'; 24 25 /** 26 * Base class for Peer-building classes. 27 * 28 * This class is designed so that it can be extended by a PHP4PeerBuilder in addition 29 * to the "standard" PHP5PeerBuilder and PHP5ComplexOMPeerBuilder. Hence, this class 30 * should not have any actual template code in it -- simply basic logic & utility 31 * methods. 32 * 33 * @author Hans Lellelid <hans@xmpl.org> 34 */ 35 abstract class PeerBuilder extends OMBuilder { 36 37 protected $basePeerClass; 38 protected $basePeerClassname; 39 40 /** 41 * Constructs a new PeerBuilder subclass. 42 */ 43 public function __construct(Table $table) { 44 parent::__construct($table); 45 $this->basePeerClass = $this->getBasePeer($table); 46 $this->basePeerClassname = $this->classname($this->basePeerClass); 47 } 48 49 /** 50 * Adds the addSelectColumns(), doCount(), etc. methods. 51 * @param string &$script The script will be modified in this method. 52 */ 53 protected function addSelectMethods(&$script) 54 { 55 $this->addAddSelectColumns($script); 56 57 $this->addCountConstants($script); 58 $this->addDoCount($script); 59 60 // consider refactoring the doSelect stuff 61 // into a top-level method 62 $this->addDoSelectOne($script); 63 $this->addDoSelect($script); 64 $this->addDoSelectRS($script); // <-- there's Creole code in here 65 $this->addPopulateObjects($script); // <-- there's Creole code in here 66 67 } 68 69 /** 70 * Adds the correct getOMClass() method, depending on whether this table uses inheritance. 71 * @param string &$script The script will be modified in this method. 72 */ 73 protected function addGetOMClassMethod(&$script) 74 { 75 $table = $this->getTable(); 76 if ($table->getChildrenColumn()) { 77 if ($table->isAbstract()) { 78 $this->addGetOMClass_Inheritance_Abstract($script); 79 } else { 80 $this->addGetOMClass_Inheritance($script); 81 } 82 } else { 83 if ($table->isAbstract()) { 84 $this->addGetOMClass_NoInheritance_Abstract($script); 85 } else { 86 $this->addGetOMClass_NoInheritance($script); 87 } 88 } 89 } 90 91 /** 92 * Adds the doInsert(), doUpdate(), doDeleteAll(), doValidate(), etc. methods. 93 * @param string &$script The script will be modified in this method. 94 */ 95 protected function addUpdateMethods(&$script) 96 { 97 $this->addDoInsert($script); 98 $this->addDoUpdate($script); 99 $this->addDoDeleteAll($script); 100 $this->addDoDelete($script); 101 if ($this->isDeleteCascadeEmulationNeeded()) { 102 $this->addDoOnDeleteCascade($script); 103 } 104 if ($this->isDeleteSetNullEmulationNeeded()) { 105 $this->addDoOnDeleteSetNull($script); 106 } 107 $this->addDoValidate($script); 108 } 109 110 /** 111 * Adds the retrieveByPK() (and possibly retrieveByPKs()) method(s) appropriate for this class. 112 * @param string &$script The script will be modified in this method. 113 */ 114 protected function addRetrieveByPKMethods(&$script) 115 { 116 if (count($this->getTable()->getPrimaryKey()) === 1) { 117 $this->addRetrieveByPK_SinglePK($script); 118 $this->addRetrieveByPKs_SinglePK($script); 119 } else { 120 $this->addRetrieveByPK_MultiPK($script); 121 } 122 } 123 124 /** 125 * This method adds the contents of the generated class to the script. 126 * 127 * This method contains the high-level logic that determines which methods 128 * get generated. 129 * 130 * Hint: Override this method in your subclass if you want to reorganize or 131 * drastically change the contents of the generated peer class. 132 * 133 * @param string &$script The script will be modified in this method. 134 */ 135 protected function addClassBody(&$script) 136 { 137 138 $table = $this->getTable(); 139 140 if (!$table->isAlias()) { 141 $this->addConstantsAndAttributes($script); 142 } 143 144 $this->addGetMapBuilder($script); 145 $this->addGetPhpNameMap($script); 146 147 $this->addTranslateFieldName($script); 148 $this->addGetFieldNames($script); 149 150 if (!$table->isAlias()) { 151 $this->addAlias($script); // alias() utility method (deprecated?) 152 $this->addSelectMethods($script); 153 $this->addGetTableMap($script); 154 } 155 156 $this->addGetOMClassMethod($script); 157 158 // add the insert, update, delete, validate etc. methods 159 if (!$table->isAlias() && !$table->isReadOnly()) { 160 $this->addUpdateMethods($script); 161 } 162 163 if (count($table->getPrimaryKey()) > 0) { 164 $this->addRetrieveByPKMethods($script); 165 } 166 } 167 168 /** 169 * Whether the platform in use requires ON DELETE CASCADE emulation and whether there are references to this table. 170 * @return boolean 171 */ 172 protected function isDeleteCascadeEmulationNeeded() 173 { 174 $table = $this->getTable(); 175 if ((!$this->getPlatform()->supportsNativeDeleteTrigger() || $this->getBuildProperty('emulateForeignKeyConstraints')) && count($table->getReferrers()) > 0) { 176 foreach ($table->getReferrers() as $fk) { 177 if ($fk->getOnDelete() == ForeignKey::CASCADE) { 178 return true; 179 } 180 } 181 } 182 return false; 183 } 184 185 /** 186 * Whether the platform in use requires ON DELETE SETNULL emulation and whether there are references to this table. 187 * @return boolean 188 */ 189 protected function isDeleteSetNullEmulationNeeded() 190 { 191 $table = $this->getTable(); 192 if ((!$this->getPlatform()->supportsNativeDeleteTrigger() || $this->getBuildProperty('emulateForeignKeyConstraints')) && count($table->getReferrers()) > 0) { 193 foreach ($table->getReferrers() as $fk) { 194 if ($fk->getOnDelete() == ForeignKey::SETNULL) { 195 return true; 196 } 197 } 198 } 199 return false; 200 } 201 202 /** 203 * Whether to add the generic mutator methods (setByName(), setByPosition(), fromArray()). 204 * This is based on the build property propel.addGenericMutators, and also whether the 205 * table is read-only or an alias. 206 * @return boolean 207 */ 208 protected function isAddGenericMutators() 209 { 210 $table = $this->getTable(); 211 return (!$table->isAlias() && $this->getBuildProperty('addGenericMutators') && !$table->isReadOnly()); 212 } 213 214 /** 215 * Whether to add the generic accessor methods (getByName(), getByPosition(), toArray()). 216 * This is based on the build property propel.addGenericAccessors, and also whether the 217 * table is an alias. 218 * @return boolean 219 */ 220 protected function isAddGenericAccessors() 221 { 222 $table = $this->getTable(); 223 return (!$table->isAlias() && $this->getBuildProperty('addGenericAccessors')); 224 } 225 226 /** 227 * Returns the retrieveByPK method name to use for this table. 228 * If the table is an alias then the method name looks like "retrieveTablenameByPK" 229 * otherwise simply "retrieveByPK". 230 * @return string 231 */ 232 public function getRetrieveMethodName() 233 { 234 if ($this->getTable()->isAlias()) { 235 $retrieveMethod = "retrieve" . $this->getTable()->getPhpName() . "ByPK"; 236 } else { 237 $retrieveMethod = "retrieveByPK"; 238 } 239 return $retrieveMethod; 240 } 241 242 243 /** 244 * COMPATIBILITY: Get the column constant name (e.g. PeerName::COLUMN_NAME). 245 * 246 * This method exists simply because it belonged to the 'PeerBuilder' that this 247 * class is replacing (because of name conflict more than actual functionality overlap). 248 * When the new builder model is finished this method will be removed. 249 * 250 * @param Column $col The column we need a name for. 251 * @param string $phpName The PHP Name of the peer class. The 'Peer' is appended automatically. 252 * 253 * @return string If $phpName is provided, then will return {$phpName}Peer::COLUMN_NAME; if not, just COLUMN_NAME. 254 * @deprecated 255 */ 256 public static function getColumnName(Column $col, $phpName = null) { 257 // was it overridden in schema.xml ? 258 if ($col->getPeerName()) { 259 $const = strtoupper($col->getPeerName()); 260 } else { 261 $const = strtoupper($col->getName()); 262 } 263 if ($phpName !== null) { 264 return $phpName . 'Peer::' . $const; 265 } else { 266 return $const; 267 } 268 } 269 }
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 |