Merge "[JobQueue] Added a JobQueueRedis class."
[lhc/web/wiklou.git] / includes / db / ORMTable.php
index 4079315..06f88c1 100644 (file)
@@ -19,6 +19,7 @@
  * http://www.gnu.org/copyleft/gpl.html
  *
  * @since 1.20
+ * Non-abstract since 1.21
  *
  * @file ORMTable.php
  * @ingroup ORM
  * @author Jeroen De Dauw < jeroendedauw@gmail.com >
  */
 
-abstract class ORMTable extends DBAccessBase implements IORMTable {
+class ORMTable extends DBAccessBase implements IORMTable {
 
        /**
-        * Gets the db field prefix.
+        * Cache for instances, used by the singleton method.
         *
         * @since 1.20
+        * @deprecated since 1.21
         *
-        * @return string
+        * @var ORMTable[]
         */
-       protected abstract function getFieldPrefix();
+       protected static $instanceCache = array();
 
        /**
-        * Cache for instances, used by the singleton method.
+        * @since 1.21
         *
-        * @since 1.20
-        * @var array of DBTable
+        * @var string
         */
-       protected static $instanceCache = array();
+       protected $tableName;
+
+       /**
+        * @since 1.21
+        *
+        * @var string[]
+        */
+       protected $fields = array();
+
+       /**
+        * @since 1.21
+        *
+        * @var string
+        */
+       protected $fieldPrefix = '';
+
+       /**
+        * @since 1.21
+        *
+        * @var string
+        */
+       protected $rowClass = 'ORMRow';
+
+       /**
+        * @since 1.21
+        *
+        * @var array
+        */
+       protected $defaults = array();
 
        /**
         * ID of the database connection to use for read operations.
         * Can be changed via @see setReadDb.
         *
         * @since 1.20
+        *
         * @var integer DB_ enum
         */
        protected $readDb = DB_SLAVE;
 
+       /**
+        * Constructor.
+        *
+        * @since 1.21
+        *
+        * @param string $tableName
+        * @param string[] $fields
+        * @param array $defaults
+        * @param string|null $rowClass
+        * @param string $fieldPrefix
+        */
+       public function __construct( $tableName = '', array $fields = array(), array $defaults = array(), $rowClass = null, $fieldPrefix = '' ) {
+               $this->tableName = $tableName;
+               $this->fields = $fields;
+               $this->defaults = $defaults;
+
+               if ( is_string( $rowClass ) ) {
+                       $this->rowClass = $rowClass;
+               }
+
+               $this->fieldPrefix = $fieldPrefix;
+       }
+
+       /**
+        * @see IORMTable::getName
+        *
+        * @since 1.21
+        *
+        * @return string
+        * @throws MWException
+        */
+       public function getName() {
+               if ( $this->tableName === '' ) {
+                       throw new MWException( 'The table name needs to be set' );
+               }
+
+               return $this->tableName;
+       }
+
+       /**
+        * Gets the db field prefix.
+        *
+        * @since 1.20
+        *
+        * @return string
+        */
+       protected function getFieldPrefix() {
+               return $this->fieldPrefix;
+       }
+
+       /**
+        * @see IORMTable::getRowClass
+        *
+        * @since 1.21
+        *
+        * @return string
+        */
+       public function getRowClass() {
+               return $this->rowClass;
+       }
+
+       /**
+        * @see ORMTable::getFields
+        *
+        * @since 1.21
+        *
+        * @return array
+        * @throws MWException
+        */
+       public function getFields() {
+               if ( $this->fields === array() ) {
+                       throw new MWException( 'The table needs to have one or more fields' );
+               }
+
+               return $this->fields;
+       }
+
        /**
         * Returns a list of default field values.
         * field name => field value
@@ -64,7 +171,7 @@ abstract class ORMTable extends DBAccessBase implements IORMTable {
         * @return array
         */
        public function getDefaults() {
-               return array();
+               return $this->defaults;
        }
 
        /**
@@ -680,6 +787,7 @@ abstract class ORMTable extends DBAccessBase implements IORMTable {
         * Get an instance of this class.
         *
         * @since 1.20
+        * @deprecated since 1.21
         *
         * @return IORMTable
         */