S3.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  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){1,3}\.(\d){1,3}\.(\d){1,3}\.(\d){1,3}/', $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. $client->setAuth(false);
  393. // Work around buglet in HTTP client - it doesn't clean headers
  394. // Remove when ZHC is fixed
  395. $client->setHeaders(array('Content-MD5' => null,
  396. 'Expect' => null,
  397. 'Range' => null,
  398. 'x-amz-acl' => null));
  399. $client->setUri($endpoint);
  400. $client->setHeaders($headers);
  401. if (is_array($params)) {
  402. foreach ($params as $name=>$value) {
  403. $client->setParameterGet($name, $value);
  404. }
  405. }
  406. if (($method == 'PUT') && ($data !== null)) {
  407. if (!isset($headers['Content-type'])) {
  408. $headers['Content-type'] = self::getMimeType($path);
  409. }
  410. $client->setRawData($data, $headers['Content-type']);
  411. }
  412. do {
  413. $retry = false;
  414. $response = $client->request($method);
  415. $response_code = $response->getStatus();
  416. // Some 5xx errors are expected, so retry automatically
  417. if ($response_code >= 500 && $response_code < 600 && $retry_count <= 5) {
  418. $retry = true;
  419. $retry_count++;
  420. sleep($retry_count / 4 * $retry_count);
  421. }
  422. else if ($response_code == 307) {
  423. // Need to redirect, new S3 endpoint given
  424. // This should never happen as Zend_Http_Client will redirect automatically
  425. }
  426. else if ($response_code == 100) {
  427. // echo 'OK to Continue';
  428. }
  429. } while ($retry);
  430. return $response;
  431. }
  432. /**
  433. * Add the S3 Authorization signature to the request headers
  434. *
  435. * @param string $method
  436. * @param string $path
  437. * @param array &$headers
  438. * @return string
  439. */
  440. protected function addSignature($method, $path, &$headers)
  441. {
  442. if (!is_array($headers)) {
  443. $headers = array($headers);
  444. }
  445. $type = $md5 = $date = '';
  446. // Search for the Content-type, Content-MD5 and Date headers
  447. foreach ($headers as $key=>$val) {
  448. if (strcasecmp($key, 'content-type') == 0) {
  449. $type = $val;
  450. }
  451. else if (strcasecmp($key, 'content-md5') == 0) {
  452. $md5 = $val;
  453. }
  454. else if (strcasecmp($key, 'date') == 0) {
  455. $date = $val;
  456. }
  457. }
  458. // If we have an x-amz-date header, use that instead of the normal Date
  459. if (isset($headers['x-amz-date']) && isset($date)) {
  460. $date = '';
  461. }
  462. $sig_str = "$method\n$md5\n$type\n$date\n";
  463. // For x-amz- headers, combine like keys, lowercase them, sort them
  464. // alphabetically and remove excess spaces around values
  465. $amz_headers = array();
  466. foreach ($headers as $key=>$val) {
  467. $key = strtolower($key);
  468. if (substr($key, 0, 6) == 'x-amz-') {
  469. if (is_array($val)) {
  470. $amz_headers[$key] = $val;
  471. }
  472. else {
  473. $amz_headers[$key][] = preg_replace('/\s+/', ' ', $val);
  474. }
  475. }
  476. }
  477. if (!empty($amz_headers)) {
  478. ksort($amz_headers);
  479. foreach ($amz_headers as $key=>$val) {
  480. $sig_str .= $key.':'.implode(',', $val)."\n";
  481. }
  482. }
  483. $sig_str .= '/'.parse_url($path, PHP_URL_PATH);
  484. if (strpos($path, '?location') !== false) {
  485. $sig_str .= '?location';
  486. }
  487. else if (strpos($path, '?acl') !== false) {
  488. $sig_str .= '?acl';
  489. }
  490. else if (strpos($path, '?torrent') !== false) {
  491. $sig_str .= '?torrent';
  492. }
  493. $signature = base64_encode(Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'sha1', utf8_encode($sig_str), Zend_Crypt_Hmac::BINARY));
  494. $headers['Authorization'] = 'AWS '.$this->_getAccessKey().':'.$signature;
  495. return $sig_str;
  496. }
  497. /**
  498. * Attempt to get the content-type of a file based on the extension
  499. *
  500. * TODO: move this to Zend_Mime
  501. *
  502. * @param string $path
  503. * @return string
  504. */
  505. public static function getMimeType($path)
  506. {
  507. $ext = substr(strrchr($path, '.'), 1);
  508. if(!$ext) {
  509. // shortcut
  510. return 'binary/octet-stream';
  511. }
  512. switch ($ext) {
  513. case 'xls':
  514. $content_type = 'application/excel';
  515. break;
  516. case 'hqx':
  517. $content_type = 'application/macbinhex40';
  518. break;
  519. case 'doc':
  520. case 'dot':
  521. case 'wrd':
  522. $content_type = 'application/msword';
  523. break;
  524. case 'pdf':
  525. $content_type = 'application/pdf';
  526. break;
  527. case 'pgp':
  528. $content_type = 'application/pgp';
  529. break;
  530. case 'ps':
  531. case 'eps':
  532. case 'ai':
  533. $content_type = 'application/postscript';
  534. break;
  535. case 'ppt':
  536. $content_type = 'application/powerpoint';
  537. break;
  538. case 'rtf':
  539. $content_type = 'application/rtf';
  540. break;
  541. case 'tgz':
  542. case 'gtar':
  543. $content_type = 'application/x-gtar';
  544. break;
  545. case 'gz':
  546. $content_type = 'application/x-gzip';
  547. break;
  548. case 'php':
  549. case 'php3':
  550. case 'php4':
  551. $content_type = 'application/x-httpd-php';
  552. break;
  553. case 'js':
  554. $content_type = 'application/x-javascript';
  555. break;
  556. case 'ppd':
  557. case 'psd':
  558. $content_type = 'application/x-photoshop';
  559. break;
  560. case 'swf':
  561. case 'swc':
  562. case 'rf':
  563. $content_type = 'application/x-shockwave-flash';
  564. break;
  565. case 'tar':
  566. $content_type = 'application/x-tar';
  567. break;
  568. case 'zip':
  569. $content_type = 'application/zip';
  570. break;
  571. case 'mid':
  572. case 'midi':
  573. case 'kar':
  574. $content_type = 'audio/midi';
  575. break;
  576. case 'mp2':
  577. case 'mp3':
  578. case 'mpga':
  579. $content_type = 'audio/mpeg';
  580. break;
  581. case 'ra':
  582. $content_type = 'audio/x-realaudio';
  583. break;
  584. case 'wav':
  585. $content_type = 'audio/wav';
  586. break;
  587. case 'bmp':
  588. $content_type = 'image/bitmap';
  589. break;
  590. case 'gif':
  591. $content_type = 'image/gif';
  592. break;
  593. case 'iff':
  594. $content_type = 'image/iff';
  595. break;
  596. case 'jb2':
  597. $content_type = 'image/jb2';
  598. break;
  599. case 'jpg':
  600. case 'jpe':
  601. case 'jpeg':
  602. $content_type = 'image/jpeg';
  603. break;
  604. case 'jpx':
  605. $content_type = 'image/jpx';
  606. break;
  607. case 'png':
  608. $content_type = 'image/png';
  609. break;
  610. case 'tif':
  611. case 'tiff':
  612. $content_type = 'image/tiff';
  613. break;
  614. case 'wbmp':
  615. $content_type = 'image/vnd.wap.wbmp';
  616. break;
  617. case 'xbm':
  618. $content_type = 'image/xbm';
  619. break;
  620. case 'css':
  621. $content_type = 'text/css';
  622. break;
  623. case 'txt':
  624. $content_type = 'text/plain';
  625. break;
  626. case 'htm':
  627. case 'html':
  628. $content_type = 'text/html';
  629. break;
  630. case 'xml':
  631. $content_type = 'text/xml';
  632. break;
  633. case 'xsl':
  634. $content_type = 'text/xsl';
  635. break;
  636. case 'mpg':
  637. case 'mpe':
  638. case 'mpeg':
  639. $content_type = 'video/mpeg';
  640. break;
  641. case 'qt':
  642. case 'mov':
  643. $content_type = 'video/quicktime';
  644. break;
  645. case 'avi':
  646. $content_type = 'video/x-ms-video';
  647. break;
  648. case 'eml':
  649. $content_type = 'message/rfc822';
  650. break;
  651. default:
  652. $content_type = 'binary/octet-stream';
  653. break;
  654. }
  655. return $content_type;
  656. }
  657. /**
  658. * Register this object as stream wrapper client
  659. *
  660. * @param string $name
  661. * @return Zend_Service_Amazon_S3
  662. */
  663. public function registerAsClient($name)
  664. {
  665. self::$_wrapperClients[$name] = $this;
  666. return $this;
  667. }
  668. /**
  669. * Unregister this object as stream wrapper client
  670. *
  671. * @param string $name
  672. * @return Zend_Service_Amazon_S3
  673. */
  674. public function unregisterAsClient($name)
  675. {
  676. unset(self::$_wrapperClients[$name]);
  677. return $this;
  678. }
  679. /**
  680. * Get wrapper client for stream type
  681. *
  682. * @param string $name
  683. * @return Zend_Service_Amazon_S3
  684. */
  685. public static function getWrapperClient($name)
  686. {
  687. return self::$_wrapperClients[$name];
  688. }
  689. /**
  690. * Register this object as stream wrapper
  691. *
  692. * @param string $name
  693. * @return Zend_Service_Amazon_S3
  694. */
  695. public function registerStreamWrapper($name='s3')
  696. {
  697. /**
  698. * @see Zend_Service_Amazon_S3_Stream
  699. */
  700. require_once 'Zend/Service/Amazon/S3/Stream.php';
  701. stream_register_wrapper($name, 'Zend_Service_Amazon_S3_Stream');
  702. $this->registerAsClient($name);
  703. }
  704. /**
  705. * Unregister this object as stream wrapper
  706. *
  707. * @param string $name
  708. * @return Zend_Service_Amazon_S3
  709. */
  710. public function unregisterStreamWrapper($name='s3')
  711. {
  712. stream_wrapper_unregister($name);
  713. $this->unregisterAsClient($name);
  714. }
  715. }