setParameter() public method

Set request parameter
public setParameter ( string $key, string $value ) : void
$key string Key
$value string Value
return void
示例#1
0
 /**
  * Get object or bucket Access Control Policy
  *
  * @param string $bucket Bucket name
  * @param string $uri Object URI
  * @return mixed | false
  */
 public static function getAccessControlPolicy($bucket, $uri = '')
 {
     $rest = new S3Request('GET', $bucket, $uri, self::$endpoint);
     $rest->setParameter('acl', null);
     $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::getAccessControlPolicy({$bucket}, {$uri}): [%s] %s", $rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
         return false;
     }
     $acp = array();
     if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName)) {
         $acp['owner'] = array('id' => (string) $rest->body->Owner->ID, 'name' => (string) $rest->body->Owner->DisplayName);
     }
     if (isset($rest->body->AccessControlList)) {
         $acp['acl'] = array();
         foreach ($rest->body->AccessControlList->Grant as $grant) {
             foreach ($grant->Grantee as $grantee) {
                 if (isset($grantee->ID, $grantee->DisplayName)) {
                     // CanonicalUser
                     $acp['acl'][] = array('type' => 'CanonicalUser', 'id' => (string) $grantee->ID, 'name' => (string) $grantee->DisplayName, 'permission' => (string) $grant->Permission);
                 } elseif (isset($grantee->EmailAddress)) {
                     // AmazonCustomerByEmail
                     $acp['acl'][] = array('type' => 'AmazonCustomerByEmail', 'email' => (string) $grantee->EmailAddress, 'permission' => (string) $grant->Permission);
                 } elseif (isset($grantee->URI)) {
                     // Group
                     $acp['acl'][] = array('type' => 'Group', 'uri' => (string) $grantee->URI, 'permission' => (string) $grant->Permission);
                 } else {
                     continue;
                 }
             }
         }
     }
     return $acp;
 }
示例#2
0
 public static function getBucketLocation($bucket)
 {
     $rest = new S3Request('GET', $bucket, '');
     $rest->setParameter('location', null);
     $rest = $rest->getResponse();
     if ($rest->error !== false || $rest->code !== 200) {
         throw new Exception(sprintf("S3::getBucketLocation(%s): [%s] %s", $bucket, $rest->code, 'Unexpected HTTP status'));
     }
     return isset($rest->body[0]) && (string) $rest->body[0] !== '' ? (string) $rest->body[0] : 'US';
 }
示例#3
0
文件: s3.php 项目: nikels/HeavyMetal
	/**
	 * Gets the contents of a bucket
	 * 
	 * @param $bucket
	 * @param $prefix
	 * @param $marker
	 * @param $maxKeys
	 * @param $delimiter
	 * @return unknown_type
	 */
	public function bucket_contents($bucket, $prefix = null, $marker = null, $maxKeys = null, $delimiter = null) 
	{
		$rest = new S3Request($this->id,$this->secret,true,'GET', $bucket, '');
	
		if ($prefix !== null && $prefix !== '') 
			$rest->setParameter('prefix', $prefix);

		if ($marker !== null && $marker !== '') 
			$rest->setParameter('marker', $marker);

		if ($maxKeys !== null && $maxKeys !== '') 
			$rest->setParameter('max-keys', $maxKeys);
		
		if ($delimiter !== null && $delimiter !== '') 
			$rest->setParameter('delimiter', $delimiter);
		
		$response = $rest->getResponse();
		
		if ($response->error === false && $response->code !== 200)
			$response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status');
		
		if ($response->error !== false) 
			throw new AWSException(sprintf("S3::getBucket(): [%s] %s", $response->error['code'], $response->error['message']));

		$results = array();

		$lastMarker = null;
		if (isset($response->body, $response->body->Contents))
			foreach ($response->body->Contents as $c) 
			{
				$results[(string)$c->Key] = array(
					'name' => (string)$c->Key,
					'time' => strtotime((string)$c->LastModified),
					'size' => (int)$c->Size,
					'hash' => substr((string)$c->ETag, 1, -1)
				);
				$lastMarker = (string)$c->Key;
				//$response->body->IsTruncated = 'true'; break;
			}


		if (isset($response->body->IsTruncated) && (string)$response->body->IsTruncated == 'false') 
			return $results;

		// Loop through truncated results if maxKeys isn't specified
		if ($maxKeys == null && $lastMarker !== null && (string)$response->body->IsTruncated == 'true')
			do 
			{
				$rest = new S3Request($this->id,$this->secret,true,'GET', $bucket, '');

				if ($prefix !== null) 
					$rest->setParameter('prefix', $prefix);

				$rest->setParameter('marker', $lastMarker);

				if (($response = $rest->getResponse(true)) == false || $response->code !== 200) 
					break;

				if (isset($response->body, $response->body->Contents))
					foreach ($response->body->Contents as $c) 
					{
						$results[(string)$c->Key] = array(
							'name' => (string)$c->Key,
							'time' => strtotime((string)$c->LastModified),
							'size' => (int)$c->Size,
							'hash' => substr((string)$c->ETag, 1, -1)
						);
						
						$lastMarker = (string)$c->Key;
					}
				} 
				while ($response !== false && (string)$response->body->IsTruncated == 'true');

		return $results;
	}
