No need for VFS::singleton anymore
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 25 May 2010 04:02:42 +0000 (22:02 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 25 May 2010 04:02:42 +0000 (22:02 -0600)
framework/VFS/lib/VFS.php
framework/VFS/lib/VFS/Object.php
framework/VFS/scripts/VFS/vfs.php

index a04b993..6d07a75 100644 (file)
@@ -23,13 +23,6 @@ class VFS
     const QUOTA_METRIC_GB = 4;
 
     /**
-     * Singleton instances.
-     *
-     * @var array
-     */
-    static protected $_instances = array();
-
-    /**
      * Hash containing connection parameters.
      *
      * @var array
@@ -91,36 +84,6 @@ class VFS
     protected $_vfsSize = null;
 
     /**
-     * Attempts to return a reference to a concrete instance based on
-     * $driver. It will only create a new instance if no instance with the
-     * same parameters currently exists.
-     *
-     * This should be used if multiple types of file backends (and, thus,
-     * multiple VFS instances) are required.
-     *
-     * This method must be invoked as: $var = VFS::singleton();
-     *
-     * @param mixed $driver  The type of concrete subclass to return. This
-     *                       is based on the storage driver ($driver). The
-     *                       code is dynamically included.
-     * @param array $params  A hash containing any additional configuration or
-     *                       connection parameters a subclass might need.
-     *
-     * @return VFS  The concrete VFS reference.
-     * @throws VFS_Exception
-     */
-    static public function singleton($driver, $params = array())
-    {
-        ksort($params);
-        $signature = serialize(array($driver, $params));
-        if (!isset(self::$_instances[$signature])) {
-            self::$_instances[$signature] = self::factory($driver, $params);
-        }
-
-        return self::$_instances[$signature];
-    }
-
-    /**
      * Attempts to return a concrete instance based on $driver.
      *
      * @param mixed $driver  The type of concrete subclass to return. This
@@ -134,16 +97,14 @@ class VFS
      */
     static public function factory($driver, $params = array())
     {
-        $driver = basename($driver);
+        $driver = basename(ucfirst($driver));
         $class = __CLASS__ . '_' . $driver;
-        if (!class_exists($class)) {
-            include_once 'VFS/' . $driver . '.php';
-            if (!class_exists($class)) {
-                throw new VFS_Exception('Class definition of ' . $class . ' not found.');
-            }
+
+        if (class_exists($class)) {
+            return new $class($params);
         }
 
-        return new $class($params);
+        throw new VFS_Exception('Class definition of ' . $class . ' not found.');
     }
 
     /**
index da25ffc..9d1dabf 100644 (file)
@@ -36,45 +36,6 @@ class VFS_Object
     protected $_folderList;
 
     /**
-     * Attempts to return a reference to a concrete instance
-     * based on $driver. It will only create a new instance if no
-     * VFS instance with the same parameters currently exists.
-     *
-     * This should be used if multiple types of file backends (and,
-     * thus, multiple VFS instances) are required.
-     *
-     * This method must be invoked as: $var = VFS_Object::singleton();
-     *
-     * @param mixed $driver  The type of concrete subclass to return.
-     * @param array $params  A hash containing any additional configuration or
-     *                       connection parameters a subclass might need.
-     *
-     * @return VFS_Object  The concrete VFS_Object reference.
-     * @throws VFS_Exception
-     */
-    static public function singleton($driver, $params = array())
-    {
-        require_once dirname(__FILE__) . '/../VFS.php';
-        $classname = __CLASS__;
-        return new $classname(VFS::singleton($driver, $params = array()));
-    }
-
-    /**
-     * Attempts to return a concrete instance based on $driver.
-     *
-     * @param mixed $driver  The type of concrete subclass to return.
-     * @param array $params  A hash containing any additional configuration or
-     *                       connection parameters a subclass might need.
-     *
-     * @return VFS_Object  The newly created concrete VFS_Object instance.
-     * @throws VFS_Exception
-     */
-    static public function factory($driver, $params = array())
-    {
-        return self::singleton($driver, $params);
-    }
-
-    /**
      * Constructor.
      *
      * If you pass in an existing VFS object, it will be used as the VFS
@@ -223,12 +184,10 @@ class VFS_Object
                 $this->_folderList = $folderList;
                 $this->_currentPath = $path;
             } else {
-                require_once dirname(__FILE__) . '/Exception.php';
                 throw new VFS_Exception('Could not read ' . $path . '.');
             }
         }
 
-        require_once dirname(__FILE__) . '/ListItem.php';
         return ($file = array_shift($this->_folderList))
             ? new VFS_ListItem($path, $file)
             : false;
index 87ad04c..1bce6b2 100644 (file)
@@ -152,8 +152,8 @@ function cp($source, $target, $argv, $filter)
         // TODO: Shortcut with VFS::copy()
     }
 
-    $source_vfs = &vfs($source_params);
-    $target_vfs = &vfs($target_params);
+    $source_vfs = vfs($source_params);
+    $target_vfs = vfs($target_params);
 
     _cp($source_vfs, $target_vfs, $source_path, $target_path, $argv, $filter);
 }
@@ -294,7 +294,7 @@ USAGE;
  */
 function vfs($params)
 {
-    return VFS::singleton($params['driver'], $params);
+    return VFS::factory($params['driver'], $params);
 }
 
 /**