Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop' of https://github.com/pydio/pydio-core into de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
cdujeu committed Feb 25, 2016
2 parents 80e6f1f + bfc7704 commit 4f7feeb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 24 deletions.
67 changes: 48 additions & 19 deletions core/src/core/classes/class.AJXP_MetaStreamWrapper.php
Expand Up @@ -44,9 +44,11 @@ class AJXP_MetaStreamWrapper implements AjxpWrapper
*/
protected $currentDirPath;

protected static $metaWrappers = array(
"pydio" => "AJXP_MetaStreamWrapper"
);
protected static $metaWrappers = [
'core' => [
'pydio' => 'AJXP_MetaStreamWrapper'
]
];

protected static $cachedRepositoriesWrappers = array();

Expand All @@ -60,7 +62,8 @@ public static function register($registered_wrappers = null){
if($registered_wrappers == null){
$registered_wrappers = stream_get_wrappers();
}
foreach(self::$metaWrappers as $protocol => $className){
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator(self::$metaWrappers));
foreach($it as $protocol => $className){
if(!in_array($protocol, $registered_wrappers)){
stream_wrapper_register($protocol, $className);
}
Expand All @@ -72,14 +75,18 @@ public static function register($registered_wrappers = null){
* @param $name string
* @param $className string
*/
public static function appendMetaWrapper($name, $className){
self::$metaWrappers[$name] = $className;
public static function appendMetaWrapper($name, $className, $parent = "core"){
self::$metaWrappers[$parent][$name] = $className;
self::register();
}

protected static function getNextScheme($url){
protected static function getMetaWrappers($scheme) {
return array_merge((array) self::$metaWrappers['core'], (array) self::$metaWrappers[$scheme]);
}

protected static function getNextScheme($url, $context='core'){
$parts = parse_url($url);
$metaWrapperKeys = array_keys(self::$metaWrappers);
$metaWrapperKeys = array_keys(self::getMetaWrappers($context));
$key = array_search($parts["scheme"], $metaWrapperKeys);
if($key < count($metaWrapperKeys) - 1){
// Return next registered meta wrapper
Expand All @@ -98,8 +105,10 @@ protected static function getNextScheme($url){
* @throws Exception
*/
protected static function translateScheme($url, $crtInstance = null){
$currentScheme = parse_url($url, PHP_URL_SCHEME);
$newScheme = self::getNextScheme($url);
$parts=parse_url($url);
$currentScheme = $parts['scheme'];
$context = self::actualRepositoryWrapperProtocol($parts['host']);
$newScheme = self::getNextScheme($url, $context);
$repository = ConfService::getRepositoryById(parse_url($url, PHP_URL_HOST));
if($currentScheme == "pydio" && $repository->hasContentFilter()){
$baseDir = $repository->getContentFilter()->getBaseDir();
Expand All @@ -119,27 +128,33 @@ protected static function translateScheme($url, $crtInstance = null){

$newUrl = str_replace($currentScheme."://", $newScheme."://", $url);

self::applyInitPathHook($newUrl);
self::applyInitPathHook($newUrl, $context);

return $newUrl;
}

protected static function findWrapperClassName($scheme){
if(isSet(self::$metaWrappers[$scheme])){
$wrapper = self::$metaWrappers[$scheme];
// TODO - problem here
protected static function findWrapperClassName($scheme, $context = "core"){

$metaWrappers = self::getMetaWrappers($context);

if(isSet($metaWrappers[$scheme])){
$wrapper = $metaWrappers[$scheme];
}else{
$wrapper = AJXP_PluginsService::getInstance()->getWrapperClassName($scheme);
}
if(empty($wrapper)) {
throw new Exception("Cannot find any wrapper for the scheme " . $scheme);
throw new Exception("Cannot find any wrapper for the scheme " . $scheme . " in context " . $context);
}
return $wrapper;
}

protected static function findSubWrapperClassName($url){
$nextScheme = self::getNextScheme($url);
$repositoryId = parse_url($url, PHP_URL_HOST);
$context = self::actualRepositoryWrapperProtocol($repositoryId);
$nextScheme = self::getNextScheme($url, $context);

return self::findWrapperClassName($nextScheme);
return self::findWrapperClassName($nextScheme, $context);
}

protected static function actualRepositoryWrapperData($repositoryId){
Expand All @@ -158,6 +173,7 @@ protected static function actualRepositoryWrapperData($repositoryId){
}
}


/**
* Return the final ajxp.XX wrapper class name.
* @param $repositoryId
Expand All @@ -169,14 +185,27 @@ public static function actualRepositoryWrapperClass($repositoryId){
return $data["classname"];
}

/**
* Return the final ajxp.XX wrapper protocol.
* @param $repositoryId
* @return string mixed
* @throws Exception
*/
public static function actualRepositoryWrapperProtocol($repositoryId){
$data = self::actualRepositoryWrapperData($repositoryId);
return $data["protocol"];
}



/**
* Call Init function for a translated Path if defined
*
* @param string $path
*/
public static function applyInitPathHook($path) {
public static function applyInitPathHook($path, $context = 'core') {
$currentScheme = parse_url($path, PHP_URL_SCHEME);
$wrapper = self::findWrapperClassName($currentScheme);
$wrapper = self::findWrapperClassName($currentScheme, $context);

if (is_callable(array($wrapper, "applyInitPathHook"))){
call_user_func(array($wrapper, "applyInitPathHook"), $path);
Expand Down
3 changes: 1 addition & 2 deletions core/src/plugins/access.webdav/src/Client.php
Expand Up @@ -202,10 +202,9 @@ public function getIterator($response) {
array_shift($keys);

foreach ($keys as $key) {

$formattedStat = $this->_formatUrlStat($response[$key]);
$this->files[] = [
basename($key),
urldecode(basename($key)),
$formattedStat
];
}
Expand Down
15 changes: 12 additions & 3 deletions core/src/plugins/access.webdav/src/Driver.php
Expand Up @@ -45,15 +45,24 @@ class Driver extends \fsAccessDriver
protected $wrapperClassName;
protected $urlBase;

/*
* Driver Initialization
*
*/
public function init($repository, $options = array())
{
parent::init($repository, $options);

AJXP_MetaStreamWrapper::appendMetaWrapper("auth.dav", "Pydio\Access\Core\Stream\AuthWrapper", "pydio.dav");
AJXP_MetaStreamWrapper::appendMetaWrapper("path.dav", "Pydio\Access\Core\Stream\PathWrapper", "pydio.dav");
}

/**
* Repository Initialization
*
*/
public function initRepository()
{
AJXP_MetaStreamWrapper::appendMetaWrapper("auth.dav", "Pydio\Access\Core\Stream\AuthWrapper");
AJXP_MetaStreamWrapper::appendMetaWrapper("path.dav", "Pydio\Access\Core\Stream\PathWrapper");

$this->detectStreamWrapper(true);

if (is_array($this->pluginConf)) {
Expand Down

0 comments on commit 4f7feeb

Please sign in to comment.