Files
fdn2/app/private/lib/system/SFSManager.php
T
2022-08-29 23:20:16 +02:00

142 lines
3.2 KiB
PHP

<?php
/**
* SFSManager - Storage and FileSystem Manager
* Gestore degli storage e dei filesystem presenti sul dispositivo fisico
*
* @author Riccardo Di Dato
*
*/
class SFSException extends CataloguedException {}
class SFSManager {
private static $fslist;
public static function getFilesystemList() {
if(self::$fslist == null || !is_array(self::$fslist) || sizeof(self::$fslist)==0) return null;
return self::$fslist;
}
public static function addFilesystem($fsobj) {
if (!($fsobj instanceof FSObject)) throw new SFSException("sfs.man.notafso");
if(self::$fslist == null || !is_array(self::$fslist)) self::$fslist = array();
self::$fslist[]=$fsobj;
}
public static function getFSObjByPath($path){
$memory=null;
foreach (self::$fslist as $fso){
if (preg_match('|^'.$fso->getMountPoint().'|',$path)){
if ($memory!=null){
if (preg_match('|^'.$memory->getMountPoint().'|',$fso->getMountPoint())){
$memory=$fso;
}
}
else {
$memory=$fso;
}
}
}
return $memory;
}
public static function readFile($path){
$fso=self::getFSObjByPath($path);
if($fso!=null){
return $fso->readFile($path);
}
}
public static function writeFile($content,$file){
$fso=self::getFSObjByPath($file);
if($fso!=null){
return $fso->writeFile($content,$file);
}
}
public static function appendToFile($content,$file){
$fso=self::getFSObjByPath($file);
if($fso!=null){
return $fso->appendToFile($content,$file);
}
}
public static function copyFile($source,$destination,$sudo=false){
$fso=self::getFSObjByPath($destination);
if($fso!=null){
return $fso->copyFile($source,$destination,$sudo);
}
}
public static function moveFile($source,$destination,$sudo=false){
$fso=self::getFSObjByPath($destination);
if($fso!=null){
return $fso->moveFile($source,$destination,$sudo);
}
}
public static function touchFile($path,$sudo=false){
$fso=self::getFSObjByPath($path);
if($fso!=null){
return $fso->touchFile($path,$sudo);
}
}
public static function deleteFile($path,$sudo=false){
$fso=self::getFSObjByPath($path);
if($fso!=null){
return $fso->deleteFile($path,$sudo);
}
}
public static function createDirectory($path,$sudo=false){
$fso=self::getFSObjByPath($path);
if($fso!=null){
return $fso->createDirectory($path,$sudo);
}
}
public static function copyDirectory($source,$destination,$sudo=false){
$fso=self::getFSObjByPath($destination);
if($fso!=null){
return $fso->copyDirectory($source,$destination,$sudo);
}
}
public static function fileExists($path){
$fso=self::getFSObjByPath($path);
if($fso!=null){
return $fso->fileExists($path);
}
}
public static function lsDir($path){
$fso=self::getFSObjByPath($path);
if($fso!=null){
return $fso->lsDir($path);
}
}
// Accepts file array or single directory
public static function createArchive($source,$dest){
$fso=self::getFSObjByPath($dest);
if($fso!=null){
return $fso->createArchive($dest,$source);
}
}
public static function deleteDirectory($path,$sudo=false){
$fso=self::getFSObjByPath($path);
if($fso!=null){
return $fso->deleteDirectory($path,$sudo);
}
}
}
?>