| [ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * $Id: BaseObject.php 316 2005-12-29 14:33:08Z hans $ 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/om/Persistent.php'; 24 25 /** 26 * This class contains attributes and methods that are used by all 27 * business objects within the system. 28 * 29 * @author Hans Lellelid <hans@xmpl.org> (Propel) 30 * @author Frank Y. Kim <frank.kim@clearink.com> (Torque) 31 * @author John D. McNally <jmcnally@collab.net> (Torque) 32 * @version $Revision: 316 $ 33 * @package propel.om 34 */ 35 abstract class BaseObject { 36 37 /** 38 * attribute to determine if this object has previously been saved. 39 * @var boolean 40 */ 41 private $_new = true; 42 43 /** 44 * attribute to determine whether this object has been deleted. 45 * @var boolean 46 */ 47 private $_deleted = false; 48 49 /** 50 * The columns that have been modified in current object. 51 * Tracking modified columns allows us to only update modified columns. 52 * @var array 53 */ 54 protected $modifiedColumns = array(); 55 56 /** 57 * Returns whether the object has been modified. 58 * 59 * @return boolean True if the object has been modified. 60 */ 61 public function isModified() 62 { 63 return !empty($this->modifiedColumns); 64 } 65 66 /** 67 * Has specified column been modified? 68 * 69 * @param string $col 70 * @return boolean True if $col has been modified. 71 */ 72 public function isColumnModified($col) 73 { 74 return in_array($col, $this->modifiedColumns); 75 } 76 77 /** 78 * Returns whether the object has ever been saved. This will 79 * be false, if the object was retrieved from storage or was created 80 * and then saved. 81 * 82 * @return true, if the object has never been persisted. 83 */ 84 public function isNew() 85 { 86 return $this->_new; 87 } 88 89 /** 90 * Setter for the isNew attribute. This method will be called 91 * by Propel-generated children and Peers. 92 * 93 * @param boolean $b the state of the object. 94 */ 95 public function setNew($b) 96 { 97 $this->_new = (boolean) $b; 98 } 99 100 /** 101 * Whether this object has been deleted. 102 * @return boolean The deleted state of this object. 103 */ 104 public function isDeleted() 105 { 106 return $this->_deleted; 107 } 108 109 /** 110 * Specify whether this object has been deleted. 111 * @param boolean $b The deleted state of this object. 112 * @return void 113 */ 114 public function setDeleted($b) 115 { 116 $this->_deleted = (boolean) $b; 117 } 118 119 /** 120 * Sets the modified state for the object to be false. 121 * @param string $col If supplied, only the specified column is reset. 122 * @return void 123 */ 124 public function resetModified($col = null) 125 { 126 if ($col !== null) 127 { 128 while (($offset = array_search($col, $this->modifiedColumns)) !== false) 129 array_splice($this->modifiedColumns, $offset, 1); 130 } 131 else 132 { 133 $this->modifiedColumns = array(); 134 } 135 } 136 137 /** 138 * Compares this with another <code>BaseObject</code> instance. If 139 * <code>obj</code> is an instance of <code>BaseObject</code>, delegates to 140 * <code>equals(BaseObject)</code>. Otherwise, returns <code>false</code>. 141 * 142 * @param obj The object to compare to. 143 * @return Whether equal to the object specified. 144 */ 145 public function equals($obj) 146 { 147 if (is_object($obj)) { 148 if ($this === $obj) { 149 return true; 150 } elseif ($this->getPrimaryKey() === null || $obj->getPrimaryKey() === null) { 151 return false; 152 } else { 153 return ($this->getPrimaryKey() === $obj->getPrimaryKey()); 154 } 155 } else { 156 return false; 157 } 158 } 159 160 /** 161 * If the primary key is not <code>null</code>, return the hashcode of the 162 * primary key. Otherwise calls <code>Object.hashCode()</code>. 163 * 164 * @return int Hashcode 165 */ 166 public function hashCode() 167 { 168 $ok = $this->getPrimaryKey(); 169 if ($ok === null) { 170 return crc32(serialize($this)); 171 } 172 return crc32(serialize($ok)); // serialize because it could be an array ("ComboKey") 173 } 174 175 /** 176 * Logs a message using Propel::log(). 177 * 178 * @param string $msg 179 * @param int $priority One of the Propel::LOG_* logging levels 180 * @return boolean 181 */ 182 protected function log($msg, $priority = Propel::LOG_INFO) 183 { 184 return Propel::log(get_class($this) . ': ' . $msg, $priority); 185 } 186 187 }
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 |