Use global injector binder to get VFS object using Horde vfs config
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 17 Mar 2010 22:36:54 +0000 (16:36 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 17 Mar 2010 22:39:02 +0000 (16:39 -0600)
16 files changed:
agora/lib/Agora.php
ansel/scripts/garbage_collection.php
framework/Core/lib/Horde/Core/Binder/Vfs.php [new file with mode: 0644]
framework/Core/lib/Horde/Registry.php
framework/Core/package.xml
framework/Scheduler/lib/Horde/Scheduler.php
horde/services/images/view.php
hylax/lib/Storage.php
imp/attachment.php
imp/lib/Compose.php
imp/lib/LoginTasks/SystemTask/GarbageCollection.php
imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php
whups/lib/Driver/sql.php
whups/lib/Ticket.php
whups/lib/Whups.php
wicked/lib/Driver.php

index 6c42b15..6170288 100644 (file)
@@ -227,7 +227,7 @@ class Agora {
         }
 
         try {
-            return VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
+            return $GLOBALS['injector']->getInstance('Horde_Vfs');
         } catch (VFS_Exception $e) {
             return PEAR::raiseError($e);
         }
index 59d4d9b..94a9418 100755 (executable)
@@ -36,7 +36,7 @@ foreach ($opts as $opt) {
     }
 }
 
-$vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
+$vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
 $vfspath = '.horde/ansel/';
 $garbagepath = $vfspath . 'garbage/';
 
diff --git a/framework/Core/lib/Horde/Core/Binder/Vfs.php b/framework/Core/lib/Horde/Core/Binder/Vfs.php
new file mode 100644 (file)
index 0000000..fab9401
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+class Horde_Core_Binder_Vfs implements Horde_Injector_Binder
+{
+    public function create(Horde_Injector $injector)
+    {
+        $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
+        $vfs->setLogger($injector->getInstance('Horde_Log_Logger'));
+
+        return $vfs;
+    }
+
+    public function equals(Horde_Injector_Binder $binder)
+    {
+        return false;
+    }
+}
index bb56192..b5e6d42 100644 (file)
@@ -241,6 +241,7 @@ class Horde_Registry
             'Horde_Notification' => new Horde_Core_Binder_Notification(),
             'Horde_Perms' => new Horde_Core_Binder_Perms(),
             'Horde_Template' => new Horde_Core_Binder_Template(),
+            'Horde_Vfs' => new Horde_Core_Binder_Vfs(),
             'Net_DNS_Resolver' => new Horde_Core_Binder_Dns()
         );
 
index 2412cfb..c706220 100644 (file)
@@ -72,6 +72,7 @@ Application Framework.
        <file name="Notification.php" role="php" />
        <file name="Perms.php" role="php" />
        <file name="Template.php" role="php" />
+       <file name="Vfs.php" role="php" />
       </dir> <!-- /lib/Horde/Core/Binder -->
       <dir name="Factory">
        <file name="KolabServer.php" role="php" />
@@ -199,6 +200,7 @@ Application Framework.
    <install name="lib/Horde/Core/Binder/Notification.php" as="Horde/Core/Binder/Notification.php" />
    <install name="lib/Horde/Core/Binder/Perms.php" as="Horde/Core/Binder/Perms.php" />
    <install name="lib/Horde/Core/Binder/Template.php" as="Horde/Core/Binder/Template.php" />
+   <install name="lib/Horde/Core/Binder/Vfs.php" as="Horde/Core/Binder/Vfs.php" />
    <install name="lib/Horde/Core/Factory/KolabServer.php" as="Horde/Core/Factory/KolabServer.php" />
    <install name="lib/Horde/Core/Factory/KolabSession.php" as="Horde/Core/Factory/KolabSession.php" />
    <install name="lib/Horde/Core/Log/Logger.php" as="Horde/Core/Log/Logger.php" />
