Skip to content
This repository
Browse code

new function: setBucketRedirect(bucket, location)

  • Loading branch information...
commit 458b558d00e2fc0ed270501c3fb9a8a9a88ee8d5 1 parent 5677037
Dave Jones authored February 23, 2013

Showing 1 changed file with 41 additions and 0 deletions. Show diff stats Hide diff stats

  1. 41  S3.php
41  S3.php
@@ -674,6 +674,47 @@ public static function copyObject($srcBucket, $srcUri, $bucket, $uri, $acl = sel
674 674
 
675 675
 
676 676
 	/**
  677
+	* Set up a bucket redirection
  678
+	*
  679
+	* @param string $bucket Bucket name
  680
+	* @param string $location Target host name
  681
+	* @return boolean
  682
+	*/
  683
+	public static function setBucketRedirect($bucket = NULL, $location = NULL)
  684
+	{
  685
+		$rest = new S3Request('PUT', $bucket, '', self::$endpoint);
  686
+
  687
+		if( empty($bucket) || empty($location) ) {
  688
+			self::__triggerError("S3::setBucketRedirect({$bucket}, {$location}): Empty parameter.", __FILE__, __LINE__);
  689
+			return false;
  690
+		}
  691
+
  692
+		$dom = new DOMDocument;
  693
+		$websiteConfiguration = $dom->createElement('WebsiteConfiguration');
  694
+		$redirectAllRequestsTo = $dom->createElement('RedirectAllRequestsTo');
  695
+		$hostName = $dom->createElement('HostName', $location);
  696
+		$redirectAllRequestsTo->appendChild($hostName);
  697
+		$websiteConfiguration->appendChild($redirectAllRequestsTo);
  698
+		$dom->appendChild($websiteConfiguration);
  699
+                $rest->setParameter('website', null);
  700
+		$rest->data = $dom->saveXML();
  701
+		$rest->size = strlen($rest->data);
  702
+		$rest->setHeader('Content-Type', 'application/xml');
  703
+		$rest = $rest->getResponse();
  704
+
  705
+		if ($rest->error === false && $rest->code !== 200)
  706
+			$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
  707
+		if ($rest->error !== false)
  708
+		{
  709
+			self::__triggerError(sprintf("S3::setBucketRedirect({$bucket}, {$location}): [%s] %s",
  710
+			$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
  711
+			return false;
  712
+		}
  713
+		return true;
  714
+	}
  715
+
  716
+
  717
+	/**
677 718
 	* Set logging for a bucket
678 719
 	*
679 720
 	* @param string $bucket Bucket name

0 notes on commit 458b558

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