Complex classes like TActiveRecord 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 TActiveRecord, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 147 | abstract class TActiveRecord extends TComponent |
||
| 148 | { |
||
| 149 | const BELONGS_TO='BELONGS_TO'; |
||
| 150 | const HAS_ONE='HAS_ONE'; |
||
| 151 | const HAS_MANY='HAS_MANY'; |
||
| 152 | const MANY_TO_MANY='MANY_TO_MANY'; |
||
| 153 | |||
| 154 | const STATE_NEW=0; |
||
| 155 | const STATE_LOADED=1; |
||
| 156 | const STATE_DELETED=2; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @var integer record state: 0 = new, 1 = loaded, 2 = deleted. |
||
| 160 | * @since 3.1.2 |
||
| 161 | */ |
||
| 162 | protected $_recordState=0; // use protected so that serialization is fine |
||
| 163 | |||
| 164 | /** |
||
| 165 | * This static variable defines the column mapping. |
||
| 166 | * The keys are physical column names as defined in database, |
||
| 167 | * and the values are logical column names as defined as public variable/property names |
||
| 168 | * for the corresponding active record class. |
||
| 169 | * @var array column mapping. Keys: physical column names, values: logical column names. |
||
| 170 | * @since 3.1.1 |
||
| 171 | */ |
||
| 172 | public static $COLUMN_MAPPING=array(); |
||
| 173 | private static $_columnMapping=array(); |
||
| 174 | |||
| 175 | /** |
||
| 176 | * This static variable defines the relationships. |
||
| 177 | * The keys are public variable/property names defined in the AR class. |
||
| 178 | * Each value is an array, e.g. array(self::HAS_MANY, 'PlayerRecord'). |
||
| 179 | * @var array relationship. |
||
| 180 | * @since 3.1.1 |
||
| 181 | */ |
||
| 182 | public static $RELATIONS=array(); |
||
| 183 | private static $_relations=array(); |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @var TDbConnection database connection object. |
||
| 187 | */ |
||
| 188 | protected $_connection; // use protected so that serialization is fine |
||
| 189 | |||
| 190 | |||
| 191 | /** |
||
| 192 | * Defaults to 'null' |
||
| 193 | * |
||
| 194 | * @var TActiveRecordInvalidFinderResult |
||
| 195 | * @since 3.1.5 |
||
| 196 | */ |
||
| 197 | protected $_invalidFinderResult = null; // use protected so that serialization is fine |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Prevent __call() method creating __sleep() when serializing. |
||
| 201 | */ |
||
| 202 | public function __sleep() |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Prevent __call() method creating __wakeup() when unserializing. |
||
| 209 | */ |
||
| 210 | public function __wakeup() |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Create a new instance of an active record with given $data. The record |
||
| 218 | * can be saved to the database specified by the $connection object. |
||
| 219 | * |
||
| 220 | * @param array optional name value pair record data. |
||
| 221 | * @param TDbConnection optional database connection this object record use. |
||
| 222 | */ |
||
| 223 | public function __construct($data=array(), $connection=null) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Magic method for reading properties. |
||
| 235 | * This method is overriden to provide read access to the foreign objects via |
||
| 236 | * the key names declared in the RELATIONS array. |
||
| 237 | * @param string property name |
||
| 238 | * @return mixed property value. |
||
| 239 | * @since 3.1.2 |
||
| 240 | */ |
||
| 241 | public function __get($name) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Magic method for writing properties. |
||
| 253 | * This method is overriden to provide write access to the foreign objects via |
||
| 254 | * the key names declared in the RELATIONS array. |
||
| 255 | * @param string property name |
||
| 256 | * @param mixed property value. |
||
| 257 | * @since 3.1.2 |
||
| 258 | */ |
||
| 259 | public function __set($name,$value) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @since 3.1.1 |
||
| 269 | */ |
||
| 270 | private function setupColumnMapping() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @since 3.1.2 |
||
| 282 | */ |
||
| 283 | private function setupRelations() |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Copies data from an array or another object. |
||
| 298 | * @throws TActiveRecordException if data is not array or not object. |
||
| 299 | */ |
||
| 300 | public function copyFrom($data) |
||
| 309 | |||
| 310 | |||
| 311 | public static function getActiveDbConnection() |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Gets the current Db connection, the connection object is obtained from |
||
| 320 | * the TActiveRecordManager if connection is currently null. |
||
| 321 | * @return TDbConnection current db connection for this object. |
||
| 322 | */ |
||
| 323 | public function getDbConnection() |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @param TDbConnection db connection object for this record. |
||
| 332 | */ |
||
| 333 | public function setDbConnection($connection) |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @return TDbTableInfo the meta information of the table associated with this AR class. |
||
| 340 | */ |
||
| 341 | public function getRecordTableInfo() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Compare two records using their primary key values (all column values if |
||
| 348 | * table does not defined primary keys). The default uses simple == for |
||
| 349 | * comparison of their values. Set $strict=true for identity comparison (===). |
||
| 350 | * @param TActiveRecord another record to compare with. |
||
| 351 | * @param boolean true to perform strict identity comparison |
||
| 352 | * @return boolean true if $record equals, false otherwise. |
||
| 353 | */ |
||
| 354 | public function equals(TActiveRecord $record, $strict=false) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Returns the instance of a active record finder for a particular class. |
||
| 376 | * The finder objects are static instances for each ActiveRecord class. |
||
| 377 | * This means that event handlers bound to these finder instances are class wide. |
||
| 378 | * Create a new instance of the ActiveRecord class if you wish to bound the |
||
| 379 | * event handlers to object instance. |
||
| 380 | * @param string active record class name. |
||
| 381 | * @return TActiveRecord active record finder instance. |
||
| 382 | */ |
||
| 383 | public static function finder($className=__CLASS__) |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Gets the record manager for this object, the default is to call |
||
| 396 | * TActiveRecordManager::getInstance(). |
||
| 397 | * @return TActiveRecordManager default active record manager. |
||
| 398 | */ |
||
| 399 | public static function getRecordManager() |
||
| 403 | |||
| 404 | /** |
||
| 405 | * @return TActiveRecordGateway record table gateway. |
||
| 406 | */ |
||
| 407 | public function getRecordGateway() |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Saves the current record to the database, insert or update is automatically determined. |
||
| 414 | * @return boolean true if record was saved successfully, false otherwise. |
||
| 415 | */ |
||
| 416 | public function save() |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Deletes the current record from the database. Once deleted, this object |
||
| 443 | * can not be saved again in the same instance. |
||
| 444 | * @return boolean true if the record was deleted successfully, false otherwise. |
||
| 445 | */ |
||
| 446 | public function delete() |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Delete records by primary key. Usage: |
||
| 467 | * |
||
| 468 | * <code> |
||
| 469 | * $finder->deleteByPk($primaryKey); //delete 1 record |
||
| 470 | * $finder->deleteByPk($key1,$key2,...); //delete multiple records |
||
| 471 | * $finder->deleteByPk(array($key1,$key2,...)); //delete multiple records |
||
| 472 | * </code> |
||
| 473 | * |
||
| 474 | * For composite primary keys (determined from the table definitions): |
||
| 475 | * <code> |
||
| 476 | * $finder->deleteByPk(array($key1,$key2)); //delete 1 record |
||
| 477 | * |
||
| 478 | * //delete multiple records |
||
| 479 | * $finder->deleteByPk(array($key1,$key2), array($key3,$key4),...); |
||
| 480 | * |
||
| 481 | * //delete multiple records |
||
| 482 | * $finder->deleteByPk(array( array($key1,$key2), array($key3,$key4), .. )); |
||
| 483 | * </code> |
||
| 484 | * |
||
| 485 | * @param mixed primary key values. |
||
| 486 | * @return int number of records deleted. |
||
| 487 | */ |
||
| 488 | public function deleteByPk($keys) |
||
| 494 | |||
| 495 | /** |
||
| 496 | * Alias for deleteByPk() |
||
| 497 | */ |
||
| 498 | public function deleteAllByPks($keys) |
||
| 504 | /** |
||
| 505 | * Delete multiple records using a criteria. |
||
| 506 | * @param string|TActiveRecordCriteria SQL condition or criteria object. |
||
| 507 | * @param mixed parameter values. |
||
| 508 | * @return int number of records deleted. |
||
| 509 | */ |
||
| 510 | public function deleteAll($criteria=null, $parameters=array()) |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Populates a new record with the query result. |
||
| 519 | * This is a wrapper of {@link createRecord}. |
||
| 520 | * @param array name value pair of record data |
||
| 521 | * @return TActiveRecord object record, null if data is empty. |
||
| 522 | */ |
||
| 523 | protected function populateObject($data) |
||
| 527 | |||
| 528 | /** |
||
| 529 | * @param TDbDataReader data reader |
||
| 530 | * @return array the AR objects populated by the query result |
||
| 531 | * @since 3.1.2 |
||
| 532 | */ |
||
| 533 | protected function populateObjects($reader) |
||
| 540 | |||
| 541 | /** |
||
| 542 | * Create an AR instance specified by the AR class name and initial data. |
||
| 543 | * If the initial data is empty, the AR object will not be created and null will be returned. |
||
| 544 | * (You should use the "new" operator to create the AR instance in that case.) |
||
| 545 | * @param string the AR class name |
||
| 546 | * @param array initial data to be populated into the AR object. |
||
| 547 | * @return TActiveRecord the initialized AR object. Null if the initial data is empty. |
||
| 548 | * @since 3.1.2 |
||
| 549 | */ |
||
| 550 | public static function createRecord($type, $data) |
||
| 558 | |||
| 559 | /** |
||
| 560 | * Find one single record that matches the criteria. |
||
| 561 | * |
||
| 562 | * Usage: |
||
| 563 | * <code> |
||
| 564 | * $finder->find('username = :name AND password = :pass', |
||
| 565 | * array(':name'=>$name, ':pass'=>$pass)); |
||
| 566 | * $finder->find('username = ? AND password = ?', array($name, $pass)); |
||
| 567 | * $finder->find('username = ? AND password = ?', $name, $pass); |
||
| 568 | * //$criteria is of TActiveRecordCriteria |
||
| 569 | * $finder->find($criteria); //the 2nd parameter for find() is ignored. |
||
| 570 | * </code> |
||
| 571 | * |
||
| 572 | * @param string|TActiveRecordCriteria SQL condition or criteria object. |
||
| 573 | * @param mixed parameter values. |
||
| 574 | * @return TActiveRecord matching record object. Null if no result is found. |
||
| 575 | */ |
||
| 576 | public function find($criteria,$parameters=array()) |
||
| 584 | |||
| 585 | /** |
||
| 586 | * Same as find() but returns an array of objects. |
||
| 587 | * |
||
| 588 | * @param string|TActiveRecordCriteria SQL condition or criteria object. |
||
| 589 | * @param mixed parameter values. |
||
| 590 | * @return array matching record objects. Empty array if no result is found. |
||
| 591 | */ |
||
| 592 | public function findAll($criteria=null,$parameters=array()) |
||
| 600 | |||
| 601 | /** |
||
| 602 | * Find one record using only the primary key or composite primary keys. Usage: |
||
| 603 | * |
||
| 604 | * <code> |
||
| 605 | * $finder->findByPk($primaryKey); |
||
| 606 | * $finder->findByPk($key1, $key2, ...); |
||
| 607 | * $finder->findByPk(array($key1,$key2,...)); |
||
| 608 | * </code> |
||
| 609 | * |
||
| 610 | * @param mixed primary keys |
||
| 611 | * @return TActiveRecord. Null if no result is found. |
||
| 612 | */ |
||
| 613 | public function findByPk($keys) |
||
| 622 | |||
| 623 | /** |
||
| 624 | * Find multiple records matching a list of primary or composite keys. |
||
| 625 | * |
||
| 626 | * For scalar primary keys: |
||
| 627 | * <code> |
||
| 628 | * $finder->findAllByPk($key1, $key2, ...); |
||
| 629 | * $finder->findAllByPk(array($key1, $key2, ...)); |
||
| 630 | * </code> |
||
| 631 | * |
||
| 632 | * For composite keys: |
||
| 633 | * <code> |
||
| 634 | * $finder->findAllByPk(array($key1, $key2), array($key3, $key4), ...); |
||
| 635 | * $finder->findAllByPk(array(array($key1, $key2), array($key3, $key4), ...)); |
||
| 636 | * </code> |
||
| 637 | * @param mixed primary keys |
||
| 638 | * @return array matching ActiveRecords. Empty array is returned if no result is found. |
||
| 639 | */ |
||
| 640 | public function findAllByPks($keys) |
||
| 647 | |||
| 648 | /** |
||
| 649 | * Find records using full SQL, returns corresponding record object. |
||
| 650 | * The names of the column retrieved must be defined in your Active Record |
||
| 651 | * class. |
||
| 652 | * @param string select SQL |
||
| 653 | * @param array $parameters |
||
| 654 | * @return TActiveRecord, null if no result is returned. |
||
| 655 | */ |
||
| 656 | public function findBySql($sql,$parameters=array()) |
||
| 664 | |||
| 665 | /** |
||
| 666 | * Find records using full SQL, returns corresponding record object. |
||
| 667 | * The names of the column retrieved must be defined in your Active Record |
||
| 668 | * class. |
||
| 669 | * @param string select SQL |
||
| 670 | * @param array $parameters |
||
| 671 | * @return array matching active records. Empty array is returned if no result is found. |
||
| 672 | */ |
||
| 673 | public function findAllBySql($sql,$parameters=array()) |
||
| 680 | |||
| 681 | /** |
||
| 682 | * Fetches records using the sql clause "(fields) IN (values)", where |
||
| 683 | * fields is an array of column names and values is an array of values that |
||
| 684 | * the columns must have. |
||
| 685 | * |
||
| 686 | * This method is to be used by the relationship handler. |
||
| 687 | * |
||
| 688 | * @param TActiveRecordCriteria additional criteria |
||
| 689 | * @param array field names to match with "(fields) IN (values)" sql clause. |
||
| 690 | * @param array matching field values. |
||
| 691 | * @return array matching active records. Empty array is returned if no result is found. |
||
| 692 | */ |
||
| 693 | public function findAllByIndex($criteria,$fields,$values) |
||
| 698 | |||
| 699 | /** |
||
| 700 | * Find the number of records. |
||
| 701 | * @param string|TActiveRecordCriteria SQL condition or criteria object. |
||
| 702 | * @param mixed parameter values. |
||
| 703 | * @return int number of records. |
||
| 704 | */ |
||
| 705 | public function count($criteria=null,$parameters=array()) |
||
| 712 | |||
| 713 | /** |
||
| 714 | * Returns the active record relationship handler for $RELATION with key |
||
| 715 | * value equal to the $property value. |
||
| 716 | * @param string relationship/property name corresponding to keys in $RELATION array. |
||
| 717 | * @param array method call arguments. |
||
| 718 | * @return TActiveRecordRelation, null if the context or the handler doesn't exist |
||
| 719 | */ |
||
| 720 | protected function getRelationHandler($name,$args=array()) |
||
| 730 | |||
| 731 | /** |
||
| 732 | * Gets a static copy of the relationship context for given property (a key |
||
| 733 | * in $RELATIONS), returns null if invalid relationship. Keeps a null |
||
| 734 | * reference to all invalid relations called. |
||
| 735 | * @param string relationship/property name corresponding to keys in $RELATION array. |
||
| 736 | * @return TActiveRecordRelationContext object containing information on |
||
| 737 | * the active record relationships for given property, null if invalid relationship |
||
| 738 | * @since 3.1.2 |
||
| 739 | */ |
||
| 740 | protected function createRelationContext($name) |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Tries to load the relationship results for the given property. The $property |
||
| 753 | * value should correspond to an entry key in the $RELATION array. |
||
| 754 | * This method can be used to lazy load relationships. |
||
| 755 | * <code> |
||
| 756 | * class TeamRecord extends TActiveRecord |
||
| 757 | * { |
||
| 758 | * ... |
||
| 759 | * |
||
| 760 | * private $_players; |
||
| 761 | * public static $RELATION=array |
||
| 762 | * ( |
||
| 763 | * 'players' => array(self::HAS_MANY, 'PlayerRecord'), |
||
| 764 | * ); |
||
| 765 | * |
||
| 766 | * public function setPlayers($array) |
||
| 767 | * { |
||
| 768 | * $this->_players=$array; |
||
| 769 | * } |
||
| 770 | * |
||
| 771 | * public function getPlayers() |
||
| 772 | * { |
||
| 773 | * if($this->_players===null) |
||
| 774 | * $this->fetchResultsFor('players'); |
||
| 775 | * return $this->_players; |
||
| 776 | * } |
||
| 777 | * } |
||
| 778 | * Usage example: |
||
| 779 | * $team = TeamRecord::finder()->findByPk(1); |
||
| 780 | * var_dump($team->players); //uses lazy load to fetch 'players' relation |
||
| 781 | * </code> |
||
| 782 | * @param string relationship/property name corresponding to keys in $RELATION array. |
||
| 783 | * @return boolean true if relationship exists, false otherwise. |
||
| 784 | * @since 3.1.2 |
||
| 785 | */ |
||
| 786 | protected function fetchResultsFor($property) |
||
| 793 | |||
| 794 | /** |
||
| 795 | * Dynamic find method using parts of method name as search criteria. |
||
| 796 | * Method name starting with "findBy" only returns 1 record. |
||
| 797 | * Method name starting with "findAllBy" returns 0 or more records. |
||
| 798 | * Method name starting with "deleteBy" deletes records by the trail criteria. |
||
| 799 | * The condition is taken as part of the method name after "findBy", "findAllBy" |
||
| 800 | * or "deleteBy". |
||
| 801 | * |
||
| 802 | * The following are equivalent: |
||
| 803 | * <code> |
||
| 804 | * $finder->findByName($name) |
||
| 805 | * $finder->find('Name = ?', $name); |
||
| 806 | * </code> |
||
| 807 | * <code> |
||
| 808 | * $finder->findByUsernameAndPassword($name,$pass); // OR may be used |
||
| 809 | * $finder->findBy_Username_And_Password($name,$pass); // _OR_ may be used |
||
| 810 | * $finder->find('Username = ? AND Password = ?', $name, $pass); |
||
| 811 | * </code> |
||
| 812 | * <code> |
||
| 813 | * $finder->findAllByAge($age); |
||
| 814 | * $finder->findAll('Age = ?', $age); |
||
| 815 | * </code> |
||
| 816 | * <code> |
||
| 817 | * $finder->deleteAll('Name = ?', $name); |
||
| 818 | * $finder->deleteByName($name); |
||
| 819 | * </code> |
||
| 820 | * @return mixed single record if method name starts with "findBy", 0 or more records |
||
| 821 | * if method name starts with "findAllBy" |
||
| 822 | */ |
||
| 823 | public function __call($method,$args) |
||
| 853 | |||
| 854 | /** |
||
| 855 | * @return TActiveRecordInvalidFinderResult Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'. |
||
| 856 | * @see TActiveRecordManager::getInvalidFinderResult |
||
| 857 | * @since 3.1.5 |
||
| 858 | */ |
||
| 859 | public function getInvalidFinderResult() |
||
| 866 | |||
| 867 | /** |
||
| 868 | * Define the way an active record finder react if an invalid magic-finder invoked |
||
| 869 | * |
||
| 870 | * @param TActiveRecordInvalidFinderResult|null |
||
| 871 | * @see TActiveRecordManager::setInvalidFinderResult |
||
| 872 | * @since 3.1.5 |
||
| 873 | */ |
||
| 874 | public function setInvalidFinderResult($value) |
||
| 881 | |||
| 882 | /** |
||
| 883 | * Create a new TSqlCriteria object from a string $criteria. The $args |
||
| 884 | * are additional parameters and are used in place of the $parameters |
||
| 885 | * if $parameters is not an array and $args is an arrary. |
||
| 886 | * @param string|TSqlCriteria sql criteria |
||
| 887 | * @param mixed parameters passed by the user. |
||
| 888 | * @param array additional parameters obtained from function_get_args(). |
||
| 889 | * @return TSqlCriteria criteria object. |
||
| 890 | */ |
||
| 891 | protected function getRecordCriteria($criteria, $parameters, $args=array()) |
||
| 904 | |||
| 905 | /** |
||
| 906 | * Raised when a command is prepared and parameter binding is completed. |
||
| 907 | * The parameter object is TDataGatewayEventParameter of which the |
||
| 908 | * {@link TDataGatewayEventParameter::getCommand Command} property can be |
||
| 909 | * inspected to obtain the sql query to be executed. |
||
| 910 | * |
||
| 911 | * Note well that the finder objects obtained from ActiveRecord::finder() |
||
| 912 | * method are static objects. This means that the event handlers are |
||
| 913 | * bound to a static finder object and not to each distinct active record object. |
||
| 914 | * @param TDataGatewayEventParameter |
||
| 915 | */ |
||
| 916 | public function onCreateCommand($param) |
||
| 920 | |||
| 921 | /** |
||
| 922 | * Raised when a command is executed and the result from the database was returned. |
||
| 923 | * The parameter object is TDataGatewayResultEventParameter of which the |
||
| 924 | * {@link TDataGatewayEventParameter::getResult Result} property contains |
||
| 925 | * the data return from the database. The data returned can be changed |
||
| 926 | * by setting the {@link TDataGatewayEventParameter::setResult Result} property. |
||
| 927 | * |
||
| 928 | * Note well that the finder objects obtained from ActiveRecord::finder() |
||
| 929 | * method are static objects. This means that the event handlers are |
||
| 930 | * bound to a static finder object and not to each distinct active record object. |
||
| 931 | * @param TDataGatewayResultEventParameter |
||
| 932 | */ |
||
| 933 | public function onExecuteCommand($param) |
||
| 937 | |||
| 938 | /** |
||
| 939 | * Raised before the record attempt to insert its data into the database. |
||
| 940 | * To prevent the insert operation, set the TActiveRecordChangeEventParameter::IsValid parameter to false. |
||
| 941 | * @param TActiveRecordChangeEventParameter event parameter to be passed to the event handlers |
||
| 942 | */ |
||
| 943 | public function onInsert($param) |
||
| 947 | |||
| 948 | /** |
||
| 949 | * Raised before the record attempt to delete its data from the database. |
||
| 950 | * To prevent the delete operation, set the TActiveRecordChangeEventParameter::IsValid parameter to false. |
||
| 951 | * @param TActiveRecordChangeEventParameter event parameter to be passed to the event handlers |
||
| 952 | */ |
||
| 953 | public function onDelete($param) |
||
| 957 | |||
| 958 | /** |
||
| 959 | * Raised before the record attempt to update its data in the database. |
||
| 960 | * To prevent the update operation, set the TActiveRecordChangeEventParameter::IsValid parameter to false. |
||
| 961 | * @param TActiveRecordChangeEventParameter event parameter to be passed to the event handlers |
||
| 962 | */ |
||
| 963 | public function onUpdate($param) |
||
| 967 | |||
| 968 | /** |
||
| 969 | * Retrieves the column value according to column name. |
||
| 970 | * This method is used internally. |
||
| 971 | * @param string the column name (as defined in database schema) |
||
| 972 | * @return mixed the corresponding column value |
||
| 973 | * @since 3.1.1 |
||
| 974 | */ |
||
| 975 | public function getColumnValue($columnName) |
||
| 982 | |||
| 983 | /** |
||
| 984 | * Sets the column value according to column name. |
||
| 985 | * This method is used internally. |
||
| 986 | * @param string the column name (as defined in database schema) |
||
| 987 | * @param mixed the corresponding column value |
||
| 988 | * @since 3.1.1 |
||
| 989 | */ |
||
| 990 | public function setColumnValue($columnName,$value) |
||
| 997 | |||
| 998 | /** |
||
| 999 | * @param string relation property name |
||
| 1000 | * @return array relation definition for the specified property |
||
| 1001 | * @since 3.1.2 |
||
| 1002 | */ |
||
| 1003 | public function getRecordRelation($property) |
||
| 1009 | |||
| 1010 | /** |
||
| 1011 | * @return array all relation definitions declared in the AR class |
||
| 1012 | * @since 3.1.2 |
||
| 1013 | */ |
||
| 1014 | public function getRecordRelations() |
||
| 1018 | |||
| 1019 | /** |
||
| 1020 | * @param string AR property name |
||
| 1021 | * @return boolean whether a relation is declared for the specified AR property |
||
| 1022 | * @since 3.1.2 |
||
| 1023 | */ |
||
| 1024 | public function hasRecordRelation($property) |
||
| 1028 | |||
| 1029 | /** |
||
| 1030 | * Return record data as array |
||
| 1031 | * @return array of column name and column values |
||
| 1032 | * @since 3.2.4 |
||
| 1033 | */ |
||
| 1034 | public function toArray(){ |
||
| 1042 | |||
| 1043 | /** |
||
| 1044 | * Return record data as JSON |
||
| 1045 | * @return JSON |
||
| 1046 | * @since 3.2.4 |
||
| 1047 | */ |
||
| 1048 | public function toJSON(){ |
||
| 1051 | } |
||
| 1052 | |||
| 1108 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.