web/lib/Zend/Cloud/StorageService/Adapter/FileSystem.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    11  * to license@zend.com so we can send you a copy immediately.
    11  * to license@zend.com so we can send you a copy immediately.
    12  *
    12  *
    13  * @category   Zend
    13  * @category   Zend
    14  * @package    Zend_Cloud
    14  * @package    Zend_Cloud
    15  * @subpackage StorageService
    15  * @subpackage StorageService
    16  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    16  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    17  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  */
    18  */
    19 
    19 
    20 require_once 'Zend/Cloud/StorageService/Adapter.php';
    20 require_once 'Zend/Cloud/StorageService/Adapter.php';
    21 require_once 'Zend/Cloud/StorageService/Exception.php';
    21 require_once 'Zend/Cloud/StorageService/Exception.php';
    24  * FileSystem adapter for unstructured cloud storage.
    24  * FileSystem adapter for unstructured cloud storage.
    25  *
    25  *
    26  * @category   Zend
    26  * @category   Zend
    27  * @package    Zend_Cloud
    27  * @package    Zend_Cloud
    28  * @subpackage StorageService
    28  * @subpackage StorageService
    29  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    29  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    30  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    30  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    31  */
    31  */
    32 class Zend_Cloud_StorageService_Adapter_FileSystem implements Zend_Cloud_StorageService_Adapter
    32 class Zend_Cloud_StorageService_Adapter_FileSystem implements Zend_Cloud_StorageService_Adapter
    33 {
    33 {
    34 
    34 
    43      */
    43      */
    44     protected $_directory = null;
    44     protected $_directory = null;
    45 
    45 
    46     /**
    46     /**
    47      * Constructor
    47      * Constructor
    48      * 
    48      *
    49      * @param  array|Zend_Config $options 
    49      * @param  array|Zend_Config $options
    50      * @return void
    50      * @return void
    51      */
    51      */
    52     public function __construct($options = array()) 
    52     public function __construct($options = array())
    53     {
    53     {
    54         if ($options instanceof Zend_Config) {
    54         if ($options instanceof Zend_Config) {
    55             $options = $options->toArray();
    55             $options = $options->toArray();
    56         }
    56         }
    57 
    57 
    73      *
    73      *
    74      * @param  string $path
    74      * @param  string $path
    75      * @param  array $options
    75      * @param  array $options
    76      * @return false|string
    76      * @return false|string
    77      */
    77      */
    78     public function fetchItem($path, $options = array()) 
    78     public function fetchItem($path, $options = array())
    79     {
    79     {
    80         $filepath = $this->_getFullPath($path);
    80         $filepath = $this->_getFullPath($path);
    81         $path     = realpath($filepath);
    81         $path     = realpath($filepath);
    82 
    82 
    83         if (!$path) {
    83         if (!$path || !file_exists($path)) {
    84             return false;
    84             return false;
    85         }
    85         }
    86 
    86 
    87         return file_get_contents($path);
    87         return file_get_contents($path);
    88     }
    88     }
    98      * @param  string $destinationPath
    98      * @param  string $destinationPath
    99      * @param  mixed $data
    99      * @param  mixed $data
   100      * @param  array $options
   100      * @param  array $options
   101      * @return void
   101      * @return void
   102      */
   102      */
   103     public function storeItem($destinationPath, $data, $options = array()) 
   103     public function storeItem($destinationPath, $data, $options = array())
   104     {
   104     {
   105         $path = $this->_getFullPath($destinationPath);
   105         $path = $this->_getFullPath($destinationPath);
   106         file_put_contents($path, $data);
   106         file_put_contents($path, $data);
   107         chmod($path, 0777);
   107         chmod($path, 0777);
   108     }
   108     }
   112      *
   112      *
   113      * @param  string $path
   113      * @param  string $path
   114      * @param  array $options
   114      * @param  array $options
   115      * @return void
   115      * @return void
   116      */
   116      */
   117     public function deleteItem($path, $options = array()) 
   117     public function deleteItem($path, $options = array())
   118     {
   118     {
   119         if (!isset($path)) {
   119         if (!isset($path)) {
   120             return;
   120             return;
   121         }
   121         }
   122 
   122 
   137      * @param  string $sourcePath
   137      * @param  string $sourcePath
   138      * @param  string $destination path
   138      * @param  string $destination path
   139      * @param  array $options
   139      * @param  array $options
   140      * @return void
   140      * @return void
   141      */
   141      */
   142     public function copyItem($sourcePath, $destinationPath, $options = array()) 
   142     public function copyItem($sourcePath, $destinationPath, $options = array())
   143     {
   143     {
   144         copy($this->_getFullPath($sourcePath), $this->_getFullPath($destinationPath));
   144         copy($this->_getFullPath($sourcePath), $this->_getFullPath($destinationPath));
   145     }
   145     }
   146 
   146 
   147     /**
   147     /**
   155      * @param  string $sourcePath
   155      * @param  string $sourcePath
   156      * @param  string $destination path
   156      * @param  string $destination path
   157      * @param  array $options
   157      * @param  array $options
   158      * @return void
   158      * @return void
   159      */
   159      */
   160     public function moveItem($sourcePath, $destinationPath, $options = array()) 
   160     public function moveItem($sourcePath, $destinationPath, $options = array())
   161     {
   161     {
   162         rename($this->_getFullPath($sourcePath), $this->_getFullPath($destinationPath));
   162         rename($this->_getFullPath($sourcePath), $this->_getFullPath($destinationPath));
   163     }
   163     }
   164 
   164 
   165         /**
   165         /**
   169      * @param  string $path
   169      * @param  string $path
   170      * @param  string $name
   170      * @param  string $name
   171      * @param  array $options
   171      * @param  array $options
   172      * @return void
   172      * @return void
   173      */
   173      */
   174     public function renameItem($path, $name, $options = null) 
   174     public function renameItem($path, $name, $options = null)
   175     {
   175     {
   176         rename(
   176         rename(
   177             $this->_getFullPath($path), 
   177             $this->_getFullPath($path),
   178             dirname($this->_getFullPath($path)) . DIRECTORY_SEPARATOR . $name
   178             dirname($this->_getFullPath($path)) . DIRECTORY_SEPARATOR . $name
   179         );
   179         );
   180     }
   180     }
   181 
   181 
   182     /**
   182     /**
   187      *
   187      *
   188      * @param  string $path Must be a directory
   188      * @param  string $path Must be a directory
   189      * @param  array $options
   189      * @param  array $options
   190      * @return array A list of item names
   190      * @return array A list of item names
   191      */
   191      */
   192     public function listItems($path, $options = null) 
   192     public function listItems($path, $options = null)
   193     {
   193     {
   194         $listing = scandir($this->_getFullPath($path));
   194         $listing = scandir($this->_getFullPath($path));
   195 
   195 
   196         // Remove the hidden navigation directories
   196         // Remove the hidden navigation directories
   197         $listing = array_diff($listing, array('.', '..'));
   197         $listing = array_diff($listing, array('.', '..'));
   204      *
   204      *
   205      * @param  string $path
   205      * @param  string $path
   206      * @param  array $options
   206      * @param  array $options
   207      * @return array
   207      * @return array
   208      */
   208      */
   209     public function fetchMetadata($path, $options = array()) 
   209     public function fetchMetadata($path, $options = array())
   210     {
   210     {
   211         $fullPath = $this->_getFullPath($path);
   211         $fullPath = $this->_getFullPath($path);
   212         $metadata = null;
   212         $metadata = null;
   213         if (file_exists($fullPath)) {
   213         if (file_exists($fullPath)) {
   214             $metadata = stat(realpath($fullPath));
   214             $metadata = stat(realpath($fullPath));
   224      *
   224      *
   225      * @param  string $destinationPath
   225      * @param  string $destinationPath
   226      * @param  array $options
   226      * @param  array $options
   227      * @return void
   227      * @return void
   228      */
   228      */
   229     public function storeMetadata($destinationPath, $metadata, $options = array()) 
   229     public function storeMetadata($destinationPath, $metadata, $options = array())
   230     {
   230     {
   231         require_once 'Zend/Cloud/OperationNotAvailableException.php';
   231         require_once 'Zend/Cloud/OperationNotAvailableException.php';
   232         throw new Zend_Cloud_OperationNotAvailableException('Storing metadata not implemented');
   232         throw new Zend_Cloud_OperationNotAvailableException('Storing metadata not implemented');
   233     }
   233     }
   234 
   234 
   237      *
   237      *
   238      * @param  string $path
   238      * @param  string $path
   239      * @param  array $options
   239      * @param  array $options
   240      * @return void
   240      * @return void
   241      */
   241      */
   242     public function deleteMetadata($path) 
   242     public function deleteMetadata($path)
   243     {
   243     {
   244         require_once 'Zend/Cloud/OperationNotAvailableException.php';
   244         require_once 'Zend/Cloud/OperationNotAvailableException.php';
   245         throw new Zend_Cloud_OperationNotAvailableException('Deleting metadata not implemented');
   245         throw new Zend_Cloud_OperationNotAvailableException('Deleting metadata not implemented');
   246     }
   246     }
   247 
   247 
   248     /**
   248     /**
   249      * Return the full path for the file.
   249      * Return the full path for the file.
   250      * 
   250      *
   251      * @param string $path
   251      * @param string $path
   252      * @return string
   252      * @return string
   253      */
   253      */
   254     private function _getFullPath($path) 
   254     private function _getFullPath($path)
   255     {
   255     {
   256         return $this->_directory . DIRECTORY_SEPARATOR . $path;
   256         return $this->_directory . DIRECTORY_SEPARATOR . $path;
   257     }
   257     }
   258 
   258 
   259     /**
   259     /**
   260      * Get the concrete client.
   260      * Get the concrete client.
   261      * @return strings
   261      * @return strings
   262      */
   262      */
   263     public function getClient()
   263     public function getClient()
   264     {
   264     {
   265          return $this->_directory;       
   265          return $this->_directory;
   266     }
   266     }
   267 }
   267 }