index 5ef91e9..68330ff 100644 (file)
@@ -82,8 +82,7 @@ class Horde_Scheduler
     public function serialize($id = '')
     {
         try {
-            $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'],
-                                  Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
+            $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
             $vfs->writeData('.horde/scheduler', Horde_String::lower(get_class($this)) . $id, serialize($this), true);
             return true;
         } catch (VFS_Exception $e) {
@@ -112,8 +111,7 @@ class Horde_Scheduler
         $scheduler = new $class;
 
         try {
-            $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'],
-                              Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
+            $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
             $data = $vfs->read('.horde/scheduler', $class . $id);
             if ($tmp = @unserialize($data)) {
                 $scheduler = $tmp;
index 7a107a7..e531c61 100644 (file)
@@ -34,7 +34,7 @@ case 'vfs':
     /* Getting a file from Horde's VFS. */
     $path = Horde_Util::getFormData('p');
     try {
-        $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
+        $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
         $file_data = $vfs->read($path, $file);
     } catch (VFS_Exception $e) {
         Horde::logMessage(sprintf('Error displaying image [%s]: %s', $path . '/' . $file, $e->getMessage()), 'ERR');
index b879bb2..da59853 100644 (file)
@@ -32,17 +32,14 @@ class Hylax_Storage {
      */
     function Hylax_Storage($params)
     {
-        global $conf;
-
         $this->_params = $params;
 
         /* Set up the VFS storage. */
-        if (!isset($conf['vfs']['type'])) {
+        if (!isset($GLOBALS['conf']['vfs']['type'])) {
             Horde::fatal(_("You must configure a VFS backend to use Hylax."), __FILE__, __LINE__);
         }
-        $vfs_driver = $conf['vfs']['type'];
-        $vfs_params = Horde::getDriverConfig('vfs', $vfs_driver);
-        $this->_vfs = VFS::singleton($vfs_driver, $vfs_params);
+
+        $this->_vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
     }
 
     function saveFaxData($data, $type = '.ps')
index f9fea88..767f8d4 100644 (file)
@@ -34,7 +34,7 @@ if (is_null($mail_user) || is_null($time_stamp) || is_null($file_name)) {
 
 // Initialize the VFS.
 try {
-    $vfsroot = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
+    $vfsroot = $injector->getInstance('Horde_Vfs');
 } catch (VFS_Exception $e) {
     throw new IMP_Exception(sprintf(_("Could not create the VFS backend: %s"), $e->getMessage()));
 }
index 6e7aaaf..81f5adc 100644 (file)
@@ -1882,14 +1882,12 @@ class IMP_Compose
      */
     protected function _storeAttachment($part, $data, $vfs_file = true)
     {
-        global $conf;
-
         /* Store in VFS. */
-        if ($conf['compose']['use_vfs']) {
-            $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
-            $cacheID = uniqid(mt_rand());
-
+        if ($GLOBALS['conf']['compose']['use_vfs']) {
             try {
+                $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
+                $cacheID = uniqid(mt_rand());
+
                 if ($vfs_file) {
                     $vfs->write(self::VFS_ATTACH_PATH, $cacheID, $data, true);
                 } else {
@@ -1945,8 +1943,10 @@ class IMP_Compose
             switch ($atc['filetype']) {
             case 'vfs':
                 /* Delete from VFS. */
-                $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
-                $vfs->deleteFile(self::VFS_ATTACH_PATH, $atc['filename']);
+                try {
+                    $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
+                    $vfs->deleteFile(self::VFS_ATTACH_PATH, $atc['filename']);
+                } catch (VFS_Exception $e) {}
                 break;
 
             case 'file':
@@ -2037,8 +2037,10 @@ class IMP_Compose
         switch ($this->_cache[$id]['filetype']) {
         case 'vfs':
             // TODO: Use streams
-            $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
-            $part->setContents($vfs->read(self::VFS_ATTACH_PATH, $this->_cache[$id]['filename']));
+            try {
+                $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
+                $part->setContents($vfs->read(self::VFS_ATTACH_PATH, $this->_cache[$id]['filename']));
+            } catch (VFS_Exception $e) {}
             break;
 
         case 'file':
@@ -2318,7 +2320,11 @@ class IMP_Compose
         $auth = Horde_Auth::getAuth();
         $baseurl = Horde::applicationUrl('attachment.php', true)->setRaw(true);
 
-        $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
+        try {
+            $GLOBALS['injector']->getInstance('Horde_Vfs');
+        } catch (VFS_Exception $e) {
+            throw new IMP_Compose_Exception($e);
+        }
 
         $ts = time();
         $fullpath = sprintf('%s/%s/%d', self::VFS_LINK_ATTACH_PATH, $auth, $ts);
@@ -2615,7 +2621,7 @@ class IMP_Compose
         }
 
         try {
-            $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
+            $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
             $vfs->writeData(self::VFS_DRAFTS_PATH, hash('md5', Horde_Util::getFormData('user')), $body, true);
 
             $GLOBALS['notification']->push(_("The message you were composing has been saved as a draft. The next time you login, you may resume composing your message."));
@@ -2632,7 +2638,13 @@ class IMP_Compose
         }
 
         $filename = hash('md5', Horde_Auth::getAuth());
-        $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
+
+        try {
+            $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
+        } catch (VFS_Exception $e) {
+            return;
+        }
+
         if ($vfs->exists(self::VFS_DRAFTS_PATH, $filename)) {
             try {
                 $data = $vfs->read(self::VFS_DRAFTS_PATH, $filename);
index 20e8fa1..45a81de 100644 (file)
@@ -34,7 +34,7 @@ class IMP_LoginTasks_SystemTask_GarbageCollection extends Horde_LoginTasks_Syste
         /* Do garbage collection on compose VFS data. */
         if ($GLOBALS['conf']['compose']['use_vfs']) {
             try {
-                $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
+                $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
                 VFS_GC::gc($vfs, IMP_Compose::VFS_ATTACH_PATH, 86400);
             } catch (VFS_Exception $e) {}
         }
index dbd4cda..395891b 100644 (file)
@@ -34,7 +34,7 @@ class IMP_LoginTasks_Task_DeleteAttachmentsMonthly extends Horde_LoginTasks_Task
         $del_time = gmmktime(0, 0, 0, date('n') - $GLOBALS['prefs']->getValue('delete_attachments_monthly_keep'), 1, date('Y'));
 
         try {
-            $vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'], Horde::getDriverConfig('vfs', $GLOBALS['conf']['vfs']['type']));
+            $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
         } catch (VFS_Exception $e) {
             return false;
         }
index bb2cef9..3fca21e 100644 (file)
@@ -490,8 +490,6 @@ class Whups_Driver_sql extends Whups_Driver {
 
     function deleteTicket($info)
     {
-        global $conf;
-
         $id = (int)$info['id'];
 
         $tables = array('whups_ticket_listeners',
@@ -500,9 +498,9 @@ class Whups_Driver_sql extends Whups_Driver {
                         'whups_tickets',
                         'whups_attributes');
 
-        if (!empty($conf['vfs']['type'])) {
+        if (!empty($GLOBALS['conf']['vfs']['type'])) {
             try {
-                $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
+                $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
             } catch (VFS_Exception $e) {
                 return PEAR::raiseError($e->getMessage());
             }
index 05da3ea..98a8daf 100644 (file)
@@ -427,14 +427,12 @@ class Whups_Ticket {
      */
     function addAttachment(&$attachment_name, $attachment_file)
     {
-        global $conf;
-
-        if (!isset($conf['vfs']['type'])) {
+        if (!isset($GLOBALS['conf']['vfs']['type'])) {
             return PEAR::raiseError(_("The VFS backend needs to be configured to enable attachment uploads."), 'horde.error');
         }
 
         try {
-            $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
+            $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
         } catch (VFS_Exception $e) {
             return PEAR::raiseError($e->getMessage());
         }
@@ -479,14 +477,12 @@ class Whups_Ticket {
      */
     function deleteAttachment($attachment_name)
     {
-        global $conf;
-
-        if (!isset($conf['vfs']['type'])) {
+        if (!isset($GLOBALS['conf']['vfs']['type'])) {
             return PEAR::raiseError(_("The VFS backend needs to be configured to enable attachment uploads."), 'horde.error');
         }
 
         try {
-            $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
+            $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
         } catch (VFS_Exception $e) {
             return PEAR::raiseError($e->getMessage());
         }
index dda1212..1e35641 100644 (file)
@@ -783,14 +783,12 @@ class Whups {
      */
     function getAttachments($ticket, $name = null)
     {
-        global $conf;
-
-        if (empty($conf['vfs']['type'])) {
+        if (empty($GLOBALS['conf']['vfs']['type'])) {
             return false;
         }
 
         try {
-            $vfs = VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs'));
+            $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
         } catch (VFS_Exception $e) {
             return PEAR::raiseError($vfs->getMessage());
         }
index bb30435..a043379 100644 (file)
@@ -60,8 +60,7 @@ class Wicked_Driver {
     {
         if (!$this->_vfs) {
             try {
-                $this->_vfs = VFS::singleton($GLOBALS['conf']['vfs']['type'],
-                                             Horde::getDriverConfig('vfs'));
+                $this->_vfs = $GLOBALS['injector']->getInstance('Horde_Vfs');
             } catch (VFS_Exception $e) {
                 return PEAR::raiseError($e->getMessage());
             }