Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Connection often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Connection, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | abstract class Connection implements ActiveRecordInterface |
||
| 35 | { |
||
| 36 | /** |
||
| 37 | * TableMap class name |
||
| 38 | */ |
||
| 39 | const TABLE_MAP = '\\Jalle19\\StatusManager\\Database\\Map\\ConnectionTableMap'; |
||
| 40 | |||
| 41 | |||
| 42 | /** |
||
| 43 | * attribute to determine if this object has previously been saved. |
||
| 44 | * @var boolean |
||
| 45 | */ |
||
| 46 | protected $new = true; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * attribute to determine whether this object has been deleted. |
||
| 50 | * @var boolean |
||
| 51 | */ |
||
| 52 | protected $deleted = false; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * The columns that have been modified in current object. |
||
| 56 | * Tracking modified columns allows us to only update modified columns. |
||
| 57 | * @var array |
||
| 58 | */ |
||
| 59 | protected $modifiedColumns = array(); |
||
| 60 | |||
| 61 | /** |
||
| 62 | * The (virtual) columns that are added at runtime |
||
| 63 | * The formatters can add supplementary columns based on a resultset |
||
| 64 | * @var array |
||
| 65 | */ |
||
| 66 | protected $virtualColumns = array(); |
||
| 67 | |||
| 68 | /** |
||
| 69 | * The value for the id field. |
||
| 70 | * |
||
| 71 | * @var int |
||
| 72 | */ |
||
| 73 | protected $id; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * The value for the instance_name field. |
||
| 77 | * |
||
| 78 | * @var string |
||
| 79 | */ |
||
| 80 | protected $instance_name; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * The value for the user_id field. |
||
| 84 | * |
||
| 85 | * @var int |
||
| 86 | */ |
||
| 87 | protected $user_id; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * The value for the peer field. |
||
| 91 | * |
||
| 92 | * @var string |
||
| 93 | */ |
||
| 94 | protected $peer; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * The value for the started field. |
||
| 98 | * |
||
| 99 | * @var \DateTime |
||
| 100 | */ |
||
| 101 | protected $started; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * The value for the type field. |
||
| 105 | * |
||
| 106 | * @var string |
||
| 107 | */ |
||
| 108 | protected $type; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @var ChildInstance |
||
| 112 | */ |
||
| 113 | protected $aInstance; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @var ChildUser |
||
| 117 | */ |
||
| 118 | protected $aUser; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Flag to prevent endless save loop, if this object is referenced |
||
| 122 | * by another object which falls in this transaction. |
||
| 123 | * |
||
| 124 | * @var boolean |
||
| 125 | */ |
||
| 126 | protected $alreadyInSave = false; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Initializes internal state of Jalle19\StatusManager\Database\Base\Connection object. |
||
| 130 | */ |
||
| 131 | public function __construct() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Returns whether the object has been modified. |
||
| 137 | * |
||
| 138 | * @return boolean True if the object has been modified. |
||
| 139 | */ |
||
| 140 | public function isModified() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Has specified column been modified? |
||
| 147 | * |
||
| 148 | * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID |
||
| 149 | * @return boolean True if $col has been modified. |
||
| 150 | */ |
||
| 151 | public function isColumnModified($col) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Get the columns that have been modified in this object. |
||
| 158 | * @return array A unique list of the modified column names for this object. |
||
| 159 | */ |
||
| 160 | public function getModifiedColumns() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Returns whether the object has ever been saved. This will |
||
| 167 | * be false, if the object was retrieved from storage or was created |
||
| 168 | * and then saved. |
||
| 169 | * |
||
| 170 | * @return boolean true, if the object has never been persisted. |
||
| 171 | */ |
||
| 172 | public function isNew() |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Setter for the isNew attribute. This method will be called |
||
| 179 | * by Propel-generated children and objects. |
||
| 180 | * |
||
| 181 | * @param boolean $b the state of the object. |
||
| 182 | */ |
||
| 183 | public function setNew($b) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Whether this object has been deleted. |
||
| 190 | * @return boolean The deleted state of this object. |
||
| 191 | */ |
||
| 192 | public function isDeleted() |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Specify whether this object has been deleted. |
||
| 199 | * @param boolean $b The deleted state of this object. |
||
| 200 | * @return void |
||
| 201 | */ |
||
| 202 | public function setDeleted($b) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Sets the modified state for the object to be false. |
||
| 209 | * @param string $col If supplied, only the specified column is reset. |
||
| 210 | * @return void |
||
| 211 | */ |
||
| 212 | View Code Duplication | public function resetModified($col = null) |
|
| 222 | |||
| 223 | /** |
||
| 224 | * Compares this with another <code>Connection</code> instance. If |
||
| 225 | * <code>obj</code> is an instance of <code>Connection</code>, delegates to |
||
| 226 | * <code>equals(Connection)</code>. Otherwise, returns <code>false</code>. |
||
| 227 | * |
||
| 228 | * @param mixed $obj The object to compare to. |
||
| 229 | * @return boolean Whether equal to the object specified. |
||
| 230 | */ |
||
| 231 | View Code Duplication | public function equals($obj) |
|
| 247 | |||
| 248 | /** |
||
| 249 | * Get the associative array of the virtual columns in this object |
||
| 250 | * |
||
| 251 | * @return array |
||
| 252 | */ |
||
| 253 | public function getVirtualColumns() |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Checks the existence of a virtual column in this object |
||
| 260 | * |
||
| 261 | * @param string $name The virtual column name |
||
| 262 | * @return boolean |
||
| 263 | */ |
||
| 264 | public function hasVirtualColumn($name) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Get the value of a virtual column in this object |
||
| 271 | * |
||
| 272 | * @param string $name The virtual column name |
||
| 273 | * @return mixed |
||
| 274 | * |
||
| 275 | * @throws PropelException |
||
| 276 | */ |
||
| 277 | View Code Duplication | public function getVirtualColumn($name) |
|
| 285 | |||
| 286 | /** |
||
| 287 | * Set the value of a virtual column in this object |
||
| 288 | * |
||
| 289 | * @param string $name The virtual column name |
||
| 290 | * @param mixed $value The value to give to the virtual column |
||
| 291 | * |
||
| 292 | * @return $this|Connection The current object, for fluid interface |
||
| 293 | */ |
||
| 294 | public function setVirtualColumn($name, $value) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Logs a message using Propel::log(). |
||
| 303 | * |
||
| 304 | * @param string $msg |
||
| 305 | * @param int $priority One of the Propel::LOG_* logging levels |
||
| 306 | * @return boolean |
||
| 307 | */ |
||
| 308 | protected function log($msg, $priority = Propel::LOG_INFO) |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Export the current object properties to a string, using a given parser format |
||
| 315 | * <code> |
||
| 316 | * $book = BookQuery::create()->findPk(9012); |
||
| 317 | * echo $book->exportTo('JSON'); |
||
| 318 | * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
| 319 | * </code> |
||
| 320 | * |
||
| 321 | * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
| 322 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. |
||
| 323 | * @return string The exported data |
||
| 324 | */ |
||
| 325 | View Code Duplication | public function exportTo($parser, $includeLazyLoadColumns = true) |
|
| 333 | |||
| 334 | /** |
||
| 335 | * Clean up internal collections prior to serializing |
||
| 336 | * Avoids recursive loops that turn into segmentation faults when serializing |
||
| 337 | */ |
||
| 338 | View Code Duplication | public function __sleep() |
|
| 352 | |||
| 353 | /** |
||
| 354 | * Get the [id] column value. |
||
| 355 | * |
||
| 356 | * @return int |
||
| 357 | */ |
||
| 358 | public function getId() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Get the [instance_name] column value. |
||
| 365 | * |
||
| 366 | * @return string |
||
| 367 | */ |
||
| 368 | public function getInstanceName() |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Get the [user_id] column value. |
||
| 375 | * |
||
| 376 | * @return int |
||
| 377 | */ |
||
| 378 | public function getUserId() |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Get the [peer] column value. |
||
| 385 | * |
||
| 386 | * @return string |
||
| 387 | */ |
||
| 388 | public function getPeer() |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Get the [optionally formatted] temporal [started] column value. |
||
| 395 | * |
||
| 396 | * |
||
| 397 | * @param string $format The date/time format string (either date()-style or strftime()-style). |
||
| 398 | * If format is NULL, then the raw DateTime object will be returned. |
||
| 399 | * |
||
| 400 | * @return string|DateTime Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL |
||
| 401 | * |
||
| 402 | * @throws PropelException - if unable to parse/validate the date/time value. |
||
| 403 | */ |
||
| 404 | View Code Duplication | public function getStarted($format = NULL) |
|
| 412 | |||
| 413 | /** |
||
| 414 | * Get the [type] column value. |
||
| 415 | * |
||
| 416 | * @return string |
||
| 417 | */ |
||
| 418 | public function getType() |
||
| 422 | |||
| 423 | /** |
||
| 424 | * Set the value of [id] column. |
||
| 425 | * |
||
| 426 | * @param int $v new value |
||
| 427 | * @return $this|\Jalle19\StatusManager\Database\Connection The current object (for fluent API support) |
||
| 428 | */ |
||
| 429 | public function setId($v) |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Set the value of [instance_name] column. |
||
| 445 | * |
||
| 446 | * @param string $v new value |
||
| 447 | * @return $this|\Jalle19\StatusManager\Database\Connection The current object (for fluent API support) |
||
| 448 | */ |
||
| 449 | View Code Duplication | public function setInstanceName($v) |
|
| 466 | |||
| 467 | /** |
||
| 468 | * Set the value of [user_id] column. |
||
| 469 | * |
||
| 470 | * @param int $v new value |
||
| 471 | * @return $this|\Jalle19\StatusManager\Database\Connection The current object (for fluent API support) |
||
| 472 | */ |
||
| 473 | View Code Duplication | public function setUserId($v) |
|
| 490 | |||
| 491 | /** |
||
| 492 | * Set the value of [peer] column. |
||
| 493 | * |
||
| 494 | * @param string $v new value |
||
| 495 | * @return $this|\Jalle19\StatusManager\Database\Connection The current object (for fluent API support) |
||
| 496 | */ |
||
| 497 | public function setPeer($v) |
||
| 510 | |||
| 511 | /** |
||
| 512 | * Sets the value of [started] column to a normalized version of the date/time value specified. |
||
| 513 | * |
||
| 514 | * @param mixed $v string, integer (timestamp), or \DateTime value. |
||
| 515 | * Empty strings are treated as NULL. |
||
| 516 | * @return $this|\Jalle19\StatusManager\Database\Connection The current object (for fluent API support) |
||
| 517 | */ |
||
| 518 | View Code Duplication | public function setStarted($v) |
|
| 530 | |||
| 531 | /** |
||
| 532 | * Set the value of [type] column. |
||
| 533 | * |
||
| 534 | * @param string $v new value |
||
| 535 | * @return $this|\Jalle19\StatusManager\Database\Connection The current object (for fluent API support) |
||
| 536 | */ |
||
| 537 | public function setType($v) |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Indicates whether the columns in this object are only set to default values. |
||
| 553 | * |
||
| 554 | * This method can be used in conjunction with isModified() to indicate whether an object is both |
||
| 555 | * modified _and_ has some values set which are non-default. |
||
| 556 | * |
||
| 557 | * @return boolean Whether the columns in this object are only been set with default values. |
||
| 558 | */ |
||
| 559 | public function hasOnlyDefaultValues() |
||
| 564 | |||
| 565 | /** |
||
| 566 | * Hydrates (populates) the object variables with values from the database resultset. |
||
| 567 | * |
||
| 568 | * An offset (0-based "start column") is specified so that objects can be hydrated |
||
| 569 | * with a subset of the columns in the resultset rows. This is needed, for example, |
||
| 570 | * for results of JOIN queries where the resultset row includes columns from two or |
||
| 571 | * more tables. |
||
| 572 | * |
||
| 573 | * @param array $row The row returned by DataFetcher->fetch(). |
||
| 574 | * @param int $startcol 0-based offset column which indicates which restultset column to start with. |
||
| 575 | * @param boolean $rehydrate Whether this object is being re-hydrated from the database. |
||
| 576 | * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). |
||
| 577 | One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 578 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 579 | * |
||
| 580 | * @return int next starting column |
||
| 581 | * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. |
||
| 582 | */ |
||
| 583 | public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) |
||
| 618 | |||
| 619 | /** |
||
| 620 | * Checks and repairs the internal consistency of the object. |
||
| 621 | * |
||
| 622 | * This method is executed after an already-instantiated object is re-hydrated |
||
| 623 | * from the database. It exists to check any foreign keys to make sure that |
||
| 624 | * the objects related to the current object are correct based on foreign key. |
||
| 625 | * |
||
| 626 | * You can override this method in the stub class, but you should always invoke |
||
| 627 | * the base method from the overridden method (i.e. parent::ensureConsistency()), |
||
| 628 | * in case your model changes. |
||
| 629 | * |
||
| 630 | * @throws PropelException |
||
| 631 | */ |
||
| 632 | public function ensureConsistency() |
||
| 641 | |||
| 642 | /** |
||
| 643 | * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. |
||
| 644 | * |
||
| 645 | * This will only work if the object has been saved and has a valid primary key set. |
||
| 646 | * |
||
| 647 | * @param boolean $deep (optional) Whether to also de-associated any related objects. |
||
| 648 | * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. |
||
| 649 | * @return void |
||
| 650 | * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db |
||
| 651 | */ |
||
| 652 | public function reload($deep = false, ConnectionInterface $con = null) |
||
| 683 | |||
| 684 | /** |
||
| 685 | * Removes this object from datastore and sets delete attribute. |
||
| 686 | * |
||
| 687 | * @param ConnectionInterface $con |
||
| 688 | * @return void |
||
| 689 | * @throws PropelException |
||
| 690 | * @see Connection::setDeleted() |
||
| 691 | * @see Connection::isDeleted() |
||
| 692 | */ |
||
| 693 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
| 714 | |||
| 715 | /** |
||
| 716 | * Persists this object to the database. |
||
| 717 | * |
||
| 718 | * If the object is new, it inserts it; otherwise an update is performed. |
||
| 719 | * All modified related objects will also be persisted in the doSave() |
||
| 720 | * method. This method wraps all precipitate database operations in a |
||
| 721 | * single transaction. |
||
| 722 | * |
||
| 723 | * @param ConnectionInterface $con |
||
| 724 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
| 725 | * @throws PropelException |
||
| 726 | * @see doSave() |
||
| 727 | */ |
||
| 728 | View Code Duplication | public function save(ConnectionInterface $con = null) |
|
| 762 | |||
| 763 | /** |
||
| 764 | * Performs the work of inserting or updating the row in the database. |
||
| 765 | * |
||
| 766 | * If the object is new, it inserts it; otherwise an update is performed. |
||
| 767 | * All related objects are also updated in this method. |
||
| 768 | * |
||
| 769 | * @param ConnectionInterface $con |
||
| 770 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
| 771 | * @throws PropelException |
||
| 772 | * @see save() |
||
| 773 | */ |
||
| 774 | protected function doSave(ConnectionInterface $con) |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Insert the row in the database. |
||
| 819 | * |
||
| 820 | * @param ConnectionInterface $con |
||
| 821 | * |
||
| 822 | * @throws PropelException |
||
| 823 | * @see doSave() |
||
| 824 | */ |
||
| 825 | protected function doInsert(ConnectionInterface $con) |
||
| 900 | |||
| 901 | /** |
||
| 902 | * Update the row in the database. |
||
| 903 | * |
||
| 904 | * @param ConnectionInterface $con |
||
| 905 | * |
||
| 906 | * @return Integer Number of updated rows |
||
| 907 | * @see doSave() |
||
| 908 | */ |
||
| 909 | protected function doUpdate(ConnectionInterface $con) |
||
| 916 | |||
| 917 | /** |
||
| 918 | * Retrieves a field from the object by name passed in as a string. |
||
| 919 | * |
||
| 920 | * @param string $name name |
||
| 921 | * @param string $type The type of fieldname the $name is of: |
||
| 922 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 923 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 924 | * Defaults to TableMap::TYPE_PHPNAME. |
||
| 925 | * @return mixed Value of field. |
||
| 926 | */ |
||
| 927 | View Code Duplication | public function getByName($name, $type = TableMap::TYPE_PHPNAME) |
|
| 934 | |||
| 935 | /** |
||
| 936 | * Retrieves a field from the object by Position as specified in the xml schema. |
||
| 937 | * Zero-based. |
||
| 938 | * |
||
| 939 | * @param int $pos position in xml schema |
||
| 940 | * @return mixed Value of field at $pos |
||
| 941 | */ |
||
| 942 | public function getByPosition($pos) |
||
| 968 | |||
| 969 | /** |
||
| 970 | * Exports the object as an array. |
||
| 971 | * |
||
| 972 | * You can specify the key type of the array by passing one of the class |
||
| 973 | * type constants. |
||
| 974 | * |
||
| 975 | * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
| 976 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 977 | * Defaults to TableMap::TYPE_PHPNAME. |
||
| 978 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. |
||
| 979 | * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion |
||
| 980 | * @param boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE. |
||
| 981 | * |
||
| 982 | * @return array an associative array containing the field names (as keys) and field values |
||
| 983 | */ |
||
| 984 | public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false) |
||
| 1044 | |||
| 1045 | /** |
||
| 1046 | * Sets a field from the object by name passed in as a string. |
||
| 1047 | * |
||
| 1048 | * @param string $name |
||
| 1049 | * @param mixed $value field value |
||
| 1050 | * @param string $type The type of fieldname the $name is of: |
||
| 1051 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 1052 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 1053 | * Defaults to TableMap::TYPE_PHPNAME. |
||
| 1054 | * @return $this|\Jalle19\StatusManager\Database\Connection |
||
| 1055 | */ |
||
| 1056 | public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) |
||
| 1062 | |||
| 1063 | /** |
||
| 1064 | * Sets a field from the object by Position as specified in the xml schema. |
||
| 1065 | * Zero-based. |
||
| 1066 | * |
||
| 1067 | * @param int $pos position in xml schema |
||
| 1068 | * @param mixed $value field value |
||
| 1069 | * @return $this|\Jalle19\StatusManager\Database\Connection |
||
| 1070 | */ |
||
| 1071 | public function setByPosition($pos, $value) |
||
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Populates the object using an array. |
||
| 1099 | * |
||
| 1100 | * This is particularly useful when populating an object from one of the |
||
| 1101 | * request arrays (e.g. $_POST). This method goes through the column |
||
| 1102 | * names, checking to see whether a matching key exists in populated |
||
| 1103 | * array. If so the setByName() method is called for that column. |
||
| 1104 | * |
||
| 1105 | * You can specify the key type of the array by additionally passing one |
||
| 1106 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
| 1107 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 1108 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
| 1109 | * |
||
| 1110 | * @param array $arr An array to populate the object from. |
||
| 1111 | * @param string $keyType The type of keys the array uses. |
||
| 1112 | * @return void |
||
| 1113 | */ |
||
| 1114 | public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) |
||
| 1137 | |||
| 1138 | /** |
||
| 1139 | * Populate the current object from a string, using a given parser format |
||
| 1140 | * <code> |
||
| 1141 | * $book = new Book(); |
||
| 1142 | * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
| 1143 | * </code> |
||
| 1144 | * |
||
| 1145 | * You can specify the key type of the array by additionally passing one |
||
| 1146 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
| 1147 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 1148 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
| 1149 | * |
||
| 1150 | * @param mixed $parser A AbstractParser instance, |
||
| 1151 | * or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
| 1152 | * @param string $data The source data to import from |
||
| 1153 | * @param string $keyType The type of keys the array uses. |
||
| 1154 | * |
||
| 1155 | * @return $this|\Jalle19\StatusManager\Database\Connection The current object, for fluid interface |
||
| 1156 | */ |
||
| 1157 | View Code Duplication | public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) |
|
| 1167 | |||
| 1168 | /** |
||
| 1169 | * Build a Criteria object containing the values of all modified columns in this object. |
||
| 1170 | * |
||
| 1171 | * @return Criteria The Criteria object containing all modified values. |
||
| 1172 | */ |
||
| 1173 | public function buildCriteria() |
||
| 1198 | |||
| 1199 | /** |
||
| 1200 | * Builds a Criteria object containing the primary key for this object. |
||
| 1201 | * |
||
| 1202 | * Unlike buildCriteria() this method includes the primary key values regardless |
||
| 1203 | * of whether or not they have been modified. |
||
| 1204 | * |
||
| 1205 | * @throws LogicException if no primary key is defined |
||
| 1206 | * |
||
| 1207 | * @return Criteria The Criteria object containing value(s) for primary key(s). |
||
| 1208 | */ |
||
| 1209 | public function buildPkeyCriteria() |
||
| 1216 | |||
| 1217 | /** |
||
| 1218 | * If the primary key is not null, return the hashcode of the |
||
| 1219 | * primary key. Otherwise, return the hash code of the object. |
||
| 1220 | * |
||
| 1221 | * @return int Hashcode |
||
| 1222 | */ |
||
| 1223 | View Code Duplication | public function hashCode() |
|
| 1238 | |||
| 1239 | /** |
||
| 1240 | * Returns the primary key for this object (row). |
||
| 1241 | * @return int |
||
| 1242 | */ |
||
| 1243 | public function getPrimaryKey() |
||
| 1247 | |||
| 1248 | /** |
||
| 1249 | * Generic method to set the primary key (id column). |
||
| 1250 | * |
||
| 1251 | * @param int $key Primary key. |
||
| 1252 | * @return void |
||
| 1253 | */ |
||
| 1254 | public function setPrimaryKey($key) |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * Returns true if the primary key for this object is null. |
||
| 1261 | * @return boolean |
||
| 1262 | */ |
||
| 1263 | public function isPrimaryKeyNull() |
||
| 1267 | |||
| 1268 | /** |
||
| 1269 | * Sets contents of passed object to values from current object. |
||
| 1270 | * |
||
| 1271 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
| 1272 | * objects. |
||
| 1273 | * |
||
| 1274 | * @param object $copyObj An object of \Jalle19\StatusManager\Database\Connection (or compatible) type. |
||
| 1275 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
| 1276 | * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. |
||
| 1277 | * @throws PropelException |
||
| 1278 | */ |
||
| 1279 | public function copyInto($copyObj, $deepCopy = false, $makeNew = true) |
||
| 1291 | |||
| 1292 | /** |
||
| 1293 | * Makes a copy of this object that will be inserted as a new row in table when saved. |
||
| 1294 | * It creates a new object filling in the simple attributes, but skipping any primary |
||
| 1295 | * keys that are defined for the table. |
||
| 1296 | * |
||
| 1297 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
| 1298 | * objects. |
||
| 1299 | * |
||
| 1300 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
| 1301 | * @return \Jalle19\StatusManager\Database\Connection Clone of current object. |
||
| 1302 | * @throws PropelException |
||
| 1303 | */ |
||
| 1304 | View Code Duplication | public function copy($deepCopy = false) |
|
| 1313 | |||
| 1314 | /** |
||
| 1315 | * Declares an association between this object and a ChildInstance object. |
||
| 1316 | * |
||
| 1317 | * @param ChildInstance $v |
||
| 1318 | * @return $this|\Jalle19\StatusManager\Database\Connection The current object (for fluent API support) |
||
| 1319 | * @throws PropelException |
||
| 1320 | */ |
||
| 1321 | public function setInstance(ChildInstance $v = null) |
||
| 1340 | |||
| 1341 | |||
| 1342 | /** |
||
| 1343 | * Get the associated ChildInstance object |
||
| 1344 | * |
||
| 1345 | * @param ConnectionInterface $con Optional Connection object. |
||
| 1346 | * @return ChildInstance The associated ChildInstance object. |
||
| 1347 | * @throws PropelException |
||
| 1348 | */ |
||
| 1349 | View Code Duplication | public function getInstance(ConnectionInterface $con = null) |
|
| 1364 | |||
| 1365 | /** |
||
| 1366 | * Declares an association between this object and a ChildUser object. |
||
| 1367 | * |
||
| 1368 | * @param ChildUser $v |
||
| 1369 | * @return $this|\Jalle19\StatusManager\Database\Connection The current object (for fluent API support) |
||
| 1370 | * @throws PropelException |
||
| 1371 | */ |
||
| 1372 | public function setUser(ChildUser $v = null) |
||
| 1391 | |||
| 1392 | |||
| 1393 | /** |
||
| 1394 | * Get the associated ChildUser object |
||
| 1395 | * |
||
| 1396 | * @param ConnectionInterface $con Optional Connection object. |
||
| 1397 | * @return ChildUser The associated ChildUser object. |
||
| 1398 | * @throws PropelException |
||
| 1399 | */ |
||
| 1400 | View Code Duplication | public function getUser(ConnectionInterface $con = null) |
|
| 1415 | |||
| 1416 | /** |
||
| 1417 | * Clears the current object, sets all attributes to their default values and removes |
||
| 1418 | * outgoing references as well as back-references (from other objects to this one. Results probably in a database |
||
| 1419 | * change of those foreign objects when you call `save` there). |
||
| 1420 | */ |
||
| 1421 | public function clear() |
||
| 1441 | |||
| 1442 | /** |
||
| 1443 | * Resets all references and back-references to other model objects or collections of model objects. |
||
| 1444 | * |
||
| 1445 | * This method is used to reset all php object references (not the actual reference in the database). |
||
| 1446 | * Necessary for object serialisation. |
||
| 1447 | * |
||
| 1448 | * @param boolean $deep Whether to also clear the references on all referrer objects. |
||
| 1449 | */ |
||
| 1450 | public function clearAllReferences($deep = false) |
||
| 1458 | |||
| 1459 | /** |
||
| 1460 | * Return the string representation of this object |
||
| 1461 | * |
||
| 1462 | * @return string |
||
| 1463 | */ |
||
| 1464 | public function __toString() |
||
| 1468 | |||
| 1469 | /** |
||
| 1470 | * Code to be run before persisting the object |
||
| 1471 | * @param ConnectionInterface $con |
||
| 1472 | * @return boolean |
||
| 1473 | */ |
||
| 1474 | public function preSave(ConnectionInterface $con = null) |
||
| 1478 | |||
| 1479 | /** |
||
| 1480 | * Code to be run after persisting the object |
||
| 1481 | * @param ConnectionInterface $con |
||
| 1482 | */ |
||
| 1483 | public function postSave(ConnectionInterface $con = null) |
||
| 1487 | |||
| 1488 | /** |
||
| 1489 | * Code to be run before inserting to database |
||
| 1490 | * @param ConnectionInterface $con |
||
| 1491 | * @return boolean |
||
| 1492 | */ |
||
| 1493 | public function preInsert(ConnectionInterface $con = null) |
||
| 1497 | |||
| 1498 | /** |
||
| 1499 | * Code to be run after inserting to database |
||
| 1500 | * @param ConnectionInterface $con |
||
| 1501 | */ |
||
| 1502 | public function postInsert(ConnectionInterface $con = null) |
||
| 1506 | |||
| 1507 | /** |
||
| 1508 | * Code to be run before updating the object in database |
||
| 1509 | * @param ConnectionInterface $con |
||
| 1510 | * @return boolean |
||
| 1511 | */ |
||
| 1512 | public function preUpdate(ConnectionInterface $con = null) |
||
| 1516 | |||
| 1517 | /** |
||
| 1518 | * Code to be run after updating the object in database |
||
| 1519 | * @param ConnectionInterface $con |
||
| 1520 | */ |
||
| 1521 | public function postUpdate(ConnectionInterface $con = null) |
||
| 1525 | |||
| 1526 | /** |
||
| 1527 | * Code to be run before deleting the object in database |
||
| 1528 | * @param ConnectionInterface $con |
||
| 1529 | * @return boolean |
||
| 1530 | */ |
||
| 1531 | public function preDelete(ConnectionInterface $con = null) |
||
| 1535 | |||
| 1536 | /** |
||
| 1537 | * Code to be run after deleting the object in database |
||
| 1538 | * @param ConnectionInterface $con |
||
| 1539 | */ |
||
| 1540 | public function postDelete(ConnectionInterface $con = null) |
||
| 1544 | |||
| 1545 | |||
| 1546 | /** |
||
| 1547 | * Derived method to catches calls to undefined methods. |
||
| 1548 | * |
||
| 1549 | * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). |
||
| 1550 | * Allows to define default __call() behavior if you overwrite __call() |
||
| 1551 | * |
||
| 1552 | * @param string $name |
||
| 1553 | * @param mixed $params |
||
| 1554 | * |
||
| 1555 | * @return array|string |
||
| 1556 | */ |
||
| 1557 | View Code Duplication | public function __call($name, $params) |
|
| 1586 | |||
| 1587 | } |
||
| 1588 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.