From 07cd4ab1cb2ca12cafe4dddcdf8896ba834fa266 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 24 May 2010 22:02:42 -0600 Subject: [PATCH] No need for VFS::singleton anymore --- framework/VFS/lib/VFS.php | 49 ++++----------------------------------- framework/VFS/lib/VFS/Object.php | 41 -------------------------------- framework/VFS/scripts/VFS/vfs.php | 6 ++--- 3 files changed, 8 insertions(+), 88 deletions(-) diff --git a/framework/VFS/lib/VFS.php b/framework/VFS/lib/VFS.php index a04b993db..6d07a75da 100644 --- a/framework/VFS/lib/VFS.php +++ b/framework/VFS/lib/VFS.php @@ -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.'); } /** diff --git a/framework/VFS/lib/VFS/Object.php b/framework/VFS/lib/VFS/Object.php index da25ffc3c..9d1dabfaf 100644 --- a/framework/VFS/lib/VFS/Object.php +++ b/framework/VFS/lib/VFS/Object.php @@ -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; diff --git a/framework/VFS/scripts/VFS/vfs.php b/framework/VFS/scripts/VFS/vfs.php index 87ad04c1e..1bce6b2b3 100644 --- a/framework/VFS/scripts/VFS/vfs.php +++ b/framework/VFS/scripts/VFS/vfs.php @@ -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); } /** -- 2.11.0