diff --git a/src/vitis/vas/rest/class/vmlib/files/Local_files.class.inc b/src/vitis/vas/rest/class/vmlib/files/Local_files.class.inc index 6f456308b02f7d394c97e8d6865c4aa77002e781..37f99882d54fc3c313c72114c8dddd3b480f2db4 100644 --- a/src/vitis/vas/rest/class/vmlib/files/Local_files.class.inc +++ b/src/vitis/vas/rest/class/vmlib/files/Local_files.class.inc @@ -43,6 +43,15 @@ class Local_files implements Files{ public function file_put_contents ($sFilePath, $sData, $iFlags = 0, $mContext = null){ return file_put_contents($sFilePath, $sData, $iFlags, $mContext); } + /** + *read a file and return content in a string. + *@param string $sFilePath File's path. + *@param boolean $bUseIncludePath use include var to resolve a relative path. + *@param resource $mContext result de stream_context_create(). + *@param integer $iOffset offset in bytes to begin file reading, Default : 0. + *@param integer $iMaxLen Number of byte to read from the file, Default : -1 = read until the file's end. + *@return string|boolean file content, or false if the process encounter an error. + */ public function file_get_contents ($sFilePath, $bUseIncludePath = FALSE, $mContext = null, $iOffset = 0, $iMaxLen = -1){ if ($iMaxLen == -1){ return file_get_contents ($sFilePath, $bUseIncludePath, null, $iOffset); @@ -50,6 +59,16 @@ class Local_files implements Files{ return file_get_contents ($sFilePath, $bUseIncludePath, null, $iOffset, $iMaxLen); } } + /** + *read a file and return content in a string if eTag matches. + *@param string $sFilePath File's path. + *@param string $sEtag Hash Sha1 of file's content. + *@param boolean $bUseIncludePath use include var to resolve a relative path. + *@param resource $mContext result de stream_context_create(). + *@param integer $iOffset offset in bytes to begin file reading, Default : 0. + *@param integer $iMaxLen Number of byte to read from the file, Default : -1 = read until the file's end. + *@return string|boolean file content, or false if the process encounter an error. + */ public function file_get_contents_with_etag ($sFilePath, $sEtag ,$bUseIncludePath = FALSE, $mContext = null, $iOffset = 0, $iMaxLen = -1){ $sProcessedEtag = $this->getFileEtag($sFilePath); if ($sEtag == $sProcessedEtag){ @@ -58,15 +77,40 @@ class Local_files implements Files{ return false; } } + /** + *copy a file. + *@param string $sSourceFilePath File's path to copy. + *@param string $sDestFilePath File's destination. + *@return boolean true on sucess or false if the process encounter an error. + */ public function copy ($sSourceFilePath, $sDestFilePath){ return copy ($sSourceFilePath, $sDestFilePath); } + /** + *return the size of a file in bytes. + *@param string $sFilePath File's path. + *@return integer|boolean File's size in bytes or false if the process encounter an error. + */ public function filesize ($sFilePath){ return filesize($sFilePath); } + /** + *send file's content into stdout. + *@param string $sFilePath File's path. + *@param boolean $bUseIncludePath use include var to resolve a relative path. + *@param resource $mContext result de stream_context_create(). + *@return integer|boolean File's size in bytes or false if the process encounter an error. + */ public function readfile ($sFilePath, $bUseIncludePath = FALSE, $mContext = null){ return readfile($sFilePath, $bUseIncludePath, $mContext); } + /** + *move a file. + *@param string $sSourceFilePath File's path to copy. + *@param string $sDestFilePath File's destination. + *@param resource $mContext result de stream_context_create(). + *@return boolean true on sucess or false if the process encounter an error. + */ public function rename ($sSourceFilePath, $sDestFilePath, $mContext = null){ if(empty($mContext)){ return rename($sSourceFilePath, $sDestFilePath); @@ -74,6 +118,12 @@ class Local_files implements Files{ return rename($sSourceFilePath, $sDestFilePath, $mContext); } } + /** + *remove a file. + *@param string $sFilePath File's path. + *@param resource $mContext result de stream_context_create(). + *@return boolean true on sucess or false if the process encounter an error. + */ public function unlink ($sFilePath, $mContext = null){ if(empty($mContext)){ return unlink($sFilePath); @@ -81,13 +131,28 @@ class Local_files implements Files{ return unlink($sFilePath, $mContext); } } + /** + *return the number of second UNIX of the last modification on a file. + *@param string $sFilePath File's path. + *@return integer|boolean timestamp on sucess or false if the process encounter an error. + */ public function filemtime ($sFilePath){ return filemtime($sFilePath); } - + /** + *return the fomrated date of the last modification on a file. + *@param string $sFilePath File's path. + *@param string $sFormat Format to convert the timestamp. + *@return string|boolean date string on sucess or false if the process encounter an error. + */ public function filemtime_formated($sFilePath, $sFormat){ return date ($sFormat, $this->filemtime($sFilePath)); } + /** + *return the metadata structure of a file. + *@param string $sFilePath File's path. + *@return array filename, size, lastModification, href. + */ public function getFileInfos ($sFilePath){ $iFileSize = $this->filesize($sFilePath); @@ -108,6 +173,11 @@ class Local_files implements Files{ return array("filename"=>$aFileName[count($aFileName) - 1], "size"=>$sFileSize, "lastModification"=> $this->filemtime_formated ($sFilePath, "d/m/Y H:i:s"), "href" => $this->getProxyPassUrl($sFilePath)); } + /** + *return an url to download the file through Vitis API . + *@param string $sFilePath File's path. + *@return string url. + */ public function getProxyPassUrl ($sFilePath){ $date = new DateTime(); $sDataUrl = $this->oProperties['web_server_name'] . "/rest/vitis/file_downloader?key=[KEY]&eTag=[ETAG]&d=" . $date->getTimestamp(); diff --git a/src/vitis/vas/rest/class/vmlib/files/S3_files.class.inc b/src/vitis/vas/rest/class/vmlib/files/S3_files.class.inc index 470b94a1080c85e73bb0f668ba3431eee4f31d00..ec03d5ab58e6f4ff417ff937882c590d77413908 100644 --- a/src/vitis/vas/rest/class/vmlib/files/S3_files.class.inc +++ b/src/vitis/vas/rest/class/vmlib/files/S3_files.class.inc @@ -20,7 +20,11 @@ class S3_files implements Files{ 'debug' => false )); } - + /** + *parse vitis properties ti extract bucket name and bucket prefix. + *@private + *@return array bucket'name, prefix. + */ private function getBucketConst(){ $sBucket = $this->oProperties['fileS3UploaderBucket']; $sPrefix = ""; @@ -33,6 +37,11 @@ class S3_files implements Files{ return array($sBucket, $sPrefix); } + /** + *This method return the extension of a file. + *@param string $sFilePath File's path. + *@return string|boolean hash md5 of file content or false if the file doesn't exist. + */ public function getFileEtag($sFilePath){ list($sBucket, $sPrefix) = $this->getBucketConst(); $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath); @@ -49,6 +58,11 @@ class S3_files implements Files{ return false; } } + /** + *verify if a file exists. + *@param string $sFilePath File's path. + *@return boolean true if file exists, false else. + */ public function file_exists ($sFilePath){ list($sBucket, $sPrefix) = $this->getBucketConst(); @@ -65,6 +79,14 @@ class S3_files implements Files{ } return true; } + /** + *Write a string in a file. + *@param string $sFilePath File's path. + *@param string $sData string to write in this file. + *@param integer $iFlags flags to write in file (http://php.net/manual/fr/function.file-put-contents.php) Default : 0. + *@param resource $mContext result de stream_context_create(). + *@return integer|boolean number of byte written, or false if the process encounter an error. + */ public function file_put_contents ($sFilePath, $sData, $iFlags = 0, $mContext = null){ list($sBucket, $sPrefix) = $this->getBucketConst(); $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath); @@ -82,7 +104,15 @@ class S3_files implements Files{ } return strlen($sData); } - + /** + *read a file and return content in a string. + *@param string $sFilePath File's path. + *@param boolean $bUseIncludePath use include var to resolve a relative path. + *@param resource $mContext result de stream_context_create(). + *@param integer $iOffset offset in bytes to begin file reading, Default : 0. + *@param integer $iMaxLen Number of byte to read from the file, Default : -1 = read until the file's end. + *@return string|boolean file content, or false if the process encounter an error. + */ public function file_get_contents ($sFilePath, $bUseIncludePath = FALSE, $mContext = null, $iOffset = 0, $iMaxLen = -1){ list($sBucket, $sPrefix) = $this->getBucketConst(); @@ -112,7 +142,16 @@ class S3_files implements Files{ unlink($sPath); return $sFile; } - + /** + *read a file and return content in a string if eTag matches. + *@param string $sFilePath File's path. + *@param string $sEtag Hash Sha1 of file's content. + *@param boolean $bUseIncludePath use include var to resolve a relative path. + *@param resource $mContext result de stream_context_create(). + *@param integer $iOffset offset in bytes to begin file reading, Default : 0. + *@param integer $iMaxLen Number of byte to read from the file, Default : -1 = read until the file's end. + *@return string|boolean file content, or false if the process encounter an error. + */ public function file_get_contents_with_etag ($sFilePath, $sEtag ,$bUseIncludePath = FALSE, $mContext = null, $iOffset = 0, $iMaxLen = -1){ list($sBucket, $sPrefix) = $this->getBucketConst(); $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath); @@ -141,7 +180,12 @@ class S3_files implements Files{ unlink($sPath); return $sFile; } - + /** + *copy a file in the same bucket. + *@param string $sSourceFilePath Object's key to copy. + *@param string $sDestFilePath Object's destination key. + *@return boolean true on sucess or false if the process encounter an error. + */ public function copy ($sSourceFilePath, $sDestFilePath){ list($sBucket, $sPrefix) = $this->getBucketConst(); $sDestFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sDestFilePath); @@ -159,6 +203,13 @@ class S3_files implements Files{ return false; } } + /** + *copy a file in another bucket. + *@param string $sSourceFilePath Object's key to copy. + *@param string $sDests3Key Object's destination key. + *@param string $sDestBucket Object's destination bucket. + *@return boolean true on sucess or false if the process encounter an error. + */ public function copyInAnotherBucket ($sSourceFilePath, $sDests3Key, $sDestBucket){ list($sBucket, $sPrefix) = $this->getBucketConst(); $sSourceFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sSourceFilePath); @@ -175,6 +226,12 @@ class S3_files implements Files{ return false; } } + /** + *send a local file to S3. + *@param string $sSourceFilePath File's path to copy. + *@param string $sDestFilePath Object's destination key. + *@return boolean true on sucess or false if the process encounter an error. + */ public function copyLocalToS3 ($sSourceFilePath, $sDestFilePath){ list($sBucket, $sPrefix) = $this->getBucketConst(); $sDestFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sDestFilePath); @@ -192,6 +249,11 @@ class S3_files implements Files{ } return true; } + /** + *return the size of a file in bytes. + *@param string $sFilePath File's path. + *@return integer|boolean File's size in bytes or false if the process encounter an error. + */ public function filesize ($sFilePath){ list($sBucket, $sPrefix) = $this->getBucketConst(); $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath); @@ -208,6 +270,13 @@ class S3_files implements Files{ return false; } } + /** + *send file's content into stdout. + *@param string $sFilePath File's path. + *@param boolean $bUseIncludePath use include var to resolve a relative path. + *@param resource $mContext result de stream_context_create(). + *@return integer|boolean File's size in bytes or false if the process encounter an error. + */ public function readfile ($sFilePath, $bUseIncludePath = FALSE, $mContext = null){ list($sBucket, $sPrefix) = $this->getBucketConst(); $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath); @@ -230,12 +299,25 @@ class S3_files implements Files{ unlink($sPath); return $iLength; } + /** + *move a file. + *@param string $sSourceFilePath File's path to copy. + *@param string $sDestFilePath File's destination. + *@param resource $mContext result de stream_context_create(). + *@return boolean true on sucess or false if the process encounter an error. + */ public function rename ($sSourceFilePath, $sDestFilePath, $mContext = null){ $bReturn = $this->copy($sSourceFilePath, $sDestFilePath); if ($bReturn) $bReturn = $this->unlink($sSourceFilePath, $mContext); return $bReturn; } + /** + *remove a file. + *@param string $sFilePath File's path. + *@param resource $mContext result de stream_context_create(). + *@return boolean true on sucess or false if the process encounter an error. + */ public function unlink ($sFilePath, $mContext = null){ list($sBucket, $sPrefix) = $this->getBucketConst(); $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath); @@ -251,6 +333,11 @@ class S3_files implements Files{ return false; } } + /** + *return the number of second UNIX of the last modification on a file. + *@param string $sFilePath File's path. + *@return integer|boolean timestamp on sucess or false if the process encounter an error. + */ public function filemtime ($sFilePath){ list($sBucket, $sPrefix) = $this->getBucketConst(); $sFilePath = str_replace($this->oProperties["vas_home"], $sPrefix , $sFilePath); @@ -267,9 +354,20 @@ class S3_files implements Files{ return false; } } + /** + *return the fomrated date of the last modification on a file. + *@param string $sFilePath File's path. + *@param string $sFormat Format to convert the timestamp. + *@return string|boolean date string on sucess or false if the process encounter an error. + */ public function filemtime_formated ($sFilePath, $sFormat){ return date ($sFormat, $this->filemtime($sFilePath)); } + /** + *return the metadata structure of a file. + *@param string $sFilePath File's path. + *@return array filename, size, lastModification, href. + */ public function getFileInfos ($sFilePath){ $iFileSize = $this->filesize($sFilePath); @@ -290,6 +388,11 @@ class S3_files implements Files{ return array("filename"=>$aFileName[count($aFileName) - 1], "size"=>$sFileSize, "lastModification"=> $this->filemtime_formated ($sFilePath, "d/m/Y H:i:s"), "href" => $this->getProxyPassUrl($sFilePath)); } + /** + *return an url to download the file through Vitis API . + *@param string $sFilePath File's path. + *@return string url. + */ public function getProxyPassUrl ($sFilePath){ $sEtag = $this->getFileEtag($sFilePath); list($sBucket, $sPrefix) = $this->getBucketConst();