NOTE: For Version 3 of the AWS SDK for PHP, please see the V3 User Guide and V3 API Reference.

# Class SignatureV4

Signature Version 4

  Aws\Common\Signature\AbstractSignature implements Aws\Common\Signature\SignatureInterface
  Aws\Common\Signature\SignatureV4 implements Aws\Common\Signature\EndpointSignatureInterface

### Direct known subclasses

`Aws\S3\S3SignatureV4`

Namespace: Aws\Common\Signature
Link: http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html
Located at Aws/Common/Signature/SignatureV4.php

## Methods summary

- `public` `__construct ( string $serviceName = null, string $regionName = null )`
- `public` `setServiceName ( string $service )`

  Set the service name instead of inferring it from a request URL

- `public` `setRegionName ( string $region )`

  Set the region name instead of inferring it from a request URL

- `public` `setMaxCacheSize ( int $maxCacheSize )`

  Set the maximum number of computed hashes to cache

- `public` `signRequest ( Guzzle\Http\Message\RequestInterface $request, Aws\Common\Credentials\CredentialsInterface $credentials )`

  Signs the specified request with an AWS signing protocol by using the provided AWS account credentials and adding the required headers to the request.

- `public` `createPresignedUrl ( Guzzle\Http\Message\RequestInterface $request, Aws\Common\Credentials\CredentialsInterface $credentials, int|string|\DateTime $expires )`
- `public static` `convertPostToGet ( Guzzle\Http\Message\EntityEnclosingRequestInterface $request )`

  Converts a POST request to a GET request by moving POST fields into the query string.

- `protected` `getPayload ( Guzzle\Http\Message\RequestInterface $request )`

  Get the payload part of a signature from a request.

- `protected` `getPresignedPayload ( Guzzle\Http\Message\RequestInterface $request )`

  Get the payload of a request for use with pre-signed URLs.

- `protected` `createCanonicalizedPath ( Guzzle\Http\Message\RequestInterface $request )`

## Methods detail

# `public`
`__construct( string $serviceName = null, string $regionName = null )`

#### Parameters

$serviceName
  `string`
  $serviceName Bind the signing to a particular service name
$regionName
  `string`
  $regionName Bind the signing to a particular region name

# `public `Aws\Common\Signature\SignatureV4``
`setServiceName( string $service )`

Set the service name instead of inferring it from a request URL

#### Parameters

$service
  `string`
  $service Name of the service used when signing

#### Returns

``Aws\Common\Signature\SignatureV4``

#### Implementation of

`Aws\Common\Signature\EndpointSignatureInterface::setServiceName()`
# `public `Aws\Common\Signature\SignatureV4``
`setRegionName( string $region )`

Set the region name instead of inferring it from a request URL

#### Parameters

$region
  `string`
  $region Name of the region used when signing

#### Returns

``Aws\Common\Signature\SignatureV4``

#### Implementation of

`Aws\Common\Signature\EndpointSignatureInterface::setRegionName()`
# `public `Aws\Common\Signature\SignatureV4``
`setMaxCacheSize( integer $maxCacheSize )`

Set the maximum number of computed hashes to cache

#### Parameters

$maxCacheSize
  `integer`
  $maxCacheSize Maximum number of hashes to cache

#### Returns

``Aws\Common\Signature\SignatureV4``
# `public`
`signRequest( `Guzzle\Http\Message\RequestInterface` $request, `Aws\Common\Credentials\CredentialsInterface` $credentials )`

Signs the specified request with an AWS signing protocol by using the provided AWS account credentials and adding the required headers to the request.

#### Parameters

$request
  ``Guzzle\Http\Message\RequestInterface``
  $request Request to add a signature to
$credentials
  ``Aws\Common\Credentials\CredentialsInterface``
  $credentials Signing credentials

#### Implementation of

`Aws\Common\Signature\SignatureInterface::signRequest()`
# `public string`
`createPresignedUrl( `Guzzle\Http\Message\RequestInterface` $request, `Aws\Common\Credentials\CredentialsInterface` $credentials, integer|string|`DateTime` $expires )`

#### Parameters

$request
  ``Guzzle\Http\Message\RequestInterface``
  $request Request to sign
$credentials
  ``Aws\Common\Credentials\CredentialsInterface``
  $credentials Credentials used to sign
$expires
  `integer|string|`DateTime``
  $expires The time at which the URL should expire. This can be a Unix timestamp, a PHP DateTime object, or a string that can be evaluated by strtotime

#### Returns

`string`

#### CodeCoverageIgnore

#### Overrides

`Aws\Common\Signature\AbstractSignature::createPresignedUrl`

#### Implementation of

`Aws\Common\Signature\SignatureInterface::createPresignedUrl()`
# `public static `Guzzle\Http\Message\RequestInterface``
`convertPostToGet( `Guzzle\Http\Message\EntityEnclosingRequestInterface` $request )`

Converts a POST request to a GET request by moving POST fields into the query string.

Useful for pre-signing query protocol requests.

#### Parameters

$request
  ``Guzzle\Http\Message\EntityEnclosingRequestInterface``
  $request Request to clone

#### Returns

``Guzzle\Http\Message\RequestInterface``

#### Throws

``InvalidArgumentException``
if the method is not POST
# `protected string`
`getPayload( `Guzzle\Http\Message\RequestInterface` $request )`

Get the payload part of a signature from a request.

#### Parameters

$request
  ``Guzzle\Http\Message\RequestInterface``
  $request

#### Returns

`string`
# `protected string`
`getPresignedPayload( `Guzzle\Http\Message\RequestInterface` $request )`

Get the payload of a request for use with pre-signed URLs.

#### Parameters

$request
  ``Guzzle\Http\Message\RequestInterface``
  $request

#### Returns

`string`
# `protected`
`createCanonicalizedPath( `Guzzle\Http\Message\RequestInterface` $request )`

### Methods inherited from Aws\Common\Signature\AbstractSignature

`getTimestamp()`

### Magic methods summary

## Constants summary

`string` | `DEFAULT_PAYLOAD` | `'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'` | # Cache of the default empty entity-body payload

## Properties summary

`protected string` | $serviceName | # Explicitly set service name
`protected string` | $regionName | # Explicitly set region name
`protected integer` | $maxCacheSize | # Maximum number of hashes to cache
`protected array` | $hashCache | # Cache of previously signed values
`protected integer` | $cacheSize | # Size of the hash cache