1: <?php
2: /**
3: * Copyright 2013-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2013-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * A factory for creating the storage object to use for compose attachments.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2013-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Factory_ComposeAtc extends Horde_Core_Factory_Base
24: {
25: /**
26: * The class to use for attachment storage.
27: *
28: * @var string
29: */
30: public $classAtc = 'IMP_Compose_Attachment_Storage_Temp';
31:
32: /**
33: * The class to use for linked storage.
34: *
35: * @var string
36: */
37: public $classLinked = 'IMP_Compose_Attachment_Storage_VfsLinked';
38:
39: /**
40: * Instances.
41: *
42: * @var array
43: */
44: private $_instances = array();
45:
46: /**
47: * Return the requested attachment storage instance.
48: *
49: * @param string $user User.
50: * @param string $id Attachment identifier.
51: * @param string $type Either 'atc' or 'linked'. If null, will
52: * auto-determine.
53: *
54: * @return IMP_Compose_Attachment_Storage Storage object.
55: * @throws IMP_Exception
56: */
57: public function create($user = null, $id = null, $type = null)
58: {
59: global $conf;
60:
61: if (($type == 'linked') ||
62: (is_null($type) && !empty($conf['compose']['link_attachments']))) {
63: $classname = empty($conf['compose']['link_attach_threshold'])
64: ? $this->classLinked
65: : 'IMP_Compose_Attachment_Storage_AutoDetermine';
66: } else {
67: $classname = $this->classAtc;
68: }
69:
70: if (is_null($user)) {
71: $user = $GLOBALS['registry']->getAuth();
72: }
73:
74: if (is_null($id)) {
75: return new $classname($user);
76: }
77:
78: $sig = hash(
79: (PHP_MINOR_VERSION >= 4) ? 'fnv132' : 'sha1',
80: implode('|', array($user, $id))
81: );
82:
83: if (!isset($this->_instances[$sig])) {
84: $this->_instances[$sig] = new $classname($user, $id);
85: }
86:
87: return $this->_instances[$sig];
88: }
89:
90: }
91: