From 1065ab77abdfe7b025e24dab33a2db9cbbea90ac Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Mon, 24 May 2010 14:28:49 -0400 Subject: [PATCH] Use a factory for Vfs. Need to be able to specify different vfs scopes, can't assume we always want Horde's --- agora/lib/Agora.php | 2 +- ansel/scripts/garbage_collection.php | 2 +- framework/Core/lib/Horde.php | 4 +- framework/Core/lib/Horde/Core/Binder/Vfs.php | 5 +- framework/Core/lib/Horde/Core/Factory/Vfs.php | 54 ++++++++++++++++++++++ framework/Core/package.xml | 2 + framework/Scheduler/lib/Horde/Scheduler.php | 2 +- horde/services/images/view.php | 2 +- hylax/lib/Storage.php | 2 +- imp/attachment.php | 2 +- imp/lib/Compose.php | 12 ++--- .../LoginTasks/SystemTask/GarbageCollection.php | 2 +- .../LoginTasks/Task/DeleteAttachmentsMonthly.php | 2 +- whups/lib/Driver/sql.php | 2 +- whups/lib/Ticket.php | 4 +- whups/lib/Whups.php | 2 +- wicked/lib/Driver.php | 2 +- 17 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 framework/Core/lib/Horde/Core/Factory/Vfs.php diff --git a/agora/lib/Agora.php b/agora/lib/Agora.php index 6170288e9..4de487e82 100644 --- a/agora/lib/Agora.php +++ b/agora/lib/Agora.php @@ -227,7 +227,7 @@ class Agora { } try { - return $GLOBALS['injector']->getInstance('Horde_Vfs'); + return $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); } catch (VFS_Exception $e) { return PEAR::raiseError($e); } diff --git a/ansel/scripts/garbage_collection.php b/ansel/scripts/garbage_collection.php index 9e4e7aa96..75cea26f2 100755 --- a/ansel/scripts/garbage_collection.php +++ b/ansel/scripts/garbage_collection.php @@ -36,7 +36,7 @@ foreach ($opts as $opt) { } } -$vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); +$vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); $vfspath = '.horde/ansel/'; $garbagepath = $vfspath . 'garbage/'; diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 17fb312d7..c3a75de9d 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -831,11 +831,11 @@ HTML; { global $conf; - if (!isset($conf[$name]['type'])) { + if ($name !== 'horde' && !isset($conf[$name]['type'])) { throw new Horde_Exception(_("You must configure a VFS backend.")); } - $vfs = ($conf[$name]['type'] == 'horde') + $vfs = ($name == 'horde' || $conf[$name]['type'] == 'horde') ? $conf['vfs'] : $conf[$name]; diff --git a/framework/Core/lib/Horde/Core/Binder/Vfs.php b/framework/Core/lib/Horde/Core/Binder/Vfs.php index 724125ce9..0da26b74d 100644 --- a/framework/Core/lib/Horde/Core/Binder/Vfs.php +++ b/framework/Core/lib/Horde/Core/Binder/Vfs.php @@ -7,10 +7,7 @@ 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; + return new Horde_Core_Factory_Vfs($injector); } public function equals(Horde_Injector_Binder $binder) diff --git a/framework/Core/lib/Horde/Core/Factory/Vfs.php b/framework/Core/lib/Horde/Core/Factory/Vfs.php new file mode 100644 index 000000000..134c59b01 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Factory/Vfs.php @@ -0,0 +1,54 @@ + + */ + +/** + * A Horde_Injector:: based Horde_Vfs:: factory. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Core + * @author Michael J. Rubinsky + */ +class Horde_Core_Factory_Vfs +{ + /** + * The injector. + * + * @var Horde_Injector + */ + private $_injector; + + /** + * Constructor. + * + * @param Horde_Injector $injector The injector to use. + */ + public function __construct(Horde_Injector $injector) + { + $this->_injector = $injector; + } + + /** + * Obtain the Vfs instance. + * + * @param string $scope The vfs scope to return. + * + * @return VFS The VFS object + */ + public function getVfs($scope) + { + $params = Horde::getVFSConfig($scope); + return VFS::singleton($params['type'], $params['params']); + } + +} \ No newline at end of file diff --git a/framework/Core/package.xml b/framework/Core/package.xml index 1e2550173..e014fa0df 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -101,6 +101,7 @@ Application Framework. + @@ -274,6 +275,7 @@ Application Framework. + diff --git a/framework/Scheduler/lib/Horde/Scheduler.php b/framework/Scheduler/lib/Horde/Scheduler.php index 68330ffb6..57dc0d32c 100644 --- a/framework/Scheduler/lib/Horde/Scheduler.php +++ b/framework/Scheduler/lib/Horde/Scheduler.php @@ -82,7 +82,7 @@ class Horde_Scheduler public function serialize($id = '') { try { - $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); $vfs->writeData('.horde/scheduler', Horde_String::lower(get_class($this)) . $id, serialize($this), true); return true; } catch (VFS_Exception $e) { diff --git a/horde/services/images/view.php b/horde/services/images/view.php index e531c61d2..c0a9b04ce 100644 --- a/horde/services/images/view.php +++ b/horde/services/images/view.php @@ -34,7 +34,7 @@ case 'vfs': /* Getting a file from Horde's VFS. */ $path = Horde_Util::getFormData('p'); try { - $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); $file_data = $vfs->read($path, $file); } catch (VFS_Exception $e) { Horde::logMessage(sprintf('Error displaying image [%s]: %s', $path . '/' . $file, $e->getMessage()), 'ERR'); diff --git a/hylax/lib/Storage.php b/hylax/lib/Storage.php index da5985359..7d9ff7e03 100644 --- a/hylax/lib/Storage.php +++ b/hylax/lib/Storage.php @@ -39,7 +39,7 @@ class Hylax_Storage { Horde::fatal(_("You must configure a VFS backend to use Hylax."), __FILE__, __LINE__); } - $this->_vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $this->_vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); } function saveFaxData($data, $type = '.ps') diff --git a/imp/attachment.php b/imp/attachment.php index cab118510..57033bc8b 100644 --- a/imp/attachment.php +++ b/imp/attachment.php @@ -36,7 +36,7 @@ if (is_null($mail_user) || is_null($time_stamp) || is_null($file_name)) { // Initialize the VFS. try { - $vfsroot = $injector->getInstance('Horde_Vfs'); + $vfsroot = $injector->getInstance('Horde_Vfs')->getVfs(); } catch (VFS_Exception $e) { throw new IMP_Exception(sprintf(_("Could not create the VFS backend: %s"), $e->getMessage())); } diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 7241b6cc9..991022ccc 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -1909,7 +1909,7 @@ class IMP_Compose /* Store in VFS. */ if ($GLOBALS['conf']['compose']['use_vfs']) { try { - $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); $cacheID = uniqid(mt_rand()); if ($vfs_file) { @@ -1968,7 +1968,7 @@ class IMP_Compose case 'vfs': /* Delete from VFS. */ try { - $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); $vfs->deleteFile(self::VFS_ATTACH_PATH, $atc['filename']); } catch (VFS_Exception $e) {} break; @@ -2062,7 +2062,7 @@ class IMP_Compose case 'vfs': // TODO: Use streams try { - $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); $part->setContents($vfs->read(self::VFS_ATTACH_PATH, $this->_cache[$id]['filename'])); } catch (VFS_Exception $e) {} break; @@ -2345,7 +2345,7 @@ class IMP_Compose $baseurl = Horde::applicationUrl('attachment.php', true)->setRaw(true); try { - $GLOBALS['injector']->getInstance('Horde_Vfs'); + $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); } catch (VFS_Exception $e) { throw new IMP_Compose_Exception($e); } @@ -2645,7 +2645,7 @@ class IMP_Compose } try { - $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); $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.")); @@ -2664,7 +2664,7 @@ class IMP_Compose $filename = hash('md5', Horde_Auth::getAuth()); try { - $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); } catch (VFS_Exception $e) { return; } diff --git a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php index d71abc7a0..5168671f2 100644 --- a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php +++ b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php @@ -35,7 +35,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 = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); VFS_GC::gc($vfs, IMP_Compose::VFS_ATTACH_PATH, 86400); } catch (VFS_Exception $e) {} } diff --git a/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php b/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php index d6e4e7dd0..ffe6816e9 100644 --- a/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php +++ b/imp/lib/LoginTasks/Task/DeleteAttachmentsMonthly.php @@ -36,7 +36,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 = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); } catch (VFS_Exception $e) { return false; } diff --git a/whups/lib/Driver/sql.php b/whups/lib/Driver/sql.php index 5357257da..d43924a12 100644 --- a/whups/lib/Driver/sql.php +++ b/whups/lib/Driver/sql.php @@ -500,7 +500,7 @@ class Whups_Driver_sql extends Whups_Driver { if (!empty($GLOBALS['conf']['vfs']['type'])) { try { - $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); } catch (VFS_Exception $e) { return PEAR::raiseError($e->getMessage()); } diff --git a/whups/lib/Ticket.php b/whups/lib/Ticket.php index 0cdf29509..d159b5507 100644 --- a/whups/lib/Ticket.php +++ b/whups/lib/Ticket.php @@ -432,7 +432,7 @@ class Whups_Ticket { } try { - $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); } catch (VFS_Exception $e) { return PEAR::raiseError($e->getMessage()); } @@ -482,7 +482,7 @@ class Whups_Ticket { } try { - $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); } catch (VFS_Exception $e) { return PEAR::raiseError($e->getMessage()); } diff --git a/whups/lib/Whups.php b/whups/lib/Whups.php index 3ca93559f..15b52501e 100644 --- a/whups/lib/Whups.php +++ b/whups/lib/Whups.php @@ -788,7 +788,7 @@ class Whups { } try { - $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); } catch (VFS_Exception $e) { return PEAR::raiseError($vfs->getMessage()); } diff --git a/wicked/lib/Driver.php b/wicked/lib/Driver.php index a043379d8..30cbcb245 100644 --- a/wicked/lib/Driver.php +++ b/wicked/lib/Driver.php @@ -60,7 +60,7 @@ class Wicked_Driver { { if (!$this->_vfs) { try { - $this->_vfs = $GLOBALS['injector']->getInstance('Horde_Vfs'); + $this->_vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs(); } catch (VFS_Exception $e) { return PEAR::raiseError($e->getMessage()); } -- 2.11.0