_initFileSystem(); } function getContent() { $this->xmlFS = ''; $this->_getAllContent( $this->_getFullQualifiedPath( '' ) ); return $this->xmlFS; } function isDirectory( $path ) { if( is_dir( $this->_getFullQualifiedPath( $path ) ) ) return true; else return false; } function createDirectory( $path ) { $newDir = $this->_getFullQualifiedPath( $path ); if( !is_dir( $newDir ) ) { return mkdir( $newDir, 0777 ); } else return false; } function deleteDirectory( $path ) { $dir = $this->_getFullQualifiedPath( $path ); return $this->_deleteAllDirectory( $dir ); } function renameDirectory( $path, $newName ) { $oldPath = $this->_getFullQualifiedPath( $path ); $newPath = $this->_getFullQualifiedPath( $newName ); if( !is_dir( $oldPath ) ) return false; else { if( rename( $oldPath, $newPath ) ) return true; else return false; } } function isFile( $path ) { if( is_file( $this->_getFullQualifiedPath( $path ) ) ) return true; else return false; } function deleteFile( $path ) { $file = $this->_getFullQualifiedPath( $path ); if( is_file( $file ) ) { unlink( $file ); return true; } else return false; } function renameFile( $path, $newName ) { $oldPath = $this->_getFullQualifiedPath( $path ); $newPath = $this->_getFullQualifiedPath( $newName ); if( !is_file( $oldPath ) ) return false; else { if( rename( $oldPath, $newPath ) ) return true; else return false; } } function readFileContent( $path ) { $file = $this->_getFullQualifiedPath( $path ); if( !is_file( $file ) ) return 'null'; $content = file_get_contents( $file ); if( $content == FALSE ) return 'null'; else return $content; } function writeToFile( $data, $path ) { $file = $this->_getFullQualifiedPath( $path ); if( !$handle = fopen( $file, "w" ) ) return false; if ( fwrite( $handle, $data ) === FALSE ) return false; fclose( $handle ); return true; } function appendToFile( $data, $path ) { $file = $this->_getFullQualifiedPath( $path ); if( !$handle = fopen( $file, "a" ) ) return false; if ( fwrite( $handle, $data ) === FALSE ) return false; fclose( $handle ); return true; } //------------------------------------------------------------------------- // Private implementation //------------------------------------------------------------------------- function _initFileSystem() { if( !is_dir( $this->rootName ) ) { mkdir ( $this->rootName, 0777 ); } } function _getFullQualifiedPath( $path ) { return $this->rootName.$path; } function _getAllContent( $dir ) { if ( substr( $dir,-1 ) != "/" ) $dir .= "/"; if( is_dir( $dir ) ) { if ( ( $content = opendir( $dir ) ) !== false ) { $nodeName = $this->_getDirName( $dir ); if( !$nodeName ) $nodeName = 'root'; $this->xmlFS .= '<' . $nodeName . '>'; while ( ( $item = readdir( $content ) ) !== false ) { if ( $item != "." && $item != ".." ) { if ( is_dir( $dir . $item ) ) $this->_getAllContent( $dir . $item ); else if( is_file( $dir . $item ) ) $this->xmlFS .= '<' . $item . ' type="string" />'; } } closedir( $content ); } $this->xmlFS .= ''; } } function _deleteAllDirectory( $dir ) { if ( substr( $dir,-1 ) != "/" ) $dir .= "/"; if ( !is_dir( $dir ) ) return false; if ( ( $content = opendir( $dir ) ) !== false ) { while ( ( $item = readdir( $content ) ) !== false ) { if ( $item != "." && $item != ".." ) { if ( is_file( $dir . $item ) || is_link( $dir . $item ) ) unlink( $dir . $item ); else if ( is_dir( $dir . $item ) ) $this->_deleteAllDirectory( $dir . $item ); } } closedir($content); rmdir($dir); return true; } return false; } function _getDirName( $dir ) { $dir = trim($dir, "/" ); $dir = strrchr( $dir, "/" ); return trim( $dir, "/" ); } } ?>