Services_Amazon_S3
[ class tree: Services_Amazon_S3 ] [ index: Services_Amazon_S3 ] [ all elements ]

Class: Services_Amazon_S3

Source Location: /Services_Amazon_S3-0.4.0/Services/Amazon/S3.php

Class Overview


The main S3 class contains the credentials used for accessing the S3 service and is a starting point for accessing the storage service.


Author(s):

Version:

  • Release: @release-version@

Copyright:

  • 2008-2009 Peytz & Co. A/S

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 126]
The main S3 class contains the credentials used for accessing the S3 service and is a starting point for accessing the storage service.

Sample usage:

  1.  require_once 'Services/Amazon/S3.php';
  2.  // Replace with your own credentials
  3.  $accessKeyId '0PN5J17HBGZHT7JJ3X82';
  4.  $secretAccessKey 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o';
  5.  $s3 Services_Amazon_S3::getAccount($accessKeyId$secretAccessKey);

The S3 account instance can now be used to list the buckets owned by this account. A bucket is a file container similar to a filesystem directory, except that it cannot contain subdirectories.

  1.  foreach ($s3->getBuckets(as $bucket{
  2.      print '<li>' htmlspecialchars($bucket->name'</li>';
  3.  }

Get a specific bucket:

  1.  $bucket $s3->getBucket('foobar');

Iterate over the objects (files) in a bucket:

  1.  foreach ($bucket->getObjects(as $object{
  2.      print '<li>' htmlspecialchars($object->key'</li>';
  3.  }

Fetch a specific object:

  1.  $object $bucket->getObject('foo.gif');
  2.  $object->load();
  3.  $img imagecreatefromstring($object->data);

Save an object with public read access:

  1.  require_once 'Services/Amazon/S3/AccessControlList.php';
  2.  $object $bucket->getObject('foo.txt');
  3.  $object->acl = Services_Amazon_S3_AccessControlList::ACL_PUBLIC_READ;
  4.  $object->data = 'lorem ipsum dolor sit amet';
  5.  $object->save();



[ Top ]


Class Variables

$accessKeyId =

[line 148]

Amazon Web Services Access Key ID.
  • Var: 20-character, alphanumeric string, or false if this is an anonymous account
  • Access: public

Type:   string|bool


[ Top ]

$endpoint =  's3.amazonaws.com'

[line 185]

The hostname of the endpoint used for requests done by this class and requests for buckets done with REQUEST_STYLE_VIRTUAL_HOST and REQUEST_STYLE_PATH. This value may be specified per bucket using $bucket->endpoint.

Type:   mixed


[ Top ]

$httpConfig = array('follow_redirects' => true)

[line 162]

Configuration parameters for HTTP_Request2, e.g. proxy server, timeout etc. NOTE: Some options may interfere with this service.
  • Var: configuration array for HTTP_Request2.
  • See: HTTP_Request2::HTTP_Request2()
  • Access: public

Type:   array


[ Top ]

$maxKeys =  false

[line 202]

Maximum number of keys to fetch per request when iterating over the objects of a bucket. A low value will result in more requests to the serve. This value may be specified on the iterator using $iterator->maxKeys.

Type:   int|false


[ Top ]

$maxRetries =  2

[line 209]

Maximum number of retries to make if a request fails with a 500 Internal server error, or if a transport-level error occurs.
  • Var: a non-negative integer, 0 means do not retry
  • Access: public

Type:   int


[ Top ]

$request =  null

[line 221]

Object used to make HTTP requests for the S3 REST API.

Type:   HTTP_Request2


[ Top ]

$requestStyle =  Services_Amazon_S3_Resource_Bucket::REQUEST_STYLE_VIRTUAL_HOST

[line 174]

The default method for accessing buckets. This value may be specified per bucket using $bucket->requestStyle.

Type:   string


[ Top ]

$secretAccessKey =

[line 154]

Amazon Web Services Secret Access Key.
  • Var: 40-character string
  • Access: public

Type:   string


[ Top ]

$useSSL =  false

[line 191]

Whether connections should be made using HTTPS.
  • Access: public

Type:   bool


[ Top ]



Method Detail

getAccount   [line 269]

Services_Amazon_S3 getAccount( string $accessKeyId, string $secretAccessKey)

Returns an account instance with the specified credentials. This may be used to access resources owned by this account as well as resources owned by other accounts that have permissions granted to this account or to the authenticated users group.

Parameters:

string   $accessKeyId   —  Amazon Web Services Access Key ID (20-character, alphanumeric string)
string   $secretAccessKey   —  Amazon Web Services Secret Access Key (40-character string)

[ Top ]

getAnonymousAccount   [line 287]

Services_Amazon_S3 getAnonymousAccount( )

Returns an unauthorized account instance. This can be used to access resources that have permissions granted to anonymous users.

[ Top ]

getBucket   [line 344]

Services_Amazon_S3_Resource_Bucket getBucket( string $name)

Returns the buckets with the specified name.
  • Access: public

Parameters:

string   $name   —  the bucket name (UTF-8)

[ Top ]

getBuckets   [line 319]

Traversable getBuckets( )

Returns the buckets owned by the current user.

[ Top ]

getDOMXPath   [line 596]

DOMXPath getDOMXPath( HTTP_Request2_Response $response)

Returns a DOMXPath object for the XML document in the body of the specified HTTP response. This method is for internal use only.
  • Throws: Services_Amazon_S3_ServerErrorException
  • Access: public

Parameters:

HTTP_Request2_Response   $response   —  the HTTP response.

[ Top ]

getRequestSignature   [line 373]

string getRequestSignature( string $method, mixed $resource, string $subResource, array $headers)

Signs the specified request with the secret key and returns the request signature used by Services_Amazon_S3::sendRequest and Services_Amazon_S3_Resource_Bucket::getSignedUrl().

Parameters:

string   $method   —  HTTP method - "GET", "PUT", or "DELETE"
mixed   $resource   —  an instance of Services_Amazon_S3 or Services_Amazon_S3_Resource
string   $subResource   —  e.g. "?acl", "?location", or "?torrent" (including the question mark)
array   $headers   —  associative array of HTTP request headers - the "date" header is mandatory, "content-md5" and "content-type" are optional. All keys must be in lowercase.

[ Top ]

getURL   [line 302]

string getURL( )

Returns the base URL of this resource.
  • Return: an absolute URL
  • Access: public

[ Top ]

sendRequest   [line 466]

HTTP_Request2_Response sendRequest( mixed $resource, [string $subResource = false], [array $query = null], [string $method = HTTP_Request2::METHOD_GET], [array $headers = array()], [string $body = false])

Sends the specified request to the server. This method is for internal use only.
  • Throws: Services_Amazon_S3_Exception
  • Access: public

Parameters:

mixed   $resource   —  an instance of Services_Amazon_S3 or Services_Amazon_S3_Resource
string   $subResource   —  e.g. "?acl", "?location", or "?torrent" (including the question mark)
array   $query   —  additional query string parameters
string   $method   —  HTTP method - "GET", "PUT", or "DELETE"
array   $headers   —  associative array of HTTP request headers, all keys must be in lowercase
string   $body   —  HTTP request body for PUT requests

[ Top ]

setRequest   [line 247]

void setRequest( HTTP_Request2 $request)

Sets the HTTP request object to use

Can be used to mock requests for testing.

  • Access: public

Parameters:

HTTP_Request2   $request   —  the HTTP request object to use.

[ Top ]

signString   [line 430]

string signString( string $stringToSign)

Signs the specified string with the secret key.
  • Return: a 28 character string.
  • Throws: Services_Amazon_S3_Exception if this is an anonymous account
  • Access: public

Parameters:

string   $stringToSign   —  UTF-8

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:49:39 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.