<?php
/**
* @version 0.93
* @category Anahita Plugin
* @package File
* @copyright Copyright (C) 2007 - 2009 rmd Studio Inc. and Peerglobe Technology Inc. All rights reserved.
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
* @link http://www.anahitapolis.com
*/
require_once( dirname( __FILE__ ).DS.'protocols'.DS.'amazon.php' );
class AnUtilStorageAdapterAmazon extends AnUtilStorageAdapterAbstract
{
protected $_s3 = null;
protected $_bucket = array();
public function __construct($options=array())
{
parent::__construct($options);
$this->_s3 = new S3($this->getOption('access_key'), $this->getOption('secret_key'), $this->getOption('use_ssl'));
$this->_bucket = $this->getOption('bucket');
}
protected function _read($file)
{
return $this->_s3->getObject($this->_bucket, $file)->body;
}
protected function _write($file, $data, $public)
{
$acl = $public ? S3::ACL_PUBLIC_READ : S3::ACL_PRIVATE;
$options = array('Content-Type'=>$this->_s3->__getMimeType($file));
$this->_s3->putObject( $data, $this->_bucket, $file, $acl, array(), $options);
}
protected function _exists($file)
{
return false;
}
protected function _delete($file)
{
$this->_s3->deleteObject($this->_bucket, $file);
}
protected function _getUrl($file)
{
return "http://{$this->_bucket}.s3.amazonaws.com/".$file;
}
//end class
}