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 User 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 User, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 40 | abstract class User implements ActiveRecordInterface |
||
| 41 | { |
||
| 42 | /** |
||
| 43 | * TableMap class name |
||
| 44 | */ |
||
| 45 | const TABLE_MAP = '\\Core\\Models\\User\\Map\\UserTableMap'; |
||
| 46 | |||
| 47 | |||
| 48 | /** |
||
| 49 | * attribute to determine if this object has previously been saved. |
||
| 50 | * @var boolean |
||
| 51 | */ |
||
| 52 | protected $new = true; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * attribute to determine whether this object has been deleted. |
||
| 56 | * @var boolean |
||
| 57 | */ |
||
| 58 | protected $deleted = false; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * The columns that have been modified in current object. |
||
| 62 | * Tracking modified columns allows us to only update modified columns. |
||
| 63 | * @var array |
||
| 64 | */ |
||
| 65 | protected $modifiedColumns = array(); |
||
| 66 | |||
| 67 | /** |
||
| 68 | * The (virtual) columns that are added at runtime |
||
| 69 | * The formatters can add supplementary columns based on a resultset |
||
| 70 | * @var array |
||
| 71 | */ |
||
| 72 | protected $virtualColumns = array(); |
||
| 73 | |||
| 74 | /** |
||
| 75 | * The value for the id field. |
||
| 76 | * @var int |
||
| 77 | */ |
||
| 78 | protected $id; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * The value for the name field. |
||
| 82 | * @var string |
||
| 83 | */ |
||
| 84 | protected $name; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * The value for the email field. |
||
| 88 | * @var string |
||
| 89 | */ |
||
| 90 | protected $email; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * The value for the password field. |
||
| 94 | * @var string |
||
| 95 | */ |
||
| 96 | protected $password; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * The value for the remember_token field. |
||
| 100 | * @var string |
||
| 101 | */ |
||
| 102 | protected $remember_token; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * The value for the created_at field. |
||
| 106 | * @var \DateTime |
||
| 107 | */ |
||
| 108 | protected $created_at; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * The value for the updated_at field. |
||
| 112 | * @var \DateTime |
||
| 113 | */ |
||
| 114 | protected $updated_at; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Flag to prevent endless save loop, if this object is referenced |
||
| 118 | * by another object which falls in this transaction. |
||
| 119 | * |
||
| 120 | * @var boolean |
||
| 121 | */ |
||
| 122 | protected $alreadyInSave = false; |
||
| 123 | |||
| 124 | // validate behavior |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Flag to prevent endless validation loop, if this object is referenced |
||
| 128 | * by another object which falls in this transaction. |
||
| 129 | * @var boolean |
||
| 130 | */ |
||
| 131 | protected $alreadyInValidation = false; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * ConstraintViolationList object |
||
| 135 | * |
||
| 136 | * @see http://api.symfony.com/2.0/Symfony/Component/Validator/ConstraintViolationList.html |
||
| 137 | * @var ConstraintViolationList |
||
| 138 | */ |
||
| 139 | protected $validationFailures; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Initializes internal state of Core\Models\User\Base\User object. |
||
| 143 | */ |
||
| 144 | public function __construct() |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Returns whether the object has been modified. |
||
| 150 | * |
||
| 151 | * @return boolean True if the object has been modified. |
||
| 152 | */ |
||
| 153 | public function isModified() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Has specified column been modified? |
||
| 160 | * |
||
| 161 | * @param string $col column fully qualified name (TableMap::TYPE_COLNAME), e.g. Book::AUTHOR_ID |
||
| 162 | * @return boolean True if $col has been modified. |
||
| 163 | */ |
||
| 164 | public function isColumnModified($col) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Get the columns that have been modified in this object. |
||
| 171 | * @return array A unique list of the modified column names for this object. |
||
| 172 | */ |
||
| 173 | public function getModifiedColumns() |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Returns whether the object has ever been saved. This will |
||
| 180 | * be false, if the object was retrieved from storage or was created |
||
| 181 | * and then saved. |
||
| 182 | * |
||
| 183 | * @return boolean true, if the object has never been persisted. |
||
| 184 | */ |
||
| 185 | public function isNew() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Setter for the isNew attribute. This method will be called |
||
| 192 | * by Propel-generated children and objects. |
||
| 193 | * |
||
| 194 | * @param boolean $b the state of the object. |
||
| 195 | */ |
||
| 196 | public function setNew($b) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Whether this object has been deleted. |
||
| 203 | * @return boolean The deleted state of this object. |
||
| 204 | */ |
||
| 205 | public function isDeleted() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Specify whether this object has been deleted. |
||
| 212 | * @param boolean $b The deleted state of this object. |
||
| 213 | * @return void |
||
| 214 | */ |
||
| 215 | public function setDeleted($b) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Sets the modified state for the object to be false. |
||
| 222 | * @param string $col If supplied, only the specified column is reset. |
||
| 223 | * @return void |
||
| 224 | */ |
||
| 225 | View Code Duplication | public function resetModified($col = null) |
|
| 235 | |||
| 236 | /** |
||
| 237 | * Compares this with another <code>User</code> instance. If |
||
| 238 | * <code>obj</code> is an instance of <code>User</code>, delegates to |
||
| 239 | * <code>equals(User)</code>. Otherwise, returns <code>false</code>. |
||
| 240 | * |
||
| 241 | * @param mixed $obj The object to compare to. |
||
| 242 | * @return boolean Whether equal to the object specified. |
||
| 243 | */ |
||
| 244 | View Code Duplication | public function equals($obj) |
|
| 260 | |||
| 261 | /** |
||
| 262 | * Get the associative array of the virtual columns in this object |
||
| 263 | * |
||
| 264 | * @return array |
||
| 265 | */ |
||
| 266 | public function getVirtualColumns() |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Checks the existence of a virtual column in this object |
||
| 273 | * |
||
| 274 | * @param string $name The virtual column name |
||
| 275 | * @return boolean |
||
| 276 | */ |
||
| 277 | public function hasVirtualColumn($name) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Get the value of a virtual column in this object |
||
| 284 | * |
||
| 285 | * @param string $name The virtual column name |
||
| 286 | * @return mixed |
||
| 287 | * |
||
| 288 | * @throws PropelException |
||
| 289 | */ |
||
| 290 | View Code Duplication | public function getVirtualColumn($name) |
|
| 298 | |||
| 299 | /** |
||
| 300 | * Set the value of a virtual column in this object |
||
| 301 | * |
||
| 302 | * @param string $name The virtual column name |
||
| 303 | * @param mixed $value The value to give to the virtual column |
||
| 304 | * |
||
| 305 | * @return $this|User The current object, for fluid interface |
||
| 306 | */ |
||
| 307 | public function setVirtualColumn($name, $value) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Logs a message using Propel::log(). |
||
| 316 | * |
||
| 317 | * @param string $msg |
||
| 318 | * @param int $priority One of the Propel::LOG_* logging levels |
||
| 319 | * @return boolean |
||
| 320 | */ |
||
| 321 | protected function log($msg, $priority = Propel::LOG_INFO) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Export the current object properties to a string, using a given parser format |
||
| 328 | * <code> |
||
| 329 | * $book = BookQuery::create()->findPk(9012); |
||
| 330 | * echo $book->exportTo('JSON'); |
||
| 331 | * => {"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
| 332 | * </code> |
||
| 333 | * |
||
| 334 | * @param mixed $parser A AbstractParser instance, or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
| 335 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy load(ed) columns. Defaults to TRUE. |
||
| 336 | * @return string The exported data |
||
| 337 | */ |
||
| 338 | View Code Duplication | public function exportTo($parser, $includeLazyLoadColumns = true) |
|
| 346 | |||
| 347 | /** |
||
| 348 | * Clean up internal collections prior to serializing |
||
| 349 | * Avoids recursive loops that turn into segmentation faults when serializing |
||
| 350 | */ |
||
| 351 | public function __sleep() |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Get the [id] column value. |
||
| 360 | * |
||
| 361 | * @return int |
||
| 362 | */ |
||
| 363 | public function getId() |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Get the [name] column value. |
||
| 370 | * |
||
| 371 | * @return string |
||
| 372 | */ |
||
| 373 | public function getName() |
||
| 377 | |||
| 378 | /** |
||
| 379 | * Get the [email] column value. |
||
| 380 | * |
||
| 381 | * @return string |
||
| 382 | */ |
||
| 383 | public function getEmail() |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Get the [password] column value. |
||
| 390 | * |
||
| 391 | * @return string |
||
| 392 | */ |
||
| 393 | public function getPassword() |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Get the [remember_token] column value. |
||
| 400 | * |
||
| 401 | * @return string |
||
| 402 | */ |
||
| 403 | public function getRememberToken() |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Get the [optionally formatted] temporal [created_at] column value. |
||
| 410 | * |
||
| 411 | * |
||
| 412 | * @param string $format The date/time format string (either date()-style or strftime()-style). |
||
| 413 | * If format is NULL, then the raw DateTime object will be returned. |
||
| 414 | * |
||
| 415 | * @return string|DateTime Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 |
||
| 416 | * |
||
| 417 | * @throws PropelException - if unable to parse/validate the date/time value. |
||
| 418 | */ |
||
| 419 | View Code Duplication | public function getCreatedAt($format = NULL) |
|
| 427 | |||
| 428 | /** |
||
| 429 | * Get the [optionally formatted] temporal [updated_at] column value. |
||
| 430 | * |
||
| 431 | * |
||
| 432 | * @param string $format The date/time format string (either date()-style or strftime()-style). |
||
| 433 | * If format is NULL, then the raw DateTime object will be returned. |
||
| 434 | * |
||
| 435 | * @return string|DateTime Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL, and 0 if column value is 0000-00-00 00:00:00 |
||
| 436 | * |
||
| 437 | * @throws PropelException - if unable to parse/validate the date/time value. |
||
| 438 | */ |
||
| 439 | View Code Duplication | public function getUpdatedAt($format = NULL) |
|
| 447 | |||
| 448 | /** |
||
| 449 | * Set the value of [id] column. |
||
| 450 | * |
||
| 451 | * @param int $v new value |
||
| 452 | * @return $this|\Core\Models\User\User The current object (for fluent API support) |
||
| 453 | */ |
||
| 454 | View Code Duplication | public function setId($v) |
|
| 467 | |||
| 468 | /** |
||
| 469 | * Set the value of [name] column. |
||
| 470 | * |
||
| 471 | * @param string $v new value |
||
| 472 | * @return $this|\Core\Models\User\User The current object (for fluent API support) |
||
| 473 | */ |
||
| 474 | View Code Duplication | public function setName($v) |
|
| 487 | |||
| 488 | /** |
||
| 489 | * Set the value of [email] column. |
||
| 490 | * |
||
| 491 | * @param string $v new value |
||
| 492 | * @return $this|\Core\Models\User\User The current object (for fluent API support) |
||
| 493 | */ |
||
| 494 | View Code Duplication | public function setEmail($v) |
|
| 507 | |||
| 508 | /** |
||
| 509 | * Set the value of [password] column. |
||
| 510 | * |
||
| 511 | * @param string $v new value |
||
| 512 | * @return $this|\Core\Models\User\User The current object (for fluent API support) |
||
| 513 | */ |
||
| 514 | View Code Duplication | public function setPassword($v) |
|
| 527 | |||
| 528 | /** |
||
| 529 | * Set the value of [remember_token] column. |
||
| 530 | * |
||
| 531 | * @param string $v new value |
||
| 532 | * @return $this|\Core\Models\User\User The current object (for fluent API support) |
||
| 533 | */ |
||
| 534 | View Code Duplication | public function setRememberToken($v) |
|
| 547 | |||
| 548 | /** |
||
| 549 | * Sets the value of [created_at] column to a normalized version of the date/time value specified. |
||
| 550 | * |
||
| 551 | * @param mixed $v string, integer (timestamp), or \DateTime value. |
||
| 552 | * Empty strings are treated as NULL. |
||
| 553 | * @return $this|\Core\Models\User\User The current object (for fluent API support) |
||
| 554 | */ |
||
| 555 | View Code Duplication | public function setCreatedAt($v) |
|
| 567 | |||
| 568 | /** |
||
| 569 | * Sets the value of [updated_at] column to a normalized version of the date/time value specified. |
||
| 570 | * |
||
| 571 | * @param mixed $v string, integer (timestamp), or \DateTime value. |
||
| 572 | * Empty strings are treated as NULL. |
||
| 573 | * @return $this|\Core\Models\User\User The current object (for fluent API support) |
||
| 574 | */ |
||
| 575 | View Code Duplication | public function setUpdatedAt($v) |
|
| 587 | |||
| 588 | /** |
||
| 589 | * Indicates whether the columns in this object are only set to default values. |
||
| 590 | * |
||
| 591 | * This method can be used in conjunction with isModified() to indicate whether an object is both |
||
| 592 | * modified _and_ has some values set which are non-default. |
||
| 593 | * |
||
| 594 | * @return boolean Whether the columns in this object are only been set with default values. |
||
| 595 | */ |
||
| 596 | public function hasOnlyDefaultValues() |
||
| 601 | |||
| 602 | /** |
||
| 603 | * Hydrates (populates) the object variables with values from the database resultset. |
||
| 604 | * |
||
| 605 | * An offset (0-based "start column") is specified so that objects can be hydrated |
||
| 606 | * with a subset of the columns in the resultset rows. This is needed, for example, |
||
| 607 | * for results of JOIN queries where the resultset row includes columns from two or |
||
| 608 | * more tables. |
||
| 609 | * |
||
| 610 | * @param array $row The row returned by DataFetcher->fetch(). |
||
| 611 | * @param int $startcol 0-based offset column which indicates which restultset column to start with. |
||
| 612 | * @param boolean $rehydrate Whether this object is being re-hydrated from the database. |
||
| 613 | * @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). |
||
| 614 | One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 615 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 616 | * |
||
| 617 | * @return int next starting column |
||
| 618 | * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. |
||
| 619 | */ |
||
| 620 | public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) |
||
| 664 | |||
| 665 | /** |
||
| 666 | * Checks and repairs the internal consistency of the object. |
||
| 667 | * |
||
| 668 | * This method is executed after an already-instantiated object is re-hydrated |
||
| 669 | * from the database. It exists to check any foreign keys to make sure that |
||
| 670 | * the objects related to the current object are correct based on foreign key. |
||
| 671 | * |
||
| 672 | * You can override this method in the stub class, but you should always invoke |
||
| 673 | * the base method from the overridden method (i.e. parent::ensureConsistency()), |
||
| 674 | * in case your model changes. |
||
| 675 | * |
||
| 676 | * @throws PropelException |
||
| 677 | */ |
||
| 678 | public function ensureConsistency() |
||
| 681 | |||
| 682 | /** |
||
| 683 | * Reloads this object from datastore based on primary key and (optionally) resets all associated objects. |
||
| 684 | * |
||
| 685 | * This will only work if the object has been saved and has a valid primary key set. |
||
| 686 | * |
||
| 687 | * @param boolean $deep (optional) Whether to also de-associated any related objects. |
||
| 688 | * @param ConnectionInterface $con (optional) The ConnectionInterface connection to use. |
||
| 689 | * @return void |
||
| 690 | * @throws PropelException - if this object is deleted, unsaved or doesn't have pk match in db |
||
| 691 | */ |
||
| 692 | View Code Duplication | public function reload($deep = false, ConnectionInterface $con = null) |
|
| 721 | |||
| 722 | /** |
||
| 723 | * Removes this object from datastore and sets delete attribute. |
||
| 724 | * |
||
| 725 | * @param ConnectionInterface $con |
||
| 726 | * @return void |
||
| 727 | * @throws PropelException |
||
| 728 | * @see User::setDeleted() |
||
| 729 | * @see User::isDeleted() |
||
| 730 | */ |
||
| 731 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
| 752 | |||
| 753 | /** |
||
| 754 | * Persists this object to the database. |
||
| 755 | * |
||
| 756 | * If the object is new, it inserts it; otherwise an update is performed. |
||
| 757 | * All modified related objects will also be persisted in the doSave() |
||
| 758 | * method. This method wraps all precipitate database operations in a |
||
| 759 | * single transaction. |
||
| 760 | * |
||
| 761 | * @param ConnectionInterface $con |
||
| 762 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
| 763 | * @throws PropelException |
||
| 764 | * @see doSave() |
||
| 765 | */ |
||
| 766 | View Code Duplication | public function save(ConnectionInterface $con = null) |
|
| 800 | |||
| 801 | /** |
||
| 802 | * Performs the work of inserting or updating the row in the database. |
||
| 803 | * |
||
| 804 | * If the object is new, it inserts it; otherwise an update is performed. |
||
| 805 | * All related objects are also updated in this method. |
||
| 806 | * |
||
| 807 | * @param ConnectionInterface $con |
||
| 808 | * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. |
||
| 809 | * @throws PropelException |
||
| 810 | * @see save() |
||
| 811 | */ |
||
| 812 | View Code Duplication | protected function doSave(ConnectionInterface $con) |
|
| 835 | |||
| 836 | /** |
||
| 837 | * Insert the row in the database. |
||
| 838 | * |
||
| 839 | * @param ConnectionInterface $con |
||
| 840 | * |
||
| 841 | * @throws PropelException |
||
| 842 | * @see doSave() |
||
| 843 | */ |
||
| 844 | protected function doInsert(ConnectionInterface $con) |
||
| 925 | |||
| 926 | /** |
||
| 927 | * Update the row in the database. |
||
| 928 | * |
||
| 929 | * @param ConnectionInterface $con |
||
| 930 | * |
||
| 931 | * @return Integer Number of updated rows |
||
| 932 | * @see doSave() |
||
| 933 | */ |
||
| 934 | protected function doUpdate(ConnectionInterface $con) |
||
| 941 | |||
| 942 | /** |
||
| 943 | * Retrieves a field from the object by name passed in as a string. |
||
| 944 | * |
||
| 945 | * @param string $name name |
||
| 946 | * @param string $type The type of fieldname the $name is of: |
||
| 947 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 948 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 949 | * Defaults to TableMap::TYPE_PHPNAME. |
||
| 950 | * @return mixed Value of field. |
||
| 951 | */ |
||
| 952 | View Code Duplication | public function getByName($name, $type = TableMap::TYPE_PHPNAME) |
|
| 959 | |||
| 960 | /** |
||
| 961 | * Retrieves a field from the object by Position as specified in the xml schema. |
||
| 962 | * Zero-based. |
||
| 963 | * |
||
| 964 | * @param int $pos position in xml schema |
||
| 965 | * @return mixed Value of field at $pos |
||
| 966 | */ |
||
| 967 | public function getByPosition($pos) |
||
| 996 | |||
| 997 | /** |
||
| 998 | * Exports the object as an array. |
||
| 999 | * |
||
| 1000 | * You can specify the key type of the array by passing one of the class |
||
| 1001 | * type constants. |
||
| 1002 | * |
||
| 1003 | * @param string $keyType (optional) One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
| 1004 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 1005 | * Defaults to TableMap::TYPE_PHPNAME. |
||
| 1006 | * @param boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE. |
||
| 1007 | * @param array $alreadyDumpedObjects List of objects to skip to avoid recursion |
||
| 1008 | * |
||
| 1009 | * @return array an associative array containing the field names (as keys) and field values |
||
| 1010 | */ |
||
| 1011 | public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array()) |
||
| 1050 | |||
| 1051 | /** |
||
| 1052 | * Sets a field from the object by name passed in as a string. |
||
| 1053 | * |
||
| 1054 | * @param string $name |
||
| 1055 | * @param mixed $value field value |
||
| 1056 | * @param string $type The type of fieldname the $name is of: |
||
| 1057 | * one of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME |
||
| 1058 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 1059 | * Defaults to TableMap::TYPE_PHPNAME. |
||
| 1060 | * @return $this|\Core\Models\User\User |
||
| 1061 | */ |
||
| 1062 | public function setByName($name, $value, $type = TableMap::TYPE_PHPNAME) |
||
| 1068 | |||
| 1069 | /** |
||
| 1070 | * Sets a field from the object by Position as specified in the xml schema. |
||
| 1071 | * Zero-based. |
||
| 1072 | * |
||
| 1073 | * @param int $pos position in xml schema |
||
| 1074 | * @param mixed $value field value |
||
| 1075 | * @return $this|\Core\Models\User\User |
||
| 1076 | */ |
||
| 1077 | public function setByPosition($pos, $value) |
||
| 1105 | |||
| 1106 | /** |
||
| 1107 | * Populates the object using an array. |
||
| 1108 | * |
||
| 1109 | * This is particularly useful when populating an object from one of the |
||
| 1110 | * request arrays (e.g. $_POST). This method goes through the column |
||
| 1111 | * names, checking to see whether a matching key exists in populated |
||
| 1112 | * array. If so the setByName() method is called for that column. |
||
| 1113 | * |
||
| 1114 | * You can specify the key type of the array by additionally passing one |
||
| 1115 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
| 1116 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 1117 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
| 1118 | * |
||
| 1119 | * @param array $arr An array to populate the object from. |
||
| 1120 | * @param string $keyType The type of keys the array uses. |
||
| 1121 | * @return void |
||
| 1122 | */ |
||
| 1123 | public function fromArray($arr, $keyType = TableMap::TYPE_PHPNAME) |
||
| 1149 | |||
| 1150 | /** |
||
| 1151 | * Populate the current object from a string, using a given parser format |
||
| 1152 | * <code> |
||
| 1153 | * $book = new Book(); |
||
| 1154 | * $book->importFrom('JSON', '{"Id":9012,"Title":"Don Juan","ISBN":"0140422161","Price":12.99,"PublisherId":1234,"AuthorId":5678}'); |
||
| 1155 | * </code> |
||
| 1156 | * |
||
| 1157 | * You can specify the key type of the array by additionally passing one |
||
| 1158 | * of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, |
||
| 1159 | * TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. |
||
| 1160 | * The default key type is the column's TableMap::TYPE_PHPNAME. |
||
| 1161 | * |
||
| 1162 | * @param mixed $parser A AbstractParser instance, |
||
| 1163 | * or a format name ('XML', 'YAML', 'JSON', 'CSV') |
||
| 1164 | * @param string $data The source data to import from |
||
| 1165 | * @param string $keyType The type of keys the array uses. |
||
| 1166 | * |
||
| 1167 | * @return $this|\Core\Models\User\User The current object, for fluid interface |
||
| 1168 | */ |
||
| 1169 | View Code Duplication | public function importFrom($parser, $data, $keyType = TableMap::TYPE_PHPNAME) |
|
| 1179 | |||
| 1180 | /** |
||
| 1181 | * Build a Criteria object containing the values of all modified columns in this object. |
||
| 1182 | * |
||
| 1183 | * @return Criteria The Criteria object containing all modified values. |
||
| 1184 | */ |
||
| 1185 | public function buildCriteria() |
||
| 1213 | |||
| 1214 | /** |
||
| 1215 | * Builds a Criteria object containing the primary key for this object. |
||
| 1216 | * |
||
| 1217 | * Unlike buildCriteria() this method includes the primary key values regardless |
||
| 1218 | * of whether or not they have been modified. |
||
| 1219 | * |
||
| 1220 | * @throws LogicException if no primary key is defined |
||
| 1221 | * |
||
| 1222 | * @return Criteria The Criteria object containing value(s) for primary key(s). |
||
| 1223 | */ |
||
| 1224 | public function buildPkeyCriteria() |
||
| 1231 | |||
| 1232 | /** |
||
| 1233 | * If the primary key is not null, return the hashcode of the |
||
| 1234 | * primary key. Otherwise, return the hash code of the object. |
||
| 1235 | * |
||
| 1236 | * @return int Hashcode |
||
| 1237 | */ |
||
| 1238 | View Code Duplication | public function hashCode() |
|
| 1253 | |||
| 1254 | /** |
||
| 1255 | * Returns the primary key for this object (row). |
||
| 1256 | * @return int |
||
| 1257 | */ |
||
| 1258 | public function getPrimaryKey() |
||
| 1262 | |||
| 1263 | /** |
||
| 1264 | * Generic method to set the primary key (id column). |
||
| 1265 | * |
||
| 1266 | * @param int $key Primary key. |
||
| 1267 | * @return void |
||
| 1268 | */ |
||
| 1269 | public function setPrimaryKey($key) |
||
| 1273 | |||
| 1274 | /** |
||
| 1275 | * Returns true if the primary key for this object is null. |
||
| 1276 | * @return boolean |
||
| 1277 | */ |
||
| 1278 | public function isPrimaryKeyNull() |
||
| 1282 | |||
| 1283 | /** |
||
| 1284 | * Sets contents of passed object to values from current object. |
||
| 1285 | * |
||
| 1286 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
| 1287 | * objects. |
||
| 1288 | * |
||
| 1289 | * @param object $copyObj An object of \Core\Models\User\User (or compatible) type. |
||
| 1290 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
| 1291 | * @param boolean $makeNew Whether to reset autoincrement PKs and make the object new. |
||
| 1292 | * @throws PropelException |
||
| 1293 | */ |
||
| 1294 | public function copyInto($copyObj, $deepCopy = false, $makeNew = true) |
||
| 1307 | |||
| 1308 | /** |
||
| 1309 | * Makes a copy of this object that will be inserted as a new row in table when saved. |
||
| 1310 | * It creates a new object filling in the simple attributes, but skipping any primary |
||
| 1311 | * keys that are defined for the table. |
||
| 1312 | * |
||
| 1313 | * If desired, this method can also make copies of all associated (fkey referrers) |
||
| 1314 | * objects. |
||
| 1315 | * |
||
| 1316 | * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. |
||
| 1317 | * @return \Core\Models\User\User Clone of current object. |
||
| 1318 | * @throws PropelException |
||
| 1319 | */ |
||
| 1320 | View Code Duplication | public function copy($deepCopy = false) |
|
| 1329 | |||
| 1330 | /** |
||
| 1331 | * Clears the current object, sets all attributes to their default values and removes |
||
| 1332 | * outgoing references as well as back-references (from other objects to this one. Results probably in a database |
||
| 1333 | * change of those foreign objects when you call `save` there). |
||
| 1334 | */ |
||
| 1335 | public function clear() |
||
| 1350 | |||
| 1351 | /** |
||
| 1352 | * Resets all references and back-references to other model objects or collections of model objects. |
||
| 1353 | * |
||
| 1354 | * This method is used to reset all php object references (not the actual reference in the database). |
||
| 1355 | * Necessary for object serialisation. |
||
| 1356 | * |
||
| 1357 | * @param boolean $deep Whether to also clear the references on all referrer objects. |
||
| 1358 | */ |
||
| 1359 | public function clearAllReferences($deep = false) |
||
| 1365 | |||
| 1366 | /** |
||
| 1367 | * Return the string representation of this object |
||
| 1368 | * |
||
| 1369 | * @return string |
||
| 1370 | */ |
||
| 1371 | public function __toString() |
||
| 1375 | |||
| 1376 | // validate behavior |
||
| 1377 | |||
| 1378 | /** |
||
| 1379 | * Configure validators constraints. The Validator object uses this method |
||
| 1380 | * to perform object validation. |
||
| 1381 | * |
||
| 1382 | * @param ClassMetadata $metadata |
||
| 1383 | */ |
||
| 1384 | static public function loadValidatorMetadata(ClassMetadata $metadata) |
||
| 1388 | |||
| 1389 | /** |
||
| 1390 | * Validates the object and all objects related to this table. |
||
| 1391 | * |
||
| 1392 | * @see getValidationFailures() |
||
| 1393 | * @param object $validator A Validator class instance |
||
| 1394 | * @return boolean Whether all objects pass validation. |
||
| 1395 | */ |
||
| 1396 | public function validate(ValidatorInterface $validator = null) |
||
| 1435 | |||
| 1436 | /** |
||
| 1437 | * Gets any ConstraintViolation objects that resulted from last call to validate(). |
||
| 1438 | * |
||
| 1439 | * |
||
| 1440 | * @return object ConstraintViolationList |
||
| 1441 | * @see validate() |
||
| 1442 | */ |
||
| 1443 | public function getValidationFailures() |
||
| 1447 | |||
| 1448 | /** |
||
| 1449 | * Code to be run before persisting the object |
||
| 1450 | * @param ConnectionInterface $con |
||
| 1451 | * @return boolean |
||
| 1452 | */ |
||
| 1453 | public function preSave(ConnectionInterface $con = null) |
||
| 1457 | |||
| 1458 | /** |
||
| 1459 | * Code to be run after persisting the object |
||
| 1460 | * @param ConnectionInterface $con |
||
| 1461 | */ |
||
| 1462 | public function postSave(ConnectionInterface $con = null) |
||
| 1466 | |||
| 1467 | /** |
||
| 1468 | * Code to be run before inserting to database |
||
| 1469 | * @param ConnectionInterface $con |
||
| 1470 | * @return boolean |
||
| 1471 | */ |
||
| 1472 | public function preInsert(ConnectionInterface $con = null) |
||
| 1476 | |||
| 1477 | /** |
||
| 1478 | * Code to be run after inserting to database |
||
| 1479 | * @param ConnectionInterface $con |
||
| 1480 | */ |
||
| 1481 | public function postInsert(ConnectionInterface $con = null) |
||
| 1485 | |||
| 1486 | /** |
||
| 1487 | * Code to be run before updating the object in database |
||
| 1488 | * @param ConnectionInterface $con |
||
| 1489 | * @return boolean |
||
| 1490 | */ |
||
| 1491 | public function preUpdate(ConnectionInterface $con = null) |
||
| 1495 | |||
| 1496 | /** |
||
| 1497 | * Code to be run after updating the object in database |
||
| 1498 | * @param ConnectionInterface $con |
||
| 1499 | */ |
||
| 1500 | public function postUpdate(ConnectionInterface $con = null) |
||
| 1504 | |||
| 1505 | /** |
||
| 1506 | * Code to be run before deleting the object in database |
||
| 1507 | * @param ConnectionInterface $con |
||
| 1508 | * @return boolean |
||
| 1509 | */ |
||
| 1510 | public function preDelete(ConnectionInterface $con = null) |
||
| 1514 | |||
| 1515 | /** |
||
| 1516 | * Code to be run after deleting the object in database |
||
| 1517 | * @param ConnectionInterface $con |
||
| 1518 | */ |
||
| 1519 | public function postDelete(ConnectionInterface $con = null) |
||
| 1523 | |||
| 1524 | |||
| 1525 | /** |
||
| 1526 | * Derived method to catches calls to undefined methods. |
||
| 1527 | * |
||
| 1528 | * Provides magic import/export method support (fromXML()/toXML(), fromYAML()/toYAML(), etc.). |
||
| 1529 | * Allows to define default __call() behavior if you overwrite __call() |
||
| 1530 | * |
||
| 1531 | * @param string $name |
||
| 1532 | * @param mixed $params |
||
| 1533 | * |
||
| 1534 | * @return array|string |
||
| 1535 | */ |
||
| 1536 | View Code Duplication | public function __call($name, $params) |
|
| 1565 | |||
| 1566 | } |
||
| 1567 |
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.