コード例 #1
0
ファイル: datamanager.php プロジェクト: nemein/openpsa
 /**
  * This function sets the system to use a specific storage object. You can pass
  * either a MidCOM DBA object or a fully initialized storage subclass. The former
  * is automatically wrapped in a midcom storage object. If you pass your own
  * storage object, ensure that it uses the same schema as this class. Ideally,
  * you should use references for this.
  *
  * This call will fail if there is no schema set. All types will be set and
  * initialized to the new storage object. Thus, it is possible to call set_storage
  * repeatedly thus switching an existing DM instance over to a new storage object
  * as long as you work with the same schema.
  *
  * @param mixed &$object A reference to either a MidCOM DBA class or a subclass of
  *     midcom_helper_datamanager2_storage.
  * @return boolean Indicating success.
  */
 function set_storage($object)
 {
     if ($this->schema === null) {
         debug_add('Cannot initialize to a storage object if the schema is not yet set.', MIDCOM_LOG_INFO);
         return false;
     }
     if (!is_a($object, 'midcom_helper_datamanager2_storage')) {
         $this->storage = new midcom_helper_datamanager2_storage_midgard($this->schema, $object);
     } else {
         $this->storage = $object;
     }
     // For reasons I do not completely comprehend, PHP drops the storage references into the types
     // in the lines above. Right now the only solution (except debugging this 5 hours long line
     // by line) I see is explicitly setting the storage references in the types.
     foreach ($this->types as $type => $copy) {
         $this->types[$type]->set_storage($this->storage);
     }
     $this->storage->load($this->types);
     return true;
 }