diff options
author | Robin Appelman <icewind1991@gmail.com> | 2011-08-15 20:37:50 +0200 |
---|---|---|
committer | Robin Appelman <icewind1991@gmail.com> | 2011-08-15 21:09:13 +0200 |
commit | 6173c0fbc262f0d02c45d9cf4e81b020ad839145 (patch) | |
tree | 7c453e5dce300051efbcc3721eec4d7306c6000d /lib/fileproxy.php | |
parent | 2f1a06b2ee8b2022e71d8903fd5ce0ccf2f8c22f (diff) | |
download | nextcloud-server-6173c0fbc262f0d02c45d9cf4e81b020ad839145.tar.gz nextcloud-server-6173c0fbc262f0d02c45d9cf4e81b020ad839145.zip |
a bit of refactoring for oc_filesystem and implement user quota
Diffstat (limited to 'lib/fileproxy.php')
-rw-r--r-- | lib/fileproxy.php | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/lib/fileproxy.php b/lib/fileproxy.php new file mode 100644 index 00000000000..549b7015a6a --- /dev/null +++ b/lib/fileproxy.php @@ -0,0 +1,111 @@ +<?php + +/** +* ownCloud +* +* @author Robin Appelman +* @copyright 2011 Robin Appelman icewind1991@gmail.com +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +/** + * Class for manipulating filesystem requests + * + * Manipulation happens by using 2 kind of proxy operations, pre and post proxies + * that manipulate the filesystem call and the result of the call respectively + * + * A pre-proxy recieves the filepath as arugments (or 2 filespaths in case of operations like copy or move) and return a boolean + * If a pre-proxy returnes false the file operation will be canceled + * All filesystem operations have a pre-proxy + * + * A post-proxy recieves 2 arguments, the filepath and the result of the operation. + * The return calue of the post-proxy will be used as the new result of the operation + * The operations that have a post-proxy are + * file_get_contents, is_file, is_dir, file_exists, stat, is_readable, is_writable, fileatime, filemtime, filectime, file_get_contents, getMimeType, hash, free_space and search + */ + +class OC_FileProxy{ + private static $proxies=array(); + + /** + * check if this proxy implments a specific proxy operation + * @param string #proxy name of the proxy operation + * @return bool + */ + public function provides($operation){ + return method_exists($this,$operation); + } + + /** + * fallback function when a proxy operation is not implement + * @param string $function the name of the proxy operation + * @param mixed + * + * this implements a dummy proxy for all operations + */ + public function __call($function,$arguments){ + if(substr($function,0,3)=='pre'){ + return true; + }else{ + return $arguments[1]; + } + } + + /** + * register a proxy to be used + * @param OC_FileProxy $proxy + */ + public static function register($proxy){ + self::$proxies[]=$proxy; + } + + public static function getProxies($operation,$post){ + $operation=(($post)?'post':'pre').$operation; + $proxies=array(); + foreach(self::$proxies as $proxy){ + if($proxy->provides($operation)){ + $proxies[]=$proxy; + } + } + return $proxies; + } + + public static function runPreProxies($operation,$filepath,$filepath2=null){ + $proxies=self::getProxies($operation,false); + $operation='pre'.$operation; + foreach($proxies as $proxy){ + if($filepath2){ + if(!$proxy->$operation($filepath,$filepath2)){ + return false; + } + }else{ + if(!$proxy->$operation($filepath)){ + return false; + } + } + } + return true; + } + + public static function runPostProxies($operation,$path,$result){ + $proxies=self::getProxies($operation,true); + $operation='post'.$operation; + foreach($proxies as $proxy){ + $result=$proxy->$operation($path,$result); + } + return $result; + } +}
\ No newline at end of file |