use the injector
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 24 May 2010 18:47:08 +0000 (14:47 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 24 May 2010 18:47:08 +0000 (14:47 -0400)
ansel/lib/Ansel.php
ansel/lib/Application.php
folks/lib/Driver.php
news/lib/News.php
turba/lib/Object.php
turba/view.php

index 51348f2..c222495 100644 (file)
@@ -55,19 +55,6 @@ class Ansel
     }
 
     /**
-     * Create and initialize the VFS object
-     *
-     * @return  VFS object.
-     */
-    static public function getVFS()
-    {
-        // @TODO: need to refactor the Vfs binder to a factory so we can handle
-        // vfs objects for different scopes.
-        $v_params = Horde::getVFSConfig('images');
-        return VFS::singleton($v_params['type'], $v_params['params']);
-    }
-
-    /**
      * Return a string containing an <option> listing of the given
      * gallery array.
      *
index b5f6028..932dd56 100644 (file)
@@ -69,7 +69,7 @@ class Ansel_Application extends Horde_Registry_Application
         // Create db, share, and vfs instances.
         $GLOBALS['ansel_db'] = Ansel::getDb();
         $GLOBALS['ansel_storage'] = new Ansel_Storage();
-        $GLOBALS['ansel_vfs'] = Ansel::getVFS();
+        $GLOBALS['ansel_vfs'] = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images');
 
         // Get list of available styles for this client.
         $GLOBALS['ansel_styles'] = Ansel::getAvailableStyles();
index babe102..4f6808c 100644 (file)
@@ -61,21 +61,6 @@ class Folks_Driver {
     }
 
     /**
-     * Load VFS Backend
-     *
-     * @throws Horde_Exception
-     */
-    protected function _loadVFS()
-    {
-        $v_params = Horde::getVFSConfig('images');
-        try {
-            return VFS::singleton($v_params['type'], $v_params['params']);
-        } catch (VFS_Exception $e) {
-            return PEAR::raiseError($e->getMessage());
-        }
-    }
-
-    /**
      * Store image
      *
      * @param string $file   Image file
@@ -85,12 +70,7 @@ class Folks_Driver {
     {
         global $conf;
 
-        try {
-        $vfs = $this->_loadVFS();
-        if ($vfs instanceof PEAR_Error) {
-            return $vfs;
-        }
-
+        $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images');
         $p = hash('md5', $user);
         $vfspath = Folks::VFS_PATH . '/' . substr(str_pad($p, 2, 0, STR_PAD_LEFT), -2) . '/';
         $vfs_name = $p . '.' . $conf['images']['image_type'];
@@ -138,11 +118,7 @@ class Folks_Driver {
      */
     public function deleteImage($user)
     {
-        $vfs = $this->_loadVFS();
-        if ($vfs instanceof PEAR_Error) {
-            return $vfs;
-        }
-
+        $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images');
         $p = hash('md5', $user);
         $vfspath = Folks::VFS_PATH . '/' . substr(str_pad($p, 2, 0, STR_PAD_LEFT), -2) . '/';
         $vfs_name = $p . '.' . $GLOBALS['conf']['images']['image_type'];
index 0a23140..e643734 100644 (file)
@@ -225,24 +225,6 @@ class News {
     }
 
     /**
-     * Load VFS Backend
-     *
-     * @throws Horde_Exception
-     * @throws VFS_Exception
-     */
-    static public function loadVFS()
-    {
-        static $vfs;
-
-        if ($vfs) {
-            return $vfs;
-        }
-
-        $v_params = Horde::getVFSConfig('images');
-        return VFS::singleton($v_params['type'], $v_params['params']);
-    }
-
-    /**
      * Store image
      *
      * @param $id     Image owner record id
@@ -254,7 +236,7 @@ class News {
     {
         global $conf;
 
-        $vfs = self::loadVFS();
+        $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images');
         $vfspath = self::VFS_PATH . '/images/' . $type;
         $vfs_name = $id . '.' . $conf['images']['image_type'];
 
@@ -317,7 +299,7 @@ class News {
      */
     static public function deleteImage($id)
     {
-        $vfs = self::loadVFS();
+        $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images');
         $vfs_name = $id . '.' . $GLOBALS['conf']['images']['image_type'];
         $vfs->deleteFile(self::VFS_PATH . '/images/news/full', $vfs_name);
         $vfs->deleteFile(self::VFS_PATH . '/images/news/small', $vfs_name);
@@ -332,7 +314,7 @@ class News {
      */
     static public function saveFile($file_id, $file_src)
     {
-        $vfs = self::loadVFS();
+        $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images');
         $vfs->writeData(self::VFS_PATH . '/files/', $file_id, file_get_contents($file_src), true);
     }
 
@@ -343,7 +325,7 @@ class News {
      */
     static public function getFile($file_id)
     {
-        $vfs = self::loadVFS();
+        $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images');
         $vfs->read(self::VFS_PATH . '/files/', $file_id);
     }
 
@@ -354,7 +336,7 @@ class News {
      */
     static public function deleteFile($file_id)
     {
-        $vfs = self::loadVFS();
+        $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('images');
         if ($vfs->exists(self::VFS_PATH . '/files/', $file_id)) {
             $vfs->deleteFile(self::VFS_PATH . '/files/', $file_id);
         }
index 943015c..2dfb378 100644 (file)
@@ -312,7 +312,7 @@ class Turba_Object {
             if ($this->_vfs->exists(TURBA_VFS_PATH, $this->getValue('__uid'))) {
                 return $this->_vfs->listFolder(TURBA_VFS_PATH . '/' . $this->getValue('__uid'));
             }
-        } catch (VFS_Exception $e) {}
+        } catch (Turba_Exception $e) {}
 
         return array();
     }
@@ -396,16 +396,10 @@ class Turba_Object {
     {
         if (!isset($this->_vfs)) {
             try {
-                $v_params = Horde::getVFSConfig('documents');
+                $this->_vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('documents');
             } catch (Horde_Exception $e) {
                 throw new Turba_Exception($e);
             }
-
-            try {
-                $this->_vfs = VFS::singleton($v_params['type'], $v_params['params']);
-            } catch (VFS_Exception $e) {
-                throw new Turba_Exception($e);
-            }
         }
     }
 
index b9bf53d..3232150 100644 (file)
@@ -39,15 +39,10 @@ if (!$object->hasPermission(Horde_Perms::READ)) {
 }
 
 try {
-    $v_params = Horde::getVFSConfig('documents');
+    $vfs = $GLOBALS['injector']->getInstance('Horde_Vfs')->getVfs('documents');
 } catch (Horde_Exception $e) {
     throw new Turba_Exception($e);
 }
-try {
-    $vfs = VFS::singleton($v_params['type'], $v_params['params']);
-} catch (VFS_Exception $e) {
-    throw new Turba_Exception($e);
-}
 
 try {
     $data = $vfs->read(TURBA_VFS_PATH . '/' . $object->getValue('__uid'), $filename);