Horde_Kolab_Server_Object_Factory::factory PHP Method

factory() public static method

Attempts to return a concrete Horde_Kolab_Server_Object instance based on $type.
public static factory ( mixed $type, string $uid, Horde_Kolab_Server_Composite $storage, array $data = null ) : Horde_Kolab_Server_Object | PEAR_Error
$type mixed The type of the Horde_Kolab_Server_Object subclass to return.
$uid string UID of the object
$storage Horde_Kolab_Server_Composite A link to the Kolab_Server class handling read/write.
$data array A possible array of data for the object
return Horde_Kolab_Server_Object | PEAR_Error The newly created concrete Horde_Kolab_Server_Object instance.
    public static function factory($type, $uid, Horde_Kolab_Server_Composite $storage, $data = null)
    {
        if (class_exists($type)) {
            $object = new $type($storage, $uid, $data);
        } else {
            throw new Horde_Kolab_Server_Exception('Class definition of ' . $type . ' not found.');
        }
        $object = new Horde_Kolab_Server_Object_Hash($object);
        return $object;
    }

Usage Example

Example #1
0
 /**
  * Fetch a Kolab object.
  *
  * This method will not retrieve any data from the server
  * immediately. Instead it will simply generate a new instance for the
  * desired object.
  *
  * The server data will only be accessed once you start reading the object
  * data.
  *
  * This method can also be used in order to fetch non-existing objects that
  * will be saved later. This is however not recommended and you should
  * rather use the add($info) method for that.
  *
  * If you do not provide the object type the server will try to determine it
  * automatically based on the uid. As this requires reading data from the
  * server it is recommended to specify the object type whenever it is known.
  *
  * If you do not specify a uid the object corresponding to the user bound to
  * the server will be returned.
  *
  * @param string $guid The GUID of the object to fetch.
  * @param string $type The type of the object to fetch.
  *
  * @return Kolab_Object The corresponding Kolab object.
  *
  * @throws Horde_Kolab_Server_Exception
  */
 public function fetch($guid = null, $type = null)
 {
     if (!isset($guid)) {
         $guid = $this->_composite->server->getGuid();
     }
     if (empty($type)) {
         $type = $this->_composite->structure->determineType($guid);
     }
     $object = Horde_Kolab_Server_Object_Factory::factory($type, $guid, $this->_composite);
     return $object;
 }
Horde_Kolab_Server_Object_Factory