follow up to r111468 - moved a bunch of methods from DBDataObject to DBTable and...
authorJeroen De Dauw <jeroendedauw@users.mediawiki.org>
Tue, 14 Feb 2012 21:16:39 +0000 (21:16 +0000)
committerJeroen De Dauw <jeroendedauw@users.mediawiki.org>
Tue, 14 Feb 2012 21:16:39 +0000 (21:16 +0000)
includes/DBDataObject.php
includes/DBTable.php

index 2059715..1e5bc26 100644 (file)
@@ -94,6 +94,7 @@ abstract class DBDataObject {
         *
         * @since 1.20
         *
+        * @param DBTable $table
         * @param array|null $fields
         * @param boolean $loadDefaults
         */
@@ -528,20 +529,6 @@ abstract class DBDataObject {
                }
        }
 
-       /**
-        * Get a new instance of the class from an array.
-        *
-        * @since 1.20
-        *
-        * @param array $data
-        * @param boolean $loadDefaults
-        *
-        * @return DBDataObject
-        */
-       public function newFromArray( array $data, $loadDefaults = false ) {
-               return new self( $data, $loadDefaults );
-       }
-
        /**
         * Get the database type used for read operations.
         *
@@ -706,43 +693,7 @@ abstract class DBDataObject {
 
                return false;
        }
-       
-       protected function getDBTable() {
-               return $this->table->getDBTable();
-       }
-       
-       /**
-        * Get an array with fields from a database result,
-        * that can be fed directly to the constructor or
-        * to setFields.
-        *
-        * @since 1.20
-        *
-        * @param object $result
-        *
-        * @return array
-        */
-       public function getFieldsFromDBResult( $result ) {
-               $result = (array)$result;
-               return array_combine(
-                       $this->unprefixFieldNames( array_keys( $result ) ),
-                       array_values( $result )
-               );
-       }
-       
-       /**
-        * Get a new instance of the class from a database result.
-        *
-        * @since 1.20
-        *
-        * @param stdClass $result
-        *
-        * @return DBDataObject
-        */
-       public function newFromDBResult( stdClass $result ) {
-               return $this->newFromArray( $this->getFieldsFromDBResult( $result ) );
-       }
-       
+
        /**
         * Returns the table this DBDataObject is a row in.
         * 
index ad09234..0353a69 100644 (file)
@@ -29,7 +29,7 @@ abstract class DBTable {
         * 
         * @return string
         */
-       protected abstract function getDataObjectClass();
+       public abstract function getDataObjectClass();
        
        /**
         * Gets the db field prefix.
@@ -482,7 +482,7 @@ abstract class DBTable {
         * @return array
         */
        public function unprefixFieldNames( array $fieldNames ) {
-               return array_map( '$this->unprefixFieldName', $fieldNames );
+               return array_map( array( $this, 'unprefixFieldName' ), $fieldNames );
        }
        
        /**
@@ -518,5 +518,63 @@ abstract class DBTable {
                
                return $instance;
        }
+
+       /**
+        * Get an array with fields from a database result,
+        * that can be fed directly to the constructor or
+        * to setFields.
+        *
+        * @since 1.20
+        *
+        * @param stdClass $result
+        *
+        * @return array
+        */
+       public function getFieldsFromDBResult( stdClass $result ) {
+               $result = (array)$result;
+               return array_combine(
+                       $this->unprefixFieldNames( array_keys( $result ) ),
+                       array_values( $result )
+               );
+       }
+
+       /**
+        * Get a new instance of the class from a database result.
+        *
+        * @since 1.20
+        *
+        * @param stdClass $result
+        *
+        * @return DBDataObject
+        */
+       public function newFromDBResult( stdClass $result ) {
+               return $this->newFromArray( $this->getFieldsFromDBResult( $result ) );
+       }
+
+       /**
+        * Get a new instance of the class from an array.
+        *
+        * @since 1.20
+        *
+        * @param array $data
+        * @param boolean $loadDefaults
+        *
+        * @return DBDataObject
+        */
+       public function newFromArray( array $data, $loadDefaults = false ) {
+               $class = $this->getDataObjectClass();
+               return new $class( $this, $data, $loadDefaults );
+       }
+
+       /**
+        * Return the names of the fields.
+        *
+        * @since 1.20
+        *
+        * @return array
+        */
+       public function getFieldNames() {
+               return array_keys( $this->getFieldTypes() );
+       }
        
 }