Skip to content
Browse files

Merge pull request #40 from daveajones/master

New function: setBucketRedirect()
  • Loading branch information...
2 parents 5677037 + 458b558 commit 66c2eaefe5cca838fb39fef3ba26fe48fecf8126 @tpyo committed Mar 19, 2013
Showing with 41 additions and 0 deletions.
  1. +41 −0 S3.php
View
41 S3.php
@@ -674,6 +674,47 @@ public static function copyObject($srcBucket, $srcUri, $bucket, $uri, $acl = sel
/**
+ * Set up a bucket redirection
+ *
+ * @param string $bucket Bucket name
+ * @param string $location Target host name
+ * @return boolean
+ */
+ public static function setBucketRedirect($bucket = NULL, $location = NULL)
+ {
+ $rest = new S3Request('PUT', $bucket, '', self::$endpoint);
+
+ if( empty($bucket) || empty($location) ) {
+ self::__triggerError("S3::setBucketRedirect({$bucket}, {$location}): Empty parameter.", __FILE__, __LINE__);
+ return false;
+ }
+
+ $dom = new DOMDocument;
+ $websiteConfiguration = $dom->createElement('WebsiteConfiguration');
+ $redirectAllRequestsTo = $dom->createElement('RedirectAllRequestsTo');
+ $hostName = $dom->createElement('HostName', $location);
+ $redirectAllRequestsTo->appendChild($hostName);
+ $websiteConfiguration->appendChild($redirectAllRequestsTo);
+ $dom->appendChild($websiteConfiguration);
+ $rest->setParameter('website', null);
+ $rest->data = $dom->saveXML();
+ $rest->size = strlen($rest->data);
+ $rest->setHeader('Content-Type', 'application/xml');
+ $rest = $rest->getResponse();
+
+ if ($rest->error === false && $rest->code !== 200)
+ $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
+ if ($rest->error !== false)
+ {
+ self::__triggerError(sprintf("S3::setBucketRedirect({$bucket}, {$location}): [%s] %s",
+ $rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
+ return false;
+ }
+ return true;
+ }
+
+
+ /**
* Set logging for a bucket
*
* @param string $bucket Bucket name

0 comments on commit 66c2eae

Please sign in to comment.
Something went wrong with that request. Please try again.