diff options
author | Evan Prodromou <evan@status.net> | 2010-06-04 15:29:38 -0400 |
---|---|---|
committer | Evan Prodromou <evan@status.net> | 2010-06-04 15:29:38 -0400 |
commit | 6d39a7513787c6747fc9ff50a33a733eb3148682 (patch) | |
tree | f5dfaf0b9636da2d6fec5b50cd96be003340306b | |
parent | cbdeb6fb8f663bb3be5c161e1c605f12fc4878a6 (diff) |
use DB_DataObject_Cast objects in a couple of different places in the code
-rw-r--r-- | classes/Memcached_DataObject.php | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index bd9b528db..4579f64df 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -133,25 +133,7 @@ class Memcached_DataObject extends Safe_DataObject common_log(LOG_ERR, __METHOD__ . ' object in param: ' . str_replace("\n", " ", $e->getTraceAsString())); } - if (is_object($v) && $v instanceof DB_DataObject_Cast) { - switch ($v->type) { - case 'date': - $vstr = $v->year . '-' . $v->month . '-' . $v->day; - break; - case 'blob': - case 'string': - case 'sql': - case 'datetime': - case 'time': - throw new ServerException("Unhandled DB_DataObject_Cast type passed as cacheKey value: '$v->type'"); - break; - default: - throw new ServerException("Unknown DB_DataObject_Cast type passed as cacheKey value: '$v->type'"); - break; - } - } else { - $vstr = $v; - } + $vstr = self::valueString($v); return common_cache_key(strtolower($cls).':'.$k.':'.$vstr); } @@ -248,10 +230,10 @@ class Memcached_DataObject extends Safe_DataObject if (empty($this->$key)) { continue; } - $ckeys[] = $this->cacheKey($this->tableName(), $key, $this->$key); + $ckeys[] = $this->cacheKey($this->tableName(), $key, self::valueString($this->$key)); } else if ($type == 'K' || $type == 'N') { $pkey[] = $key; - $pval[] = $this->$key; + $pval[] = self::valueString($this->$key); } else { throw new Exception("Unknown key type $key => $type for " . $this->tableName()); } @@ -623,5 +605,30 @@ class Memcached_DataObject extends Safe_DataObject return $c->set($cacheKey, $value); } + + static function valueString($v) + { + $vstr = null; + if (is_object($v) && $v instanceof DB_DataObject_Cast) { + switch ($v->type) { + case 'date': + $vstr = $v->year . '-' . $v->month . '-' . $v->day; + break; + case 'blob': + case 'string': + case 'sql': + case 'datetime': + case 'time': + throw new ServerException("Unhandled DB_DataObject_Cast type passed as cacheKey value: '$v->type'"); + break; + default: + throw new ServerException("Unknown DB_DataObject_Cast type passed as cacheKey value: '$v->type'"); + break; + } + } else { + $vstr = strval($v); + } + return $vstr; + } } |