示例#4
0
 public static function getBucket($bucket, $prefix = null, $marker = null, $maxKeys = null)
 {
     $rest = new S3Request('GET', $bucket, '');
     if ($prefix !== null && $prefix !== '') {
         $rest->setParameter('prefix', $prefix);
     }
     if ($marker !== null && $prefix !== '') {
         $rest->setParameter('marker', $marker);
     }
     if ($maxKeys !== null && $prefix !== '') {
         $rest->setParameter('max-keys', $maxKeys);
     }
     $response = $rest->getResponse();
     if ($response->error === false && $response->code !== 200) {
         $response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status');
     }
     if ($response->error !== false) {
         trigger_error(sprintf("S3::getBucket(): [%s] %s", $response->error['code'], $response->error['message']), E_USER_WARNING);
         return false;
     }
     $results = array();
     $lastMarker = null;
     if (isset($response->body, $response->body->Contents)) {
         foreach ($response->body->Contents as $c) {
             $results[(string) $c->Key] = array('name' => (string) $c->Key, 'time' => strToTime((string) $c->LastModified), 'size' => (int) $c->Size, 'hash' => substr((string) $c->ETag, 1, -1));
             $lastMarker = (string) $c->Key;
             //$response->body->IsTruncated = 'true'; break;
         }
     }
     if (isset($response->body->IsTruncated) && (string) $response->body->IsTruncated == 'false') {
         return $results;
     }
     // Loop through truncated results if maxKeys isn't specified
     if ($maxKeys == null && $lastMarker !== null && (string) $response->body->IsTruncated == 'true') {
         do {
             $rest = new S3Request('GET', $bucket, '');
             if ($prefix !== null) {
                 $rest->setParameter('prefix', $prefix);
             }
             $rest->setParameter('marker', $lastMarker);
             if (($response = $rest->getResponse(true)) == false || $response->code !== 200) {
                 break;
             }
             if (isset($response->body, $response->body->Contents)) {
                 foreach ($response->body->Contents as $c) {
                     $results[(string) $c->Key] = array('name' => (string) $c->Key, 'time' => strToTime((string) $c->LastModified), 'size' => (int) $c->Size, 'hash' => substr((string) $c->ETag, 1, -1));
                     $lastMarker = (string) $c->Key;
                 }
             }
         } while ($response !== false && (string) $response->body->IsTruncated == 'true');
     }
     return $results;
 }
示例#5
0
文件: S3.php 项目: pneff/binarypool
 /**
  * Get object or bucket Access Control Policy
  *
  * Currently this will trigger an error if there is no ACL on an object (will fix soon)
  *
  * @param string $bucket Bucket name
  * @param string $uri Object URI
  * @return mixed | false
  */
 public static function getAccessControlPolicy($bucket, $uri = '')
 {
     $rest = new S3Request('GET', $bucket, $uri);
     $rest->setParameter('acl', null);
     $rest = $rest->getResponse();
     if ($rest->error === false && $rest->code !== 200) {
         $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
     }
     if ($rest->error !== false) {
         throw new S3Exception($rest->error['code'], "Could not get access control policy {$bucket}/{$uri}: " . $rest->error['message']);
         return false;
     }
     $acp = array();
     if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName)) {
         $acp['owner'] = array('id' => (string) $rest->body->Owner->ID, 'name' => (string) $rest->body->Owner->DisplayName);
     }
     if (isset($rest->body->AccessControlList)) {
         $acp['acl'] = array();
         foreach ($rest->body->AccessControlList->Grant as $grant) {
             foreach ($grant->Grantee as $grantee) {
                 if (isset($grantee->ID, $grantee->DisplayName)) {
                     // CanonicalUser
                     $acp['acl'][] = array('type' => 'CanonicalUser', 'id' => (string) $grantee->ID, 'name' => (string) $grantee->DisplayName, 'permission' => (string) $grant->Permission);
                 } elseif (isset($grantee->EmailAddress)) {
                     // AmazonCustomerByEmail
                     $acp['acl'][] = array('type' => 'AmazonCustomerByEmail', 'email' => (string) $grantee->EmailAddress, 'permission' => (string) $grant->Permission);
                 } elseif (isset($grantee->URI)) {
                     // Group
                     $acp['acl'][] = array('type' => 'Group', 'uri' => (string) $grantee->URI, 'permission' => (string) $grant->Permission);
                 } else {
                     continue;
                 }
             }
         }
     }
     return $acp;
 }