1: <?php
2: /**
3: * Factory methods for Horde_Kolab_Server_Object instances.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Server
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_Server
12: */
13:
14: /**
15: * Factory methods for Horde_Kolab_Server_Object instances.
16: *
17: * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Kolab
23: * @package Kolab_Server
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Kolab_Server
27: */
28: class Horde_Kolab_Server_Object_Factory
29: {
30: /**
31: * Attempts to return a concrete Horde_Kolab_Server_Object instance based on
32: * $type.
33: *
34: * @param mixed $type The type of the Horde_Kolab_Server_Object subclass
35: * to return.
36: * @param string $uid UID of the object
37: * @param array $storage A link to the Kolab_Server class handling read/write.
38: * @param array $data A possible array of data for the object
39: *
40: * @return Horde_Kolab_Server_Object|PEAR_Error The newly created concrete
41: * Horde_Kolab_Server_Object instance.
42: */
43: static public function factory(
44: $type, $uid,
45: Horde_Kolab_Server_Composite $storage,
46: $data = null
47: ) {
48: if (class_exists($type)) {
49: $object = new $type($storage, $uid, $data);
50: } else {
51: throw new Horde_Kolab_Server_Exception('Class definition of ' . $type . ' not found.');
52: }
53:
54: $object = new Horde_Kolab_Server_Object_Hash($object);
55: return $object;
56: }
57:
58:
59: /**
60: * Attempts to load the concrete Horde_Kolab_Server_Object class based on
61: * $type.
62: *
63: * @param mixed $type The type of the Horde_Kolab_Server_Object subclass.
64: *
65: * @static
66: *
67: * @return true|PEAR_Error True if successfull.
68: */
69: static public function loadClass($type)
70: {
71: if (!class_exists($type)) {
72: throw new Horde_Kolab_Server_Exception('Class definition of ' . $type . ' not found.');
73: }
74: }
75: }
76: