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