.

InstanceReferenceSerializier Class Reference

Helper to turn an isntance into an array or string and vice versa. More...

List of all members.

Static Public Member Functions

static  array_to_instance ($arr_inst)
  Convert an an array (containing type and keys) to an instance.
static  instance_to_array (IDataObject $inst)
  Convert an instance to an array (containing type and keys).
static  instance_to_string (IDataObject $inst)
  Convert an instance to a string (containing type and keys, concated by '/').
static  string_to_instance ($s)
  Convert a string (containing type and keys, concated by '/') to an instance.

Detailed Description

Helper to turn an isntance into an array or string and vice versa.

Definition at line 5 of file instancereferenceserializer.cls.php.


Member Function Documentation

static InstanceReferenceSerializier::array_to_instance ( arr_inst  )  [static]

Convert an an array (containing type and keys) to an instance.

Returns:
IDataObject
Parameters:
array  $arr_inst

Definition at line 27 of file instancereferenceserializer.cls.php.

00027                                                             {
00028                 $ret = false;
00029                 $table = array_shift($arr_inst);
00030                 $dao = DB::create($table);
00031                 $params = array();
00032                 if ($dao) {
00033                         foreach($dao->get_table_keys() as $key => $field) {
00034                                 /* @var $field DBField */
00035                                 $params[$key] = array_shift($arr_inst);
00036                         }
00037                 }
00038                 return DB::get_item_multi($table, $params);
00039         }
static InstanceReferenceSerializier::instance_to_array ( IDataObject inst  )  [static]

Convert an instance to an array (containing type and keys).

Parameters:
IDataObject  $inst
Returns:
array

Definition at line 12 of file instancereferenceserializer.cls.php.

00012                                                                     {
00013                 $ret = array($inst->get_table_name());
00014                 foreach($inst->get_table_keys() as $key => $field) {
00015                         /* @var $field DBField */
00016                         $ret[] = $inst->$key;
00017                 }
00018                 return $ret;            
00019         }
static InstanceReferenceSerializier::instance_to_string ( IDataObject inst  )  [static]

Convert an instance to a string (containing type and keys, concated by '/').

Parameters:
IDataObject  $inst
Returns:
string

Definition at line 47 of file instancereferenceserializer.cls.php.

00047                                                                      {
00048                 $ret = '';
00049                 $arr = self::instance_to_array($inst);
00050                 if (is_array($arr)) {
00051                         $ret = implode('/', $arr);
00052                 }
00053                 return $ret;            
00054         }
static InstanceReferenceSerializier::string_to_instance ( s  )  [static]

Convert a string (containing type and keys, concated by '/') to an instance.

Parameters:
string  $s
Returns:
IDataObject $inst

Definition at line 62 of file instancereferenceserializer.cls.php.

00062                                                       {
00063                 $arr = explode('/', $s);
00064                 return self::array_to_instance($arr);
00065         }

The documentation for this class was generated from the following file: