2
0

S3.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  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 license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service
  17. * @subpackage Amazon_S3
  18. * @copyright Copyright (c) 2009, Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: S3.php 14190 2009-02-28 04:32:18Z jplock $
  21. */
  22. /**
  23. * @see Zend_Service_Amazon_Abstract
  24. */
  25. require_once 'Zend/Service/Amazon/Abstract.php';
  26. /**
  27. * @see Zend_Crypt_Hmac
  28. */
  29. require_once 'Zend/Crypt/Hmac.php';
  30. /**
  31. * Amazon S3 PHP connection class
  32. *
  33. * @category Zend
  34. * @package Zend_Service
  35. * @subpackage Amazon_S3
  36. * @copyright Copyright (c) 2005-2008, Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. * @see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/
  39. */
  40. class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
  41. {
  42. /**
  43. * Store for stream wrapper clients
  44. *
  45. * @var array
  46. */
  47. protected static $_wrapperClients = array();
  48. /**
  49. * Endpoint for the service
  50. *
  51. * @var Zend_Uri_Http
  52. */
  53. protected $_endpoint;
  54. const S3_ENDPOINT = 's3.amazonaws.com';
  55. const S3_ACL_PRIVATE = 'private';
  56. const S3_ACL_PUBLIC_READ = 'public-read';
  57. const S3_ACL_PUBLIC_WRITE = 'public-read-write';
  58. const S3_ACL_AUTH_READ = 'authenticated-read';
  59. const S3_REQUESTPAY_HEADER = 'x-amz-request-payer';
  60. const S3_ACL_HEADER = 'x-amz-acl';
  61. const S3_CONTENT_TYPE_HEADER = 'Content-Type';
  62. /**
  63. * Set S3 endpoint to use
  64. *
  65. * @param string|Zend_Uri_Http $endpoint
  66. * @return Zend_Service_Amazon_S3
  67. */
  68. public function setEndpoint($endpoint)
  69. {
  70. if(!($endpoint instanceof Zend_Uri_Http)) {
  71. $endpoint = Zend_Uri::factory($endpoint);
  72. }
  73. if(!$endpoint->valid()) {
  74. require_once 'Zend/Service/Amazon/S3/Exception.php';
  75. throw new Zend_Service_Amazon_S3_Exception("Invalid endpoint supplied");
  76. }
  77. $this->_endpoint = $endpoint;
  78. return $this;
  79. }
  80. /**
  81. * Get current S3 endpoint
  82. *
  83. * @return Zend_Uri_Http
  84. */
  85. public function getEndpoint()
  86. {
  87. return $this->_endpoint;
  88. }
  89. public function __construct($accessKey=null, $secretKey=null, $region=null)
  90. {
  91. parent::__construct($accessKey, $secretKey, $region);
  92. $this->setEndpoint("http://".self::S3_ENDPOINT);
  93. }
  94. /**
  95. * Verify if the bucket name is valid
  96. *
  97. * @param string $bucket
  98. * @return boolean
  99. */
  100. public function _validBucketName($bucket)
  101. {
  102. $len = strlen($bucket);
  103. if ($len < 3 || $len > 255) {
  104. /**
  105. * @see Zend_Service_Amazon_S3_Exception
  106. */
  107. require_once 'Zend/Service/Amazon/S3/Exception.php';
  108. throw new Zend_Service_Amazon_S3_Exception("Bucket name \"$bucket\" must be between 3 and 255 characters long");
  109. }
  110. if (preg_match('/[^a-z0-9\._-]/', $bucket)) {
  111. /**
  112. * @see Zend_Service_Amazon_S3_Exception
  113. */
  114. require_once 'Zend/Service/Amazon/S3/Exception.php';
  115. throw new Zend_Service_Amazon_S3_Exception("Bucket name \"$bucket\" contains invalid characters");
  116. }
  117. if (preg_match('/(\d+).(\d+).(\d+).(\d+)/', $bucket)) {
  118. /**
  119. * @see Zend_Service_Amazon_S3_Exception
  120. */
  121. require_once 'Zend/Service/Amazon/S3/Exception.php';
  122. throw new Zend_Service_Amazon_S3_Exception("Bucket name \"$bucket\" cannot be an IP address");
  123. }
  124. return true;
  125. }
  126. /**
  127. * Add a new bucket
  128. *
  129. * @param string $bucket
  130. * @return boolean
  131. */
  132. public function createBucket($bucket, $location = null)
  133. {
  134. $this->_validBucketName($bucket);
  135. if($location) {
  136. $data = "<CreateBucketConfiguration><LocationConstraint>$location</LocationConstraint></CreateBucketConfiguration>";
  137. } else {
  138. $data = null;
  139. }
  140. $response = $this->_makeRequest('PUT', $bucket, null, array(), $data);
  141. return ($response->getStatus() == 200);
  142. }
  143. /**
  144. * Checks if a given bucket name is available
  145. *
  146. * @param string $bucket
  147. * @return boolean
  148. */
  149. public function isBucketAvailable($bucket)
  150. {
  151. $response = $this->_makeRequest('HEAD', $bucket, array('max-keys'=>0));
  152. return ($response->getStatus() != 404);
  153. }
  154. /**
  155. * Checks if a given object exists
  156. *
  157. * @param string $object
  158. * @return boolean
  159. */
  160. public function isObjectAvailable($object)
  161. {
  162. $response = $this->_makeRequest('HEAD', $object);
  163. return ($response->getStatus() == 200);
  164. }
  165. /**
  166. * Remove a given bucket. All objects in the bucket must be removed prior
  167. * to removing the bucket.
  168. *
  169. * @param string $bucket
  170. * @return boolean
  171. */
  172. public function removeBucket($bucket)
  173. {
  174. $response = $this->_makeRequest('DELETE', $bucket);
  175. // Look for a 204 No Content response
  176. return ($response->getStatus() == 204);
  177. }
  178. /**
  179. * Get metadata information for a given object
  180. *
  181. * @param string $object
  182. * @return array|false
  183. */
  184. public function getInfo($object)
  185. {
  186. $info = array();
  187. $object = $this->_fixupObjectName($object);
  188. $response = $this->_makeRequest('HEAD', $object);
  189. if ($response->getStatus() == 200) {
  190. $info['type'] = $response->getHeader('Content-type');
  191. $info['size'] = $response->getHeader('Content-length');
  192. $info['mtime'] = strtotime($response->getHeader('Last-modified'));
  193. $info['etag'] = $response->getHeader('ETag');
  194. }
  195. else {
  196. return false;
  197. }
  198. return $info;
  199. }
  200. /**
  201. * List the S3 buckets
  202. *
  203. * @return array|false
  204. */
  205. public function getBuckets()
  206. {
  207. $response = $this->_makeRequest('GET');
  208. if ($response->getStatus() != 200) {
  209. return false;
  210. }
  211. $xml = new SimpleXMLElement($response->getBody());
  212. $buckets = array();
  213. foreach ($xml->Buckets->Bucket as $bucket) {
  214. $buckets[] = (string)$bucket->Name;
  215. }
  216. return $buckets;
  217. }
  218. /**
  219. * Remove all objects in the bucket.
  220. *
  221. * @param string $bucket
  222. * @return boolean
  223. */
  224. public function cleanBucket($bucket)
  225. {
  226. $objects = $this->getObjectsByBucket($bucket);
  227. if (!$objects) {
  228. return false;
  229. }
  230. foreach ($objects as $object) {
  231. $this->removeObject("$bucket/$object");
  232. }
  233. return true;
  234. }
  235. /**
  236. * List the objects in a bucket.
  237. *
  238. * Provides the list of object keys that are contained in the bucket.
  239. *
  240. * @param string $bucket
  241. * @return array|false
  242. */
  243. public function getObjectsByBucket($bucket)
  244. {
  245. $response = $this->_makeRequest('GET', $bucket);
  246. if ($response->getStatus() != 200) {
  247. return false;
  248. }
  249. $xml = new SimpleXMLElement($response->getBody());
  250. $objects = array();
  251. if (isset($xml->Contents)) {
  252. foreach ($xml->Contents as $contents) {
  253. foreach ($contents->Key as $object) {
  254. $objects[] = (string)$object;
  255. }
  256. }
  257. }
  258. return $objects;
  259. }
  260. protected function _fixupObjectName($object)
  261. {
  262. $nameparts = explode('/', $object);
  263. $this->_validBucketName($nameparts[0]);
  264. $firstpart = array_shift($nameparts);
  265. if(count($nameparts) == 0) {
  266. return $firstpart;
  267. }
  268. return $firstpart.'/'.join("/", array_map('rawurlencode',$nameparts));
  269. }
  270. /**
  271. * Get an object
  272. *
  273. * @param string $object
  274. * @param bool $paidobject This is "requestor pays" object
  275. * @return string|false
  276. */
  277. public function getObject($object, $paidobject = false)
  278. {
  279. $object = $this->_fixupObjectName($object);
  280. if($paidobject) {
  281. $response = $this->_makeRequest('GET', $object, null, array(self::S3_REQUESTPAY_HEADER => "requester"));
  282. } else {
  283. $response = $this->_makeRequest('GET', $object);
  284. }
  285. if ($response->getStatus() != 200) {
  286. return false;
  287. }
  288. return $response->getBody();
  289. }
  290. /**
  291. * Upload an object by a PHP string
  292. *
  293. * @param string $object Object name
  294. * @param string $data Object data
  295. * @param array $meta Metadata
  296. * @return boolean
  297. */
  298. public function putObject($object, $data, $meta=null)
  299. {
  300. $object = $this->_fixupObjectName($object);
  301. $headers = (is_array($meta)) ? $meta : array();
  302. $headers['Content-MD5'] = base64_encode(md5($data, true));
  303. $headers['Expect'] = '100-continue';
  304. if (!isset($headers[self::S3_CONTENT_TYPE_HEADER])) {
  305. $headers[self::S3_CONTENT_TYPE_HEADER] = self::getMimeType($object);
  306. }
  307. $response = $this->_makeRequest('PUT', $object, null, $headers, $data);
  308. // Check the MD5 Etag returned by S3 against and MD5 of the buffer
  309. if ($response->getStatus() == 200) {
  310. // It is escaped by double quotes for some reason
  311. $etag = str_replace('"', '', $response->getHeader('Etag'));
  312. if ($etag == md5($data)) {
  313. return true;
  314. }
  315. }
  316. return false;
  317. }
  318. /**
  319. * Put file to S3 as object
  320. *
  321. * @param string $path File name
  322. * @param string $object Object name
  323. * @param array $meta Metadata
  324. * @return boolean
  325. */
  326. public function putFile($path, $object, $meta=null)
  327. {
  328. $data = @file_get_contents($path);
  329. if ($data === false) {
  330. /**
  331. * @see Zend_Service_Amazon_S3_Exception
  332. */
  333. require_once 'Zend/Service/Amazon/S3/Exception.php';
  334. throw new Zend_Service_Amazon_S3_Exception("Cannot read file $path");
  335. }
  336. if (!is_array($meta)) {
  337. $meta = array();
  338. }
  339. if (!isset($meta[self::S3_CONTENT_TYPE_HEADER])) {
  340. $meta[self::S3_CONTENT_TYPE_HEADER] = self::getMimeType($path);
  341. }
  342. return $this->putObject($object, $data, $meta);
  343. }
  344. /**
  345. * Remove a given object
  346. *
  347. * @param string $object
  348. * @return boolean
  349. */
  350. public function removeObject($object)
  351. {
  352. $object = $this->_fixupObjectName($object);
  353. $response = $this->_makeRequest('DELETE', $object);
  354. // Look for a 204 No Content response
  355. return ($response->getStatus() == 204);
  356. }
  357. /**
  358. * Make a request to Amazon S3
  359. *
  360. * @param string $method
  361. * @param string $path
  362. * @param array $params
  363. * @param array $headers
  364. * @param string $data
  365. * @return Zend_Http_Response
  366. */
  367. public function _makeRequest($method, $path='', $params=null, $headers=array(), $data=null)
  368. {
  369. $retry_count = 0;
  370. if (!is_array($headers)) {
  371. $headers = array($headers);
  372. }
  373. $headers['Date'] = gmdate(DATE_RFC1123, time());
  374. // build the end point out
  375. $parts = explode('/', $path, 2);
  376. $endpoint = clone($this->_endpoint);
  377. if($parts[0]) {
  378. // prepend bucket name to the hostname
  379. $endpoint->setHost($parts[0].".".$endpoint->getHost());
  380. }
  381. if(!empty($parts[1])) {
  382. $endpoint->setPath('/'.$parts[1]);
  383. } else {
  384. $endpoint->setPath('/');
  385. if($parts[0]) {
  386. $path = $parts[0]."/";
  387. }
  388. }
  389. self::addSignature($method, $path, $headers);
  390. $client = self::getHttpClient();
  391. $client->resetParameters();
  392. // Work around buglet in HTTP client - it doesn't clean headers
  393. // Remove when ZHC is fixed
  394. $client->setHeaders(array('Content-MD5' => null,
  395. 'Expect' => null,
  396. 'Range' => null,
  397. 'x-amz-acl' => null));
  398. $client->setUri($endpoint);
  399. $client->setHeaders($headers);
  400. if (is_array($params)) {
  401. foreach ($params as $name=>$value) {
  402. $client->setParameterGet($name, $value);
  403. }
  404. }
  405. if (($method == 'PUT') && ($data !== null)) {
  406. if (!isset($headers['Content-type'])) {
  407. $headers['Content-type'] = self::getMimeType($path);
  408. }
  409. $client->setRawData($data, $headers['Content-type']);
  410. }
  411. do {
  412. $retry = false;
  413. $response = $client->request($method);
  414. $response_code = $response->getStatus();
  415. // Some 5xx errors are expected, so retry automatically
  416. if ($response_code >= 500 && $response_code < 600 && $retry_count <= 5) {
  417. $retry = true;
  418. $retry_count++;
  419. sleep($retry_count / 4 * $retry_count);
  420. }
  421. else if ($response_code == 307) {
  422. // Need to redirect, new S3 endpoint given
  423. // This should never happen as Zend_Http_Client will redirect automatically
  424. }
  425. else if ($response_code == 100) {
  426. // echo 'OK to Continue';
  427. }
  428. } while ($retry);
  429. return $response;
  430. }
  431. /**
  432. * Add the S3 Authorization signature to the request headers
  433. *
  434. * @param string $method
  435. * @param string $path
  436. * @param array &$headers
  437. * @return string
  438. */
  439. protected function addSignature($method, $path, &$headers)
  440. {
  441. if (!is_array($headers)) {
  442. $headers = array($headers);
  443. }
  444. $type = $md5 = $date = '';
  445. // Search for the Content-type, Content-MD5 and Date headers
  446. foreach ($headers as $key=>$val) {
  447. if (strcasecmp($key, 'content-type') == 0) {
  448. $type = $val;
  449. }
  450. else if (strcasecmp($key, 'content-md5') == 0) {
  451. $md5 = $val;
  452. }
  453. else if (strcasecmp($key, 'date') == 0) {
  454. $date = $val;
  455. }
  456. }
  457. // If we have an x-amz-date header, use that instead of the normal Date
  458. if (isset($headers['x-amz-date']) && isset($date)) {
  459. $date = '';
  460. }
  461. $sig_str = "$method\n$md5\n$type\n$date\n";
  462. // For x-amz- headers, combine like keys, lowercase them, sort them
  463. // alphabetically and remove excess spaces around values
  464. $amz_headers = array();
  465. foreach ($headers as $key=>$val) {
  466. $key = strtolower($key);
  467. if (substr($key, 0, 6) == 'x-amz-') {
  468. if (is_array($val)) {
  469. $amz_headers[$key] = $val;
  470. }
  471. else {
  472. $amz_headers[$key][] = preg_replace('/\s+/', ' ', $val);
  473. }
  474. }
  475. }
  476. if (!empty($amz_headers)) {
  477. ksort($amz_headers);
  478. foreach ($amz_headers as $key=>$val) {
  479. $sig_str .= $key.':'.implode(',', $val)."\n";
  480. }
  481. }
  482. $sig_str .= '/'.parse_url($path, PHP_URL_PATH);
  483. if (strpos($path, '?location') !== false) {
  484. $sig_str .= '?location';
  485. }
  486. else if (strpos($path, '?acl') !== false) {
  487. $sig_str .= '?acl';
  488. }
  489. else if (strpos($path, '?torrent') !== false) {
  490. $sig_str .= '?torrent';
  491. }
  492. $signature = base64_encode(Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'sha1', utf8_encode($sig_str), Zend_Crypt_Hmac::BINARY));
  493. $headers['Authorization'] = 'AWS '.$this->_getAccessKey().':'.$signature;
  494. return $sig_str;
  495. }
  496. /**
  497. * Attempt to get the content-type of a file based on the extension
  498. *
  499. * TODO: move this to Zend_Mime
  500. *
  501. * @param string $path
  502. * @return string
  503. */
  504. public static function getMimeType($path)
  505. {
  506. $ext = substr(strrchr($path, '.'), 1);
  507. if(!$ext) {
  508. // shortcut
  509. return 'binary/octet-stream';
  510. }
  511. switch ($ext) {
  512. case 'xls':
  513. $content_type = 'application/excel';
  514. break;
  515. case 'hqx':
  516. $content_type = 'application/macbinhex40';
  517. break;
  518. case 'doc':
  519. case 'dot':
  520. case 'wrd':
  521. $content_type = 'application/msword';
  522. break;
  523. case 'pdf':
  524. $content_type = 'application/pdf';
  525. break;
  526. case 'pgp':
  527. $content_type = 'application/pgp';
  528. break;
  529. case 'ps':
  530. case 'eps':
  531. case 'ai':
  532. $content_type = 'application/postscript';
  533. break;
  534. case 'ppt':
  535. $content_type = 'application/powerpoint';
  536. break;
  537. case 'rtf':
  538. $content_type = 'application/rtf';
  539. break;
  540. case 'tgz':
  541. case 'gtar':
  542. $content_type = 'application/x-gtar';
  543. break;
  544. case 'gz':
  545. $content_type = 'application/x-gzip';
  546. break;
  547. case 'php':
  548. case 'php3':
  549. case 'php4':
  550. $content_type = 'application/x-httpd-php';
  551. break;
  552. case 'js':
  553. $content_type = 'application/x-javascript';
  554. break;
  555. case 'ppd':
  556. case 'psd':
  557. $content_type = 'application/x-photoshop';
  558. break;
  559. case 'swf':
  560. case 'swc':
  561. case 'rf':
  562. $content_type = 'application/x-shockwave-flash';
  563. break;
  564. case 'tar':
  565. $content_type = 'application/x-tar';
  566. break;
  567. case 'zip':
  568. $content_type = 'application/zip';
  569. break;
  570. case 'mid':
  571. case 'midi':
  572. case 'kar':
  573. $content_type = 'audio/midi';
  574. break;
  575. case 'mp2':
  576. case 'mp3':
  577. case 'mpga':
  578. $content_type = 'audio/mpeg';
  579. break;
  580. case 'ra':
  581. $content_type = 'audio/x-realaudio';
  582. break;
  583. case 'wav':
  584. $content_type = 'audio/wav';
  585. break;
  586. case 'bmp':
  587. $content_type = 'image/bitmap';
  588. break;
  589. case 'gif':
  590. $content_type = 'image/gif';
  591. break;
  592. case 'iff':
  593. $content_type = 'image/iff';
  594. break;
  595. case 'jb2':
  596. $content_type = 'image/jb2';
  597. break;
  598. case 'jpg':
  599. case 'jpe':
  600. case 'jpeg':
  601. $content_type = 'image/jpeg';
  602. break;
  603. case 'jpx':
  604. $content_type = 'image/jpx';
  605. break;
  606. case 'png':
  607. $content_type = 'image/png';
  608. break;
  609. case 'tif':
  610. case 'tiff':
  611. $content_type = 'image/tiff';
  612. break;
  613. case 'wbmp':
  614. $content_type = 'image/vnd.wap.wbmp';
  615. break;
  616. case 'xbm':
  617. $content_type = 'image/xbm';
  618. break;
  619. case 'css':
  620. $content_type = 'text/css';
  621. break;
  622. case 'txt':
  623. $content_type = 'text/plain';
  624. break;
  625. case 'htm':
  626. case 'html':
  627. $content_type = 'text/html';
  628. break;
  629. case 'xml':
  630. $content_type = 'text/xml';
  631. break;
  632. case 'xsl':
  633. $content_type = 'text/xsl';
  634. break;
  635. case 'mpg':
  636. case 'mpe':
  637. case 'mpeg':
  638. $content_type = 'video/mpeg';
  639. break;
  640. case 'qt':
  641. case 'mov':
  642. $content_type = 'video/quicktime';
  643. break;
  644. case 'avi':
  645. $content_type = 'video/x-ms-video';
  646. break;
  647. case 'eml':
  648. $content_type = 'message/rfc822';
  649. break;
  650. default:
  651. $content_type = 'binary/octet-stream';
  652. break;
  653. }
  654. return $content_type;
  655. }
  656. /**
  657. * Register this object as stream wrapper client
  658. *
  659. * @param string $name
  660. * @return Zend_Service_Amazon_S3
  661. */
  662. public function registerAsClient($name)
  663. {
  664. self::$_wrapperClients[$name] = $this;
  665. return $this;
  666. }
  667. /**
  668. * Unregister this object as stream wrapper client
  669. *
  670. * @param string $name
  671. * @return Zend_Service_Amazon_S3
  672. */
  673. public function unregisterAsClient($name)
  674. {
  675. unset(self::$_wrapperClients[$name]);
  676. return $this;
  677. }
  678. /**
  679. * Get wrapper client for stream type
  680. *
  681. * @param string $name
  682. * @return Zend_Service_Amazon_S3
  683. */
  684. public static function getWrapperClient($name)
  685. {
  686. return self::$_wrapperClients[$name];
  687. }
  688. /**
  689. * Register this object as stream wrapper
  690. *
  691. * @param string $name
  692. * @return Zend_Service_Amazon_S3
  693. */
  694. public function registerStreamWrapper($name='s3')
  695. {
  696. /**
  697. * @see Zend_Service_Amazon_S3_Stream
  698. */
  699. require_once 'Zend/Service/Amazon/S3/Stream.php';
  700. stream_register_wrapper($name, 'Zend_Service_Amazon_S3_Stream');
  701. $this->registerAsClient($name);
  702. }
  703. /**
  704. * Unregister this object as stream wrapper
  705. *
  706. * @param string $name
  707. * @return Zend_Service_Amazon_S3
  708. */
  709. public function unregisterStreamWrapper($name='s3')
  710. {
  711. stream_wrapper_unregister($name);
  712. $this->unregisterAsClient($name);
  713. }
  714. }