1: <?php
2: 3: 4: 5: 6: 7: 8:
9:
10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22: class Horde_Core_Factory_ShareBase extends Horde_Core_Factory_Base
23: {
24: 25: 26: 27: 28:
29: protected $_instances = array();
30:
31: 32: 33: 34: 35: 36: 37: 38: 39: 40:
41: public function create($app = null, $driver = null)
42: {
43: if (empty($driver)) {
44: $driver = $GLOBALS['conf']['share']['driver'];
45: }
46: if (empty($app)) {
47: $app = $this->_injector->getInstance('Horde_Registry')->getApp();
48: }
49:
50: $sig = $app . '_' . $driver;
51: if (isset($this->_instances[$sig])) {
52: return $this->_instances[$sig];
53: }
54:
55: $class = 'Horde_Share_' . ucfirst(basename($driver));
56: if (!class_exists($class)) {
57: throw new Horde_Exception(sprintf(Horde_Core_Translation::t("\"%s\" share driver not found."), $driver));
58: }
59:
60: $ob = new $class($app, $GLOBALS['registry']->getAuth(), $this->_injector->getInstance('Horde_Perms'), $this->_injector->getInstance('Horde_Group'));
61: $cb = new Horde_Core_Share_FactoryCallback($app, $driver);
62: $ob->setShareCallback(array($cb, 'create'));
63: $ob->setLogger($this->_injector->getInstance('Horde_Log_Logger'));
64: if (!empty($GLOBALS['conf']['share']['cache'])) {
65: $cache_sig = 'horde_share/' . $app . '/' . $driver;
66: $listCache = $GLOBALS['session']->retrieve($cache_sig);
67: $ob->setListCache($listCache);
68: register_shutdown_function(array($this, 'shutdown'), $cache_sig, $ob);
69: }
70:
71: $this->_instances[$sig] = $ob;
72:
73: return $ob;
74: }
75:
76: 77: 78: 79: 80: 81:
82: public function shutdown($sig, $share)
83: {
84: $GLOBALS['session']->store($share->getListCache(), false, $sig);
85: }
86:
87: }
88: