1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26: class Gollem_Factory_Vfs extends Horde_Core_Factory_Base
27: {
28: 29: 30: 31: 32:
33: private $_instances = array();
34:
35: 36: 37: 38: 39: 40: 41:
42: public function create($backend)
43: {
44: if (empty($this->_instances[$backend])) {
45: $be_config = Gollem_Auth::getBackend($backend);
46: $params = $be_config['params'];
47:
48: if (!empty($params['password'])) {
49: $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
50: $params['password'] = $secret->read($secret->getKey('gollem'), $params['password']);
51: }
52:
53: switch (Horde_String::lower($be_config['driver'])) {
54: case 'sql':
55: case 'sqlfile':
56: case 'musql':
57: $db_params = $params;
58: unset($db_params['table']);
59: $params['db'] = $this->_injector
60: ->getInstance('Horde_Core_Factory_Db')
61: ->create('gollem', $db_params);
62: break;
63: }
64:
65: $vfs = Horde_Vfs::factory($be_config['driver'], $params);
66:
67: if (!empty($be_config['quota'])) {
68: $quotaroot = $be_config['root'] == '/' ? '' : $be_config['root'];
69: if (isset($be_config['quota_val'])) {
70: $vfs->setQuota($be_config['quota_val'], $be_config['quota_metric']);
71: $vfs->setQuotaRoot($quotaroot);
72: } else {
73: $quota_metric = array(
74: 'B' => Horde_Vfs::QUOTA_METRIC_BYTE,
75: 'KB' => Horde_Vfs::QUOTA_METRIC_KB,
76: 'MB' => Horde_Vfs::QUOTA_METRIC_MB,
77: 'GB' => Horde_Vfs::QUOTA_METRIC_GB
78: );
79: $quota_str = explode(' ', $be_config['quota'], 2);
80: if (is_numeric($quota_str[0])) {
81: $metric = trim(Horde_String::upper($quota_str[1]));
82: if (!isset($quota_metric[$metric])) {
83: $metric = 'B';
84: }
85: $vfs->setQuota($quota_str[0], $quota_metric[$metric]);
86: $vfs->setQuotaRoot($quotaroot);
87: $be_config['quota_val'] = $quota_str[0];
88: $be_config['quota_metric'] = $quota_metric[$metric];
89: }
90: }
91: }
92:
93: $this->_instances[$backend] = $vfs;
94: }
95:
96: return $this->_instances[$backend];
97: }
98: }
99: