From 411779d102f34f36be239a4593f270d788fa3f02 Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 5 Jul 2007 19:04:37 +0000 Subject: [PATCH] --- lib/Doctrine/Table.php | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 95aaa50bf..49f362257 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -1153,6 +1153,69 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { return $this->data; } + /** + * prepareValue + * this method performs special data preparation depending on + * the type of the given column + * + * 1. It unserializes array and object typed columns + * 2. Uncompresses gzip typed columns + * 3. Gets the appropriate enum values for enum typed columns + * 4. Initializes special null object pointer for null values (for fast column existence checking purposes) + * + * example: + * + * $field = 'name'; + * $value = null; + * $table->prepareValue($field, $value); // Doctrine_Null + * + * + * @throws Doctrine_Table_Exception if unserialization of array/object typed column fails or + * @throws Doctrine_Table_Exception if uncompression of gzip typed column fails * + * @param string $field the name of the field + * @param string $value field value + * @return mixed prepared value + */ + public function prepareValue($field, $value) + { + if ($value === null) { + return self::$_null; + } else { + $type = $this->getTypeOf($field); + + switch ($type) { + case 'array': + case 'object': + if (is_string($value)) { + $value = unserialize($value); + + if ($value === false) { + throw new Doctrine_Table_Exception('Unserialization of ' . $field . ' failed.'); + } + return $value; + } + break; + case 'gzip': + $value = gzuncompress($value); + + if ($value === false) { + throw new Doctrine_Table_Exception('Uncompressing of ' . $field . ' failed.'); + } + return $value; + break; + case 'enum': + return $this->enumValue($field, $value); + break; + case 'boolean': + return (boolean) $value; + break; + case 'integer': + return (int) $value; + break; + } + } + return $value; + } /** * getter for associated tree *