A scheme is not allowed to contain an underscore, but allows a dot and a

class names only allow or need underscores, but no dots
--> we replace dots in scheme with underscored to get the class-name
This commit is contained in:
Ralf Becker 2009-04-01 14:08:20 +00:00
parent 039cf26d22
commit b1f0863d81
2 changed files with 24 additions and 19 deletions

View File

@ -349,14 +349,6 @@ switch($cmd)
if (($scheme = parse_url($url,PHP_URL_SCHEME)))
{
load_wrapper($url);
if (class_exists($class = $scheme.'_stream_wrapper') && method_exists($class,'touch'))
{
$cmd = array($scheme.'_stream_wrapper',$cmd);
}
else
{
die("Can't $cmd for scheme $scheme!\n");
}
}
if ($recursive && class_exists('egw_vfs'))
{
@ -429,7 +421,7 @@ switch($cmd)
}
/**
* Load the necessary wrapper for an url
* Load the necessary wrapper for an url or die if it cant be loaded
*
* @param string $url
*/
@ -451,17 +443,16 @@ function load_wrapper($url)
{
load_egw(parse_url($url,PHP_URL_USER),parse_url($url,PHP_URL_PASS),parse_url($url,PHP_URL_HOST));
}
// as eGW might not be loaded, we have to require the class exlicit
@include_once(EGW_API_INC.'/class.'.$scheme.'_stream_wrapper.inc.php');
// get eGW's __autoload() function
include_once(EGW_API_INC.'/common_functions.inc.php');
if (!class_exists($scheme.'_stream_wrapper'))
if (!class_exists(str_replace('.','_',$scheme).'_stream_wrapper'))
{
die("Unknown scheme '$scheme' in $url !!!\n\n");
}
break;
}
}
//print_r(stream_get_wrappers());
}
/**

View File

@ -457,7 +457,7 @@ class vfs_stream_wrapper implements iface_stream_wrapper
{
if ($scheme)
{
if (!class_exists($class = $scheme.'_stream_wrapper') || !method_exists($class,$name))
if (!class_exists($class = self::scheme2class($scheme)) || !method_exists($class,$name))
{
if (!$fail_silent) trigger_error("Can't $name for scheme $scheme!\n",E_USER_WARNING);
return false;
@ -466,10 +466,10 @@ class vfs_stream_wrapper implements iface_stream_wrapper
{
$params[$path_param_key] = $url;
return call_user_func_array(array($scheme.'_stream_wrapper',$name),$params);
return call_user_func_array(array($class,$name),$params);
}
$params[$path_param_key] = $urls;
if (!is_array($r = call_user_func_array(array($scheme.'_stream_wrapper',$name),$params)))
if (!is_array($r = call_user_func_array(array($class,$name),$params)))
{
return $r;
}
@ -602,9 +602,9 @@ class vfs_stream_wrapper implements iface_stream_wrapper
if (!$mime && ($scheme = parse_url($url,PHP_URL_SCHEME)))
{
// check it it's an eGW stream wrapper returning mime-type via url_stat
if (class_exists($class = $scheme.'_stream_wrapper') && ($mime_attr = @constant($class.'::STAT_RETURN_MIME_TYPE')))
if (class_exists($class = self::scheme2class($scheme)) && ($mime_attr = @constant($class.'::STAT_RETURN_MIME_TYPE')))
{
$stat = call_user_func(array($scheme.'_stream_wrapper','url_stat'),parse_url($url,PHP_URL_PATH),0);
$stat = call_user_func(array($class,'url_stat'),parse_url($url,PHP_URL_PATH),0);
if ($stat[$mime_attr])
{
$mime = $stat[$mime_attr];
@ -965,7 +965,7 @@ class vfs_stream_wrapper implements iface_stream_wrapper
break; // default file, always loaded
default:
// check if scheme is buildin in php or one of our own stream wrappers
if (in_array($scheme,stream_get_wrappers()) || class_exists($scheme.'_stream_wrapper'))
if (in_array($scheme,stream_get_wrappers()) || class_exists(self::scheme2class($scheme)))
{
self::$wrappers[] = $scheme;
}
@ -993,6 +993,20 @@ class vfs_stream_wrapper implements iface_stream_wrapper
return self::$wrappers;
}
/**
* Get the class-name for a scheme
*
* A scheme is not allowed to contain an underscore, but allows a dot and a class names only allow or need underscores, but no dots
* --> we replace dots in scheme with underscored to get the class-name
*
* @param string $scheme eg. vfs
* @return string
*/
static function scheme2class($scheme)
{
return str_replace('.','_',$scheme).'_stream_wrapper';
}
static function init_static()
{
stream_register_wrapper(self::SCHEME,__CLASS__);