web/lib/Zend/Service/Amazon/SimpleDb.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Service_Amazon
    16  * @package    Zend_Service_Amazon
    17  * @subpackage SimpleDb
    17  * @subpackage SimpleDb
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  */
    20  */
    21 
    21 
    22 /**
    22 /**
    23  * @see Zend_Service_Amazon_Abstract
    23  * @see Zend_Service_Amazon_Abstract
    51 
    51 
    52 /**
    52 /**
    53  * @category   Zend
    53  * @category   Zend
    54  * @package    Zend_Service_Amazon
    54  * @package    Zend_Service_Amazon
    55  * @subpackage SimpleDb
    55  * @subpackage SimpleDb
    56  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    56  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    57  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    57  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    58  */
    58  */
    59 class Zend_Service_Amazon_SimpleDb extends Zend_Service_Amazon_Abstract
    59 class Zend_Service_Amazon_SimpleDb extends Zend_Service_Amazon_Abstract
    60 {
    60 {
    61     /* Notes */
    61     /* Notes */
    87     protected $_signatureMethod = 'HmacSHA256';
    87     protected $_signatureMethod = 'HmacSHA256';
    88 
    88 
    89     /**
    89     /**
    90      * Create Amazon SimpleDB client.
    90      * Create Amazon SimpleDB client.
    91      *
    91      *
    92      * @param  string $access_key       Override the default Access Key
    92      * @param string $accessKey       Override the default Access Key
    93      * @param  string $secret_key       Override the default Secret Key
    93      * @param string $secretKey       Override the default Secret Key
    94      * @param  string $region           Sets the AWS Region
       
    95      * @return void
       
    96      */
    94      */
    97     public function __construct($accessKey, $secretKey)
    95     public function __construct($accessKey, $secretKey)
    98     {
    96     {
    99         parent::__construct($accessKey, $secretKey);
    97         parent::__construct($accessKey, $secretKey);
   100         $this->setEndpoint("https://" . $this->_sdbEndpoint);
    98         $this->setEndpoint("https://" . $this->_sdbEndpoint);
   102 
   100 
   103     /**
   101     /**
   104      * Set SimpleDB endpoint to use
   102      * Set SimpleDB endpoint to use
   105      *
   103      *
   106      * @param string|Zend_Uri_Http $endpoint
   104      * @param string|Zend_Uri_Http $endpoint
       
   105      * @throws Zend_Service_Amazon_SimpleDb_Exception
       
   106      * @throws Zend_Uri_Exception
   107      * @return Zend_Service_Amazon_SimpleDb
   107      * @return Zend_Service_Amazon_SimpleDb
   108      */
   108      */
   109     public function setEndpoint($endpoint)
   109     public function setEndpoint($endpoint)
   110     {
   110     {
   111         if(!($endpoint instanceof Zend_Uri_Http)) {
   111         if(!($endpoint instanceof Zend_Uri_Http)) {
   130     }
   130     }
   131 
   131 
   132     /**
   132     /**
   133      * Get attributes API method
   133      * Get attributes API method
   134      *
   134      *
   135      * @param string $domainName Domain name within database
   135      * @param string      $domainName Domain name within database
   136      * @param string
   136      * @param string      $itemName
       
   137      * @param string|null $attributeName
       
   138      * @throws Zend_Service_Amazon_SimpleDb_Exception
       
   139      * @return array
   137      */
   140      */
   138     public function getAttributes(
   141     public function getAttributes(
   139         $domainName, $itemName, $attributeName = null
   142         $domainName, $itemName, $attributeName = null
   140     ) {
   143     ) {
   141         $params               = array();
   144         $params               = array();
   178     /**
   181     /**
   179      * Push attributes
   182      * Push attributes
   180      *
   183      *
   181      * @param  string $domainName
   184      * @param  string $domainName
   182      * @param  string $itemName
   185      * @param  string $itemName
   183      * @param  array|Traverable $attributes
   186      * @param  array|Traversable $attributes
   184      * @param  array $replace
   187      * @param  array $replace
   185      * @return void
   188      * @return void
   186      */
   189      */
   187     public function putAttributes(
   190     public function putAttributes(
   188         $domainName, $itemName, $attributes, $replace = array()
   191         $domainName, $itemName, $attributes, $replace = array()
   305             $data[] = (string)$domain;
   308             $data[] = (string)$domain;
   306         }
   309         }
   307 
   310 
   308         $nextTokenNode = $response->getSimpleXMLDocument()->ListDomainsResult->NextToken;
   311         $nextTokenNode = $response->getSimpleXMLDocument()->ListDomainsResult->NextToken;
   309         $nextToken     = (string)$nextTokenNode;
   312         $nextToken     = (string)$nextTokenNode;
   310         $nextToken     = (trim($nextToken) === '') ? null : $nextToken;
       
   311 
   313 
   312         return new Zend_Service_Amazon_SimpleDb_Page($data, $nextToken);
   314         return new Zend_Service_Amazon_SimpleDb_Page($data, $nextToken);
   313     }
   315     }
   314 
   316 
   315     /**
   317     /**
   423 
   425 
   424     /**
   426     /**
   425      * Quote SDB column or table name
   427      * Quote SDB column or table name
   426      *
   428      *
   427      * Wraps it in ``
   429      * Wraps it in ``
   428      * @param string $name
   430      *
       
   431      * @param  string $name
       
   432      * @throws Zend_Service_Amazon_SimpleDb_Exception
   429      * @return string
   433      * @return string
   430      */
   434      */
   431     public function quoteName($name)
   435     public function quoteName($name)
   432     {
   436     {
   433         if (preg_match('/^[a-z_$][a-z0-9_$-]*$/i', $name) == false) {
   437         if (preg_match('/^[a-z_$][a-z0-9_$-]*$/i', $name) == false) {
   523      * 2. Iterate over the sorted list and append the parameter name (in its
   527      * 2. Iterate over the sorted list and append the parameter name (in its
   524      *    original case) and then its value. Do not URL-encode the parameter
   528      *    original case) and then its value. Do not URL-encode the parameter
   525      *    values before constructing this string. Do not use any separator
   529      *    values before constructing this string. Do not use any separator
   526      *    characters when appending strings.
   530      *    characters when appending strings.
   527      *
   531      *
   528      * @param array  $parameters the parameters for which to get the signature.
   532      * @param array $parameters the parameters for which to get the signature.
   529      * @param string $secretKey  the secret key to use to sign the parameters.
       
   530      *
       
   531      * @return string the signed data.
   533      * @return string the signed data.
   532      */
   534      */
   533     protected function _signParameters(array $paramaters)
   535     protected function _signParameters(array $parameters)
   534     {
   536     {
   535         $data  = "POST\n";
   537         $data  = "POST\n";
   536         $data .= $this->getEndpoint()->getHost() . "\n";
   538         $data .= $this->getEndpoint()->getHost() . "\n";
   537         $data .= "/\n";
   539         $data .= "/\n";
   538 
   540 
   539         uksort($paramaters, 'strcmp');
   541         uksort($parameters, 'strcmp');
   540         unset($paramaters['Signature']);
   542         unset($parameters['Signature']);
   541 
   543 
   542         $arrData = array();
   544         $arrData = array();
   543         foreach ($paramaters as $key => $value) {
   545         foreach ($parameters as $key => $value) {
   544             $value = urlencode($value);
   546             $value = urlencode($value);
   545             $value = str_replace("%7E", "~", $value);
   547             $value = str_replace("%7E", "~", $value);
   546             $value = str_replace("+", "%20", $value);
   548             $value = str_replace("+", "%20", $value);
   547             $arrData[] = urlencode($key) . '=' . $value;
   549             $arrData[] = urlencode($key) . '=' . $value;
   548         }
   550         }
   558     /**
   560     /**
   559      * Checks for errors responses from Amazon
   561      * Checks for errors responses from Amazon
   560      *
   562      *
   561      * @param Zend_Service_Amazon_SimpleDb_Response $response the response object to
   563      * @param Zend_Service_Amazon_SimpleDb_Response $response the response object to
   562      *                                                   check.
   564      *                                                   check.
   563      *
       
   564      * @return void
       
   565      *
       
   566      * @throws Zend_Service_Amazon_SimpleDb_Exception if one or more errors are
   565      * @throws Zend_Service_Amazon_SimpleDb_Exception if one or more errors are
   567      *         returned from Amazon.
   566      *         returned from Amazon.
   568      */
   567      */
   569     private function _checkForErrors(Zend_Service_Amazon_SimpleDb_Response $response)
   568     private function _checkForErrors(Zend_Service_Amazon_SimpleDb_Response $response)
   570     {
   569     {