[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/zend/Zend/Service/Nirvanix/Namespace/ -> Imfs.php (source)

   1  <?php
   2  /**
   3   * Zend Framework
   4   *
   5   * LICENSE
   6   *
   7   * This source file is subject to the new BSD license that is bundled
   8   * with this package in the file LICENSE.txt.
   9   * It is also available through the world-wide-web at this URL:
  10   * http://framework.zend.com/license/new-bsd
  11   * If you did not receive a copy of the license and are unable to
  12   * obtain it through the world-wide-web, please send an email
  13   * to [email protected] so we can send you a copy immediately.
  14   *
  15   * @category   Zend
  16   * @package    Zend_Service
  17   * @subpackage Nirvanix
  18   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  20   * @version    $Id$
  21   */
  22  
  23  /**
  24   * @see Zend_Service_Nirvanix_Namespace_Base
  25   */
  26  require_once 'Zend/Service/Nirvanix/Namespace/Base.php';
  27  
  28  /**
  29   * Namespace proxy with additional convenience methods for the IMFS namespace.
  30   *
  31   * @category   Zend
  32   * @package    Zend_Service
  33   * @subpackage Nirvanix
  34   * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  35   * @license    http://framework.zend.com/license/new-bsd     New BSD License
  36   */
  37  class Zend_Service_Nirvanix_Namespace_Imfs extends Zend_Service_Nirvanix_Namespace_Base
  38  {
  39      /**
  40       * Convenience function to get the contents of a file on
  41       * the Nirvanix IMFS.  Analog to PHP's file_get_contents().
  42       *
  43       * @param  string  $filePath    Remote path and filename
  44       * @param  integer $expiration  Number of seconds that Nirvanix
  45       *                              make the file available for download.
  46       * @return string               Contents of file
  47       */
  48      public function getContents($filePath, $expiration = 3600)
  49      {
  50          // get url to download the file
  51          $params = array('filePath'   => $filePath,
  52                          'expiration' => $expiration);
  53          $resp = $this->getOptimalUrls($params);
  54          $url = (string)$resp->Download->DownloadURL;
  55  
  56          // download the file
  57          $this->_httpClient->resetParameters();
  58          $this->_httpClient->setUri($url);
  59          $resp = $this->_httpClient->request(Zend_Http_Client::GET);
  60  
  61          return $resp->getBody();
  62      }
  63  
  64      /**
  65       * Convenience function to put the contents of a string into
  66       * the Nirvanix IMFS.  Analog to PHP's file_put_contents().
  67       *
  68       * @param  string  $filePath    Remote path and filename
  69       * @param  integer $data        Data to store in the file
  70       * @param  string  $mimeType    Mime type of data
  71       * @return Zend_Service_Nirvanix_Response
  72       */
  73      public function putContents($filePath, $data, $mimeType = null)
  74      {
  75          // get storage node for upload
  76          $params = array('sizeBytes' => strlen($data));
  77          $resp = $this->getStorageNode($params);
  78          $host        = (string)$resp->GetStorageNode->UploadHost;
  79          $uploadToken = (string)$resp->GetStorageNode->UploadToken;
  80  
  81          // http upload data into remote file
  82          $this->_httpClient->resetParameters();
  83          $this->_httpClient->setUri("http://{$host}/Upload.ashx");
  84          $this->_httpClient->setParameterPost('uploadToken', $uploadToken);
  85          $this->_httpClient->setParameterPost('destFolderPath', str_replace('\\', '/',dirname($filePath)));
  86          $this->_httpClient->setFileUpload(basename($filePath), 'uploadFile', $data, $mimeType);
  87          $response = $this->_httpClient->request(Zend_Http_Client::POST);
  88  
  89          return new Zend_Service_Nirvanix_Response($response->getBody());
  90      }
  91  
  92      /**
  93       * Convenience function to remove a file from the Nirvanix IMFS.
  94       * Analog to PHP's unlink().
  95       *
  96       * @param  string  $filePath  Remove path and filename
  97       * @return Zend_Service_Nirvanix_Response
  98       */
  99      public function unlink($filePath)
 100      {
 101          $params = array('filePath' => $filePath);
 102          return $this->deleteFiles($params);
 103      }
 104  
 105  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1