Overview

Packages

  • Gollem
  • None

Classes

  • Gollem
  • Gollem_Ajax_Application
  • Gollem_Api
  • Gollem_Auth
  • Gollem_Exception
  • Gollem_Factory_Vfs
  • Gollem_Factory_VfsDefault
  • Gollem_LoginTasks_SystemTask_Upgrade
  • Gollem_Test
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * A Horde_Injector based Horde_Vfs factory.
 4:  *
 5:  * @author   Michael J. Rubinsky <mrubinsk@horde.org>
 6:  * @author   Jan Schneider <jan@horde.org>
 7:  * @category Horde
 8:  * @license  http://www.horde.org/licenses/gpl GPL
 9:  * @package  Gollem
10:  */
11: 
12: /**
13:  * A Horde_Injector based Horde_Vfs factory.
14:  *
15:  * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
16:  *
17:  * See the enclosed file COPYING for license information (GPL). If you
18:  * did not receive this file, see http://www.horde.org/licenses/gpl.
19:  *
20:  * @author   Michael J. Rubinsky <mrubinsk@horde.org>
21:  * @author   Jan Schneider <jan@horde.org>
22:  * @category Horde
23:  * @license  http://www.horde.org/licenses/gpl GPL
24:  * @package  Gollem
25:  */
26: class Gollem_Factory_Vfs extends Horde_Core_Factory_Base
27: {
28:     /**
29:      * Instances.
30:      *
31:      * @var array
32:      */
33:     private $_instances = array();
34: 
35:     /**
36:      * Returns the VFS instance.
37:      *
38:      * @param string $backend  The backend to return.
39:      *
40:      * @return Horde_Vfs  The VFS object.
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: 
API documentation generated by ApiGen