r111490 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111489‎ | r111490 | r111491 >
Date:21:16, 14 February 2012
Author:jeroendedauw
Status:reverted
Tags:
Comment:
follow up to r111468 - moved a bunch of methods from DBDataObject to DBTable and some minor changes
Modified paths:
  • /trunk/phase3/includes/DBDataObject.php (modified) (history)
  • /trunk/phase3/includes/DBTable.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DBDataObject.php
@@ -94,6 +94,7 @@
9595 *
9696 * @since 1.20
9797 *
 98+ * @param DBTable $table
9899 * @param array|null $fields
99100 * @param boolean $loadDefaults
100101 */
@@ -529,20 +530,6 @@
530531 }
531532
532533 /**
533 - * Get a new instance of the class from an array.
534 - *
535 - * @since 1.20
536 - *
537 - * @param array $data
538 - * @param boolean $loadDefaults
539 - *
540 - * @return DBDataObject
541 - */
542 - public function newFromArray( array $data, $loadDefaults = false ) {
543 - return new self( $data, $loadDefaults );
544 - }
545 -
546 - /**
547534 * Get the database type used for read operations.
548535 *
549536 * @since 1.20
@@ -706,44 +693,8 @@
707694
708695 return false;
709696 }
710 -
711 - protected function getDBTable() {
712 - return $this->table->getDBTable();
713 - }
714 -
 697+
715698 /**
716 - * Get an array with fields from a database result,
717 - * that can be fed directly to the constructor or
718 - * to setFields.
719 - *
720 - * @since 1.20
721 - *
722 - * @param object $result
723 - *
724 - * @return array
725 - */
726 - public function getFieldsFromDBResult( $result ) {
727 - $result = (array)$result;
728 - return array_combine(
729 - $this->unprefixFieldNames( array_keys( $result ) ),
730 - array_values( $result )
731 - );
732 - }
733 -
734 - /**
735 - * Get a new instance of the class from a database result.
736 - *
737 - * @since 1.20
738 - *
739 - * @param stdClass $result
740 - *
741 - * @return DBDataObject
742 - */
743 - public function newFromDBResult( stdClass $result ) {
744 - return $this->newFromArray( $this->getFieldsFromDBResult( $result ) );
745 - }
746 -
747 - /**
748699 * Returns the table this DBDataObject is a row in.
749700 *
750701 * @since 1.20
Index: trunk/phase3/includes/DBTable.php
@@ -29,7 +29,7 @@
3030 *
3131 * @return string
3232 */
33 - protected abstract function getDataObjectClass();
 33+ public abstract function getDataObjectClass();
3434
3535 /**
3636 * Gets the db field prefix.
@@ -482,7 +482,7 @@
483483 * @return array
484484 */
485485 public function unprefixFieldNames( array $fieldNames ) {
486 - return array_map( '$this->unprefixFieldName', $fieldNames );
 486+ return array_map( array( $this, 'unprefixFieldName' ), $fieldNames );
487487 }
488488
489489 /**
@@ -518,5 +518,63 @@
519519
520520 return $instance;
521521 }
 522+
 523+ /**
 524+ * Get an array with fields from a database result,
 525+ * that can be fed directly to the constructor or
 526+ * to setFields.
 527+ *
 528+ * @since 1.20
 529+ *
 530+ * @param stdClass $result
 531+ *
 532+ * @return array
 533+ */
 534+ public function getFieldsFromDBResult( stdClass $result ) {
 535+ $result = (array)$result;
 536+ return array_combine(
 537+ $this->unprefixFieldNames( array_keys( $result ) ),
 538+ array_values( $result )
 539+ );
 540+ }
 541+
 542+ /**
 543+ * Get a new instance of the class from a database result.
 544+ *
 545+ * @since 1.20
 546+ *
 547+ * @param stdClass $result
 548+ *
 549+ * @return DBDataObject
 550+ */
 551+ public function newFromDBResult( stdClass $result ) {
 552+ return $this->newFromArray( $this->getFieldsFromDBResult( $result ) );
 553+ }
 554+
 555+ /**
 556+ * Get a new instance of the class from an array.
 557+ *
 558+ * @since 1.20
 559+ *
 560+ * @param array $data
 561+ * @param boolean $loadDefaults
 562+ *
 563+ * @return DBDataObject
 564+ */
 565+ public function newFromArray( array $data, $loadDefaults = false ) {
 566+ $class = $this->getDataObjectClass();
 567+ return new $class( $this, $data, $loadDefaults );
 568+ }
 569+
 570+ /**
 571+ * Return the names of the fields.
 572+ *
 573+ * @since 1.20
 574+ *
 575+ * @return array
 576+ */
 577+ public function getFieldNames() {
 578+ return array_keys( $this->getFieldTypes() );
 579+ }
522580
523581 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r111468follow up to r111264; split up class into one representing a table and one re...jeroendedauw18:11, 14 February 2012

Status & tagging log