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

Class: Services_Amazon_S3

Source Location: /Services_Amazon_S3-0.2.0/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: 0.2.0

Copyright:

  • 2008-2009 Peytz & Co. A/S

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 124]
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');

Iterator 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 141]

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 177]

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

Type:   mixed


[ Top ]

$httpOptions = array('allowRedirects' => true)

[line 155]

Options for HTTP_Request, e.g. proxy server, timeout etc.

NOTE: Some options may interfere with this service.

  • Var: options array for HTTP_Request.
  • See: HTTP_Request::HTTP_Request()
  • Access: public

Type:   array


[ Top ]

$maxKeys =  false

[line 194]

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 201]

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 ]

$requestStyle =
        Services_Amazon_S3_Resource_Bucket::REQUEST_STYLE_VIRTUAL_HOST

[line 167]

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

Type:   string


[ Top ]

$secretAccessKey =

[line 147]

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

Type:   string


[ Top ]

$useSSL =  false

[line 183]

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

Type:   bool


[ Top ]



Method Detail

getAccount   [line 225]

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 240]

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 286]

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 264]

Traversable getBuckets( )

Returns the buckets owned by the current user.
  • Return: traversable collection of Services_Amazon_S3_Resource_Bucket instances
  • Throws: Services_Amazon_S3_Exception
  • Access: public

[ Top ]

getDOMXPath   [line 496]

DOMXPath getDOMXPath( HTTP_Request $request)

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

Parameters:

HTTP_Request   $request   —  a request where $request->sendRequest() has been called successfully

[ Top ]

getRequestSignature   [line 311]

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 252]

string getURL( )

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

[ Top ]

sendRequest   [line 384]

HTTP_Request sendRequest( mixed $resource, [string $subResource = false], [array $query = null], [string $method = HTTP_REQUEST_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 ]

signString   [line 355]

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:31:22 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.