]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Managed_DataObject.php
hard-require the adapter
[quix0rs-gnu-social.git] / classes / Managed_DataObject.php
index 31aa7c359314a3584d38abbb3912a61d39dbae80..7263b3e3206f787c6116599f43f1a2e1e489c7aa 100644 (file)
@@ -38,7 +38,9 @@ abstract class Managed_DataObject extends Memcached_DataObject
      */
     function table()
     {
-        $table = self::schemaDef();
+        // Hack for PHP 5.2 not supporting late static binding
+        //$table = static::schemaDef();
+        $table = call_user_func(array(get_class($this), 'schemaDef'));
         return array_map(array($this, 'columnBitmap'), $table['fields']);
     }
 
@@ -66,7 +68,7 @@ abstract class Managed_DataObject extends Memcached_DataObject
 
     function sequenceKey()
     {
-        $table = self::schemaDef();
+        $table = call_user_func(array(get_class($this), 'schemaDef'));
         foreach ($table['fields'] as $name => $column) {
             if ($column['type'] == 'serial') {
                 // We have a serial/autoincrement column.
@@ -90,8 +92,8 @@ abstract class Managed_DataObject extends Memcached_DataObject
 
     function keyTypes()
     {
+        $table = call_user_func(array(get_class($this), 'schemaDef'));
         $keys = array();
-        $table = self::schemaDef();
 
         if (!empty($table['unique keys'])) {
             foreach ($table['unique keys'] as $idx => $fields) {
@@ -117,40 +119,37 @@ abstract class Managed_DataObject extends Memcached_DataObject
      */
     function columnBitmap($column)
     {
-        $type = 0;
-
-        switch ($column['type']) {
-        case 'int':
-        case 'serial':
-        case 'numeric':
-            // Doesn't need quoting.
-            $type |= DB_DATAOBJECT_INT;
-            break;
-        default:
-            // Value needs quoting in SQL literal statements.
-            $type |= DB_DATAOBJECT_STR;
+        $type = $column['type'];
+
+        // For quoting style...
+        $intTypes = array('int',
+                          'integer',
+                          'float',
+                          'serial',
+                          'numeric');
+        if (in_array($type, $intTypes)) {
+            $style = DB_DATAOBJECT_INT;
+        } else {
+            $style = DB_DATAOBJECT_STR;
         }
 
-        switch ($column['type']) {
-        case 'blob':
-            $type |= DB_DATAOBJECT_BLOB;
-            break;
-        case 'text':
-            $type |= DB_DATAOBJECT_TXT;
-            break;
-        case 'datetime':
-            $type |= DB_DATAOBJECT_DATE;
-            $type |= DB_DATAOBJECT_TIME;
-            break;
-        case 'timestamp':
-            $type |= DB_DATAOBJECT_MYSQLTIMESTAMP;
-            break;
+        // Data type formatting style...
+        $formatStyles = array('blob' => DB_DATAOBJECT_BLOB,
+                              'text' => DB_DATAOBJECT_TXT,
+                              'date' => DB_DATAOBJECT_DATE,
+                              'time' => DB_DATAOBJECT_TIME,
+                              'datetime' => DB_DATAOBJECT_DATE | DB_DATAOBJECT_TIME,
+                              'timestamp' => DB_DATAOBJECT_MYSQLTIMESTAMP);
+
+        if (isset($formatStyles[$type])) {
+            $style |= $formatStyles[$type];
         }
 
+        // Nullable?
         if (!empty($column['not null'])) {
-            $type |= DB_DATAOBJECT_NOTNULL;
+            $style |= DB_DATAOBJECT_NOTNULL;
         }
 
-        return $type;
+        return $style;
     }
 }
\ No newline at end of file