sdb.class.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. <?php
  2. /*
  3. * Copyright 2010-2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. /**
  17. *
  18. *
  19. * Amazon SimpleDB is a web service providing the core database functions of data indexing and querying in the cloud. By offloading the time
  20. * and effort associated with building and operating a web-scale database, SimpleDB provides developers the freedom to focus on application
  21. * development.
  22. *
  23. *
  24. *
  25. * A traditional, clustered relational database requires a sizable upfront capital outlay, is complex to design, and often requires extensive
  26. * and repetitive database administration. Amazon SimpleDB is dramatically simpler, requiring no schema, automatically indexing your data and
  27. * providing a simple API for storage and access. This approach eliminates the administrative burden of data modeling, index maintenance, and
  28. * performance tuning. Developers gain access to this functionality within Amazon's proven computing environment, are able to scale instantly,
  29. * and pay only for what they use.
  30. *
  31. * Visit <a href="http://aws.amazon.com/simpledb/">http://aws.amazon.com/simpledb/</a> for more information.
  32. *
  33. * @version Wed Jul 20 13:20:46 PDT 2011
  34. * @license See the included NOTICE.md file for complete information.
  35. * @copyright See the included NOTICE.md file for complete information.
  36. * @link http://aws.amazon.com/simpledb/Amazon SimpleDB
  37. * @link http://aws.amazon.com/documentation/simpledb/Amazon SimpleDB documentation
  38. */
  39. class AmazonSDB extends CFRuntime
  40. {
  41. /*%******************************************************************************************%*/
  42. // CLASS CONSTANTS
  43. /**
  44. * Specify the default queue URL.
  45. */
  46. const DEFAULT_URL = 'sdb.amazonaws.com';
  47. /**
  48. * Specify the queue URL for the US-East (Northern Virginia) Region.
  49. */
  50. const REGION_US_E1 = self::DEFAULT_URL;
  51. /**
  52. * Specify the queue URL for the US-West (Northern California) Region.
  53. */
  54. const REGION_US_W1 = 'sdb.us-west-1.amazonaws.com';
  55. /**
  56. * Specify the queue URL for the EU (Ireland) Region.
  57. */
  58. const REGION_EU_W1 = 'sdb.eu-west-1.amazonaws.com';
  59. /**
  60. * Specify the queue URL for the Asia Pacific (Singapore) Region.
  61. */
  62. const REGION_APAC_SE1 = 'sdb.ap-southeast-1.amazonaws.com';
  63. /**
  64. * Specify the queue URL for the Asia Pacific (Japan) Region.
  65. */
  66. const REGION_APAC_NE1 = 'sdb.ap-northeast-1.amazonaws.com';
  67. /*%******************************************************************************************%*/
  68. // SETTERS
  69. /**
  70. * This allows you to explicitly sets the region for the service to use.
  71. *
  72. * @param string $region (Required) The region to explicitly set. Available options are <REGION_US_E1>, <REGION_US_W1>, <REGION_EU_W1>, or <REGION_APAC_SE1>.
  73. * @return $this A reference to the current instance.
  74. */
  75. public function set_region($region)
  76. {
  77. $this->set_hostname($region);
  78. return $this;
  79. }
  80. /*%******************************************************************************************%*/
  81. // CONVENIENCE METHODS
  82. /**
  83. * ONLY lists the domains, as an array, on the SimpleDB account.
  84. *
  85. * @param string $pcre (Optional) A Perl-Compatible Regular Expression (PCRE) to filter the names against.
  86. * @return array The list of matching queue names. If there are no results, the method will return an empty array.
  87. * @link http://php.net/pcre Perl-Compatible Regular Expression (PCRE) Docs
  88. */
  89. public function get_domain_list($pcre = null)
  90. {
  91. if ($this->use_batch_flow)
  92. {
  93. throw new SDB_Exception(__FUNCTION__ . '() cannot be batch requested');
  94. }
  95. // Get a list of domains.
  96. $list = $this->list_domains();
  97. if ($list = $list->body->DomainName())
  98. {
  99. $list = $list->map_string($pcre);
  100. return $list;
  101. }
  102. return array();
  103. }
  104. /**
  105. * Remaps the custom item-key-value format used by Batch* operations to the more common ComplexList
  106. * format. Internal use only.
  107. *
  108. * @param array $items (Required) The item-key-value format passed by <batch_put_attributes()> and <batch_delete_attributes()>.
  109. * @param boolean|array $replace (Optional) The `$replace` value passed by <batch_put_attributes()> and <batch_delete_attributes()>.
  110. * @return array A <CFComplexType>-compatible mapping of parameters.
  111. */
  112. public static function remap_batch_items_for_complextype($items, $replace = false)
  113. {
  114. $map = array(
  115. 'Item' => array()
  116. );
  117. foreach ($items as $key => $value)
  118. {
  119. $node = array();
  120. $node['ItemName'] = $key;
  121. if (is_array($value))
  122. {
  123. $node['Attribute'] = array();
  124. foreach ($value as $k => $v)
  125. {
  126. $v = is_array($v) ? $v : array($v);
  127. foreach ($v as $vv)
  128. {
  129. $n = array();
  130. $n['Name'] = $k;
  131. $n['Value'] = $vv;
  132. if (
  133. $replace === (boolean) true ||
  134. (isset($replace[$key]) && array_search($k, $replace[$key], true) !== false)
  135. )
  136. {
  137. $n['Replace'] = 'true';
  138. }
  139. $node['Attribute'][] = $n;
  140. }
  141. }
  142. }
  143. $map['Item'][] = $node;
  144. }
  145. return $map;
  146. }
  147. /**
  148. * Remaps the custom item-key-value format used by Batch* operations to the more common ComplexList
  149. * format. Internal use only.
  150. *
  151. * @param array $keys (Required) The key-value format passed by <put_attributes()>.
  152. * @param boolean|array $replace (Optional) The `$replace` value passed by <batch_put_attributes()> and <batch_delete_attributes()>.
  153. * @return array A <CFComplexType>-compatible mapping of parameters.
  154. */
  155. public static function remap_attribute_items_for_complextype($keys, $replace = false)
  156. {
  157. $map = array(
  158. 'Attribute' => array()
  159. );
  160. foreach ($keys as $k => $v)
  161. {
  162. $v = is_array($v) ? $v : array($v);
  163. foreach ($v as $vv)
  164. {
  165. $n = array();
  166. $n['Name'] = $k;
  167. $n['Value'] = $vv;
  168. if (
  169. $replace === (boolean) true ||
  170. (is_array($replace) && array_search($k, $replace, true) !== false)
  171. )
  172. {
  173. $n['Replace'] = 'true';
  174. }
  175. $map['Attribute'][] = $n;
  176. }
  177. }
  178. return $map;
  179. }
  180. /*%******************************************************************************************%*/
  181. // CONSTRUCTOR
  182. /**
  183. * Constructs a new instance of <AmazonSDB>.
  184. *
  185. * @param string $key (Optional) Your Amazon API Key. If blank, it will look for the <code>AWS_KEY</code> constant.
  186. * @param string $secret_key (Optional) Your Amazon API Secret Key. If blank, it will look for the <code>AWS_SECRET_KEY</code> constant.
  187. * @return boolean false if no valid values are set, otherwise true.
  188. */
  189. public function __construct($key = null, $secret_key = null)
  190. {
  191. $this->api_version = '2009-04-15';
  192. $this->hostname = self::DEFAULT_URL;
  193. if (!$key && !defined('AWS_KEY'))
  194. {
  195. // @codeCoverageIgnoreStart
  196. throw new SDB_Exception('No account key was passed into the constructor, nor was it set in the AWS_KEY constant.');
  197. // @codeCoverageIgnoreEnd
  198. }
  199. if (!$secret_key && !defined('AWS_SECRET_KEY'))
  200. {
  201. // @codeCoverageIgnoreStart
  202. throw new SDB_Exception('No account secret was passed into the constructor, nor was it set in the AWS_SECRET_KEY constant.');
  203. // @codeCoverageIgnoreEnd
  204. }
  205. return parent::__construct($key, $secret_key);
  206. }
  207. /*%******************************************************************************************%*/
  208. // SERVICE METHODS
  209. /**
  210. *
  211. * The <code>Select</code> operation returns a set of attributes for <code>ItemNames</code> that match the select expression.
  212. * <code>Select</code> is similar to the standard SQL SELECT statement.
  213. *
  214. * The total size of the response cannot exceed 1 MB in total size. Amazon SimpleDB automatically adjusts the number of items returned per
  215. * page to enforce this limit. For example, if the client asks to retrieve 2500 items, but each individual item is 10 kB in size, the system
  216. * returns 100 items and an appropriate <code>NextToken</code> so the client can access the next page of results.
  217. *
  218. * For information on how to construct select expressions, see Using Select to Create Amazon SimpleDB Queries in the Developer Guide.
  219. *
  220. * @param string $select_expression (Required) The expression used to query the domain.
  221. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  222. * <li><code>NextToken</code> - <code>string</code> - Optional - A string informing Amazon SimpleDB where to start the next list of <code>ItemNames</code>. </li>
  223. * <li><code>ConsistentRead</code> - <code>boolean</code> - Optional - Determines whether or not strong consistency should be enforced when data is read from SimpleDB. If <code>true</code>, any data previously written to SimpleDB will be returned. Otherwise, results will be consistent eventually, and the client may not see data that was written immediately before your read. </li>
  224. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  225. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  226. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  227. */
  228. public function select($select_expression, $opt = null)
  229. {
  230. if (!$opt) $opt = array();
  231. $opt['SelectExpression'] = $select_expression;
  232. return $this->authenticate('Select', $opt, $this->hostname);
  233. }
  234. /**
  235. * The PutAttributes operation creates or replaces attributes in an item.
  236. *
  237. * A single item can have the attributes <code>{ "first_name", "first_value" }</code> and
  238. * <code>{ "first_name", "second_value" }</code>. However, it cannot have two attribute instances where
  239. * both the attribute name and attribute value are the same. Optionally, the requestor can supply the
  240. * <code>Replace</code> parameter for each individual attribute. Setting this value to true causes the
  241. * new attribute value to replace the existing attribute value(s).
  242. *
  243. * For example, if an item has the attributes <code>{ 'a', '1' }, { 'b', '2'}</code> and <code>{ 'b', '3' }</code>
  244. * and the requestor calls <code>PutAttributes</code> using the attributes <code>{ 'b', '4' }</code> with
  245. * the <code>Replace</code> parameter set to <code>true</code>, the final attributes of the item are changed
  246. * to <code>{ 'a', '1' }</code> and <code>{ 'b', '4' }</code>, which replaces the previous values of the 'b'
  247. * attribute with the new value.
  248. *
  249. * Using PutAttributes to replace attribute values that do not exist will not result in an error
  250. * response.
  251. *
  252. * You cannot specify an empty string as an attribute name.
  253. *
  254. * Because Amazon SimpleDB makes multiple copies of your data and uses an eventual consistency update
  255. * model, an immediate GetAttributes or Select request (read) immediately after a DeleteAttributes
  256. * request (write) might not return the updated data.
  257. *
  258. * The following limitations are enforced for this operation:
  259. *
  260. * <ul>
  261. * <li>256 attribute name-value pairs per item</li>
  262. * <li>1 billion attributes per domain</li>
  263. * <li>10 GB of total user data storage per domain</li>
  264. * </ul>
  265. *
  266. * @param string $domain_name (Required) The name of the domain in which the attributes are being deleted.
  267. * @param string $item_name (Required) The name of the base item which will contain the series of keypairs.
  268. * @param array $keypairs (Required) Associative array of parameters which are treated as key-value and key-multivalue pairs (i.e. a key can have one or more values; think tags). <ul>
  269. * <li><code>[key]</code> - <code>array</code> - Set the custom key name as the key for this value. For the value, pass a string for a single value, or an indexed array for multiple values.</li>
  270. * </ul>
  271. * @param boolean|array $replace (Optional) Whether to replace a key-value pair if a matching key already exists. Supports either a boolean (which affects ALL key-value pairs) or an indexed array of key names (which affects only the keys specified). Defaults to boolean <code>false</code>.
  272. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  273. * <li><code>Expected</code> - <code>array</code> - Optional - The update condition which, if specified, determines if the specified attributes will be updated or not. The update condition must be satisfied in order for this request to be processed and the attributes to be updated. <ul>
  274. * <li><code>Name</code> - <code>string</code> - Optional - The name of the attribute involved in the condition.</li>
  275. * <li><code>Value</code> - <code>string</code> - Optional - The value of an attribute. This value can only be specified when the exists parameter is equal to true.</li>
  276. * <li><code>Exists</code> - <code>string</code> - Optional - True if the specified attribute must exist with the specified value in order for this update condition to be satisfied, otherwise false if the specified attribute should not exist in order for this update condition to be satisfied.</li>
  277. * </ul></li>
  278. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  279. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This is useful for manually-managed batch requests.</li></ul>
  280. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  281. */
  282. public function put_attributes($domain_name, $item_name, $keypairs, $replace = null, $opt = null)
  283. {
  284. if (!$opt) $opt = array();
  285. $opt['DomainName'] = $domain_name;
  286. $opt['ItemName'] = $item_name;
  287. $opt = array_merge($opt, CFComplexType::map(
  288. self::remap_attribute_items_for_complextype($keypairs, $replace)
  289. ));
  290. if (isset($opt['Expected']))
  291. {
  292. $opt = array_merge($opt, CFComplexType::map(array(
  293. 'Expected' => $opt['Expected']
  294. )));
  295. unset($opt['Expected']);
  296. }
  297. return $this->authenticate('PutAttributes', $opt, $this->hostname);
  298. }
  299. /**
  300. * Performs multiple DeleteAttributes operations in a single call, which reduces round trips and latencies.
  301. * This enables Amazon SimpleDB to optimize requests, which generally yields better throughput.
  302. *
  303. * If you specify BatchDeleteAttributes without attributes or values, all the attributes for the item are
  304. * deleted. BatchDeleteAttributes is an idempotent operation; running it multiple times on the same item
  305. * or attribute doesn't result in an error. The BatchDeleteAttributes operation succeeds or fails in its
  306. * entirety. There are no partial deletes.
  307. *
  308. * You can execute multiple BatchDeleteAttributes operations and other operations in parallel. However,
  309. * large numbers of concurrent BatchDeleteAttributes calls can result in Service Unavailable (503) responses.
  310. * This operation does not support conditions using <code>Expected.X.Name</code>, <code>Expected.X.Value</code>,
  311. * or <code>Expected.X.Exists</code>.
  312. *
  313. * The following limitations are enforced for this operation:
  314. *
  315. * <ul>
  316. * <li>1 MB request size</li>
  317. * <li>25 item limit per BatchDeleteAttributes operation</li>
  318. * </ul>
  319. *
  320. * @param string $domain_name (Required) The name of the domain in which the attributes are being deleted.
  321. * @param array $item_keypairs (Required) Associative array of parameters which are treated as item-key-value and item-key-multivalue pairs (i.e. a key can have one or more values; think tags). <ul>
  322. * <li><code>[item]</code> - <code>array</code> - Set the custom item name as the key for this value.<ul>
  323. * <li><code>[key]</code> - <code>array</code> - Set the custom key name as the key for this value. For the value, pass a string for a single value, or an indexed array for multiple values.</li>
  324. * </ul></li>
  325. * </ul>
  326. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  327. * <li><code>Item</code> - <code>array</code> - Optional - A list of items on which to perform the operation. <ul>
  328. * <li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
  329. * <li><code>ItemName</code> - <code>string</code> - Optional - This is the parameter format supported by the web service API. This is the item name to use.</li>
  330. * <li><code>Attribute</code> - <code>array</code> - Optional - This is the parameter format supported by the web service API. This is the attribute node. <ul>
  331. * <li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
  332. * <li><code>Name</code> - <code>string</code> - Required - The name of the attribute. </li>
  333. * <li><code>AlternateNameEncoding</code> - <code>string</code> - Optional - This is the parameter format supported by the web service API. This is the alternate name encoding to use.</li>
  334. * <li><code>Value</code> - <code>string</code> - Required - The value of the attribute. </li>
  335. * <li><code>AlternateValueEncoding</code> - <code>string</code> - Optional - This is the parameter format supported by the web service API. This is the alternate value encoding to use.</li>
  336. * </ul></li>
  337. * </ul></li>
  338. * </ul></li>
  339. * </ul></li>
  340. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  341. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This is useful for manually-managed batch requests.</li></ul>
  342. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  343. */
  344. public function batch_delete_attributes($domain_name, $item_keypairs, $opt = null)
  345. {
  346. if (!$opt) $opt = array();
  347. $opt['DomainName'] = $domain_name;
  348. $opt = array_merge($opt, CFComplexType::map(
  349. self::remap_batch_items_for_complextype($item_keypairs)
  350. ));
  351. if (isset($opt['Item']))
  352. {
  353. $opt = array_merge($opt, CFComplexType::map(array(
  354. 'Item' => $opt['Item']
  355. )));
  356. unset($opt['Item']);
  357. }
  358. return $this->authenticate('BatchDeleteAttributes', $opt, $this->hostname);
  359. }
  360. /**
  361. *
  362. * The <code>DeleteDomain</code> operation deletes a domain. Any items (and their attributes) in the domain are deleted as well. The
  363. * <code>DeleteDomain</code> operation might take 10 or more seconds to complete.
  364. *
  365. * Running <code>DeleteDomain</code> on a domain that does not exist or running the function multiple times using the same domain name will
  366. * not result in an error response.
  367. *
  368. * @param string $domain_name (Required) The name of the domain to delete.
  369. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  370. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  371. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  372. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  373. */
  374. public function delete_domain($domain_name, $opt = null)
  375. {
  376. if (!$opt) $opt = array();
  377. $opt['DomainName'] = $domain_name;
  378. return $this->authenticate('DeleteDomain', $opt, $this->hostname);
  379. }
  380. /**
  381. *
  382. * The <code>CreateDomain</code> operation creates a new domain. The domain name should be unique among the domains associated with the Access
  383. * Key ID provided in the request. The <code>CreateDomain</code> operation may take 10 or more seconds to complete.
  384. *
  385. * CreateDomain is an idempotent operation; running it multiple times using the same domain name will not result in an error response.
  386. *
  387. * The client can create up to 100 domains per account.
  388. *
  389. * If the client requires additional domains, go to <a
  390. * href="http://aws.amazon.com/contact-us/simpledb-limit-request/">http://aws.amazon.com/contact-us/simpledb-limit-request/</a>.
  391. *
  392. * @param string $domain_name (Required) The name of the domain to create. The name can range between 3 and 255 characters and can contain the following characters: a-z, A-Z, 0-9, '_', '-', and '.'.
  393. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  394. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  395. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  396. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  397. */
  398. public function create_domain($domain_name, $opt = null)
  399. {
  400. if (!$opt) $opt = array();
  401. $opt['DomainName'] = $domain_name;
  402. return $this->authenticate('CreateDomain', $opt, $this->hostname);
  403. }
  404. /**
  405. * Deletes one or more attributes associated with the item. If all attributes of an item are deleted,
  406. * the item is deleted.
  407. *
  408. * If you specify DeleteAttributes without attributes or values, all the attributes for the item are
  409. * deleted.
  410. *
  411. * DeleteAttributes is an idempotent operation; running it multiple times on the same item or
  412. * attribute does not result in an error response.
  413. *
  414. * Because Amazon SimpleDB makes multiple copies of your data and uses an eventual consistency update
  415. * model, performing a GetAttributes or Select request (read) immediately after a DeleteAttributes or
  416. * PutAttributes request (write) might not return the updated data.
  417. *
  418. * @param string $domain_name (Required) The name of the domain in which the attributes are being deleted.
  419. * @param string $item_name (Required) The name of the base item which will contain the series of keypairs.
  420. * @param array $attributes (Optional) Similar to columns on a spreadsheet, attributes represent categories of data that can be assigned to items. Takes an associative array of parameters that can have the following keys: <ul>
  421. * <li><code>Attribute</code> - <code>array</code> - Optional - This is the parameter format supported by the web service API. This is the attribute node.<ul>
  422. * <li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
  423. * <li><code>Name</code> - <code>string</code> - Required - The name of the attribute. </li>
  424. * <li><code>AlternateNameEncoding</code> - <code>string</code> - Optional - This is the parameter format supported by the web service API. This is the alternate name encoding to use.</li>
  425. * <li><code>Value</code> - <code>string</code> - Required - The value of the attribute. </li>
  426. * <li><code>AlternateValueEncoding</code> - <code>string</code> - Optional - This is the parameter format supported by the web service API. This is the alternate value encoding to use.</li>
  427. * </ul></li>
  428. * </ul></li></ul>
  429. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  430. * <li><code>Expected</code> - <code>array</code> - Optional - The update condition which, if specified, determines if the specified attributes will be updated or not. The update condition must be satisfied in order for this request to be processed and the attributes to be updated. <ul>
  431. * <li><code>Name</code> - <code>string</code> - Optional - The name of the attribute involved in the condition.</li>
  432. * <li><code>Value</code> - <code>string</code> - Optional - The value of an attribute. This value can only be specified when the exists parameter is equal to true.</li>
  433. * <li><code>Exists</code> - <code>string</code> - Optional - True if the specified attribute must exist with the specified value in order for this update condition to be satisfied, otherwise false if the specified attribute should not exist in order for this update condition to be satisfied.</li>
  434. * </ul></li>
  435. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  436. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This is useful for manually-managed batch requests.</li></ul>
  437. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  438. */
  439. public function delete_attributes($domain_name, $item_name, $attributes = null, $opt = null)
  440. {
  441. if (!$opt) $opt = array();
  442. $opt['DomainName'] = $domain_name;
  443. $opt['ItemName'] = $item_name;
  444. if ($attributes)
  445. {
  446. $opt = array_merge($opt, CFComplexType::map(array(
  447. 'Attribute' => (is_array($attributes) ? $attributes : array($attributes))
  448. )));
  449. }
  450. if (isset($opt['Expected']))
  451. {
  452. $opt = array_merge($opt, CFComplexType::map(array(
  453. 'Expected' => $opt['Expected']
  454. )));
  455. unset($opt['Expected']);
  456. }
  457. return $this->authenticate('DeleteAttributes', $opt, $this->hostname);
  458. }
  459. /**
  460. *
  461. * The <code>ListDomains</code> operation lists all domains associated with the Access Key ID. It returns domain names up to the limit set by
  462. * <a href="#MaxNumberOfDomains">MaxNumberOfDomains</a>. A <a href="#NextToken">NextToken</a> is returned if there are more than
  463. * <code>MaxNumberOfDomains</code> domains. Calling <code>ListDomains</code> successive times with the <code>NextToken</code> provided by the
  464. * operation returns up to <code>MaxNumberOfDomains</code> more domain names with each successive operation call.
  465. *
  466. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  467. * <li><code>MaxNumberOfDomains</code> - <code>integer</code> - Optional - The maximum number of domain names you want returned. The range is 1 to 100. The default setting is 100. </li>
  468. * <li><code>NextToken</code> - <code>string</code> - Optional - A string informing Amazon SimpleDB where to start the next list of domain names. </li>
  469. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  470. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  471. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  472. */
  473. public function list_domains($opt = null)
  474. {
  475. if (!$opt) $opt = array();
  476. return $this->authenticate('ListDomains', $opt, $this->hostname);
  477. }
  478. /**
  479. * Returns all of the attributes associated with the item. Optionally, the attributes returned can be
  480. * limited to one or more specified attribute name parameters.
  481. *
  482. * If the item does not exist on the replica that was accessed for this operation, an empty set is
  483. * returned. The system does not return an error as it cannot guarantee the item does not exist on
  484. * other replicas.
  485. *
  486. * If you specify GetAttributes without any attribute names, all the attributes for the item are
  487. * returned.
  488. *
  489. * @param string $domain_name (Required) The name of the domain in which to perform the operation.
  490. * @param string $item_name (Required) The name of the base item which will contain the series of keypairs.
  491. * @param string|array $attribute_name (Optional) The names of the attributes. Pass a string for a single value, or an indexed array for multiple values.
  492. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  493. * <li><code>ConsistentRead</code> - <code>boolean</code> - Optional - True if strong consistency should be enforced when data is read from SimpleDB, meaning that any data previously written to SimpleDB will be returned. Without specifying this parameter, results will be eventually consistent, and you may not see data that was written immediately before your read.</li>
  494. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  495. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This is useful for manually-managed batch requests.</li></ul>
  496. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  497. */
  498. public function get_attributes($domain_name, $item_name, $attribute_name = null, $opt = null)
  499. {
  500. if (!$opt) $opt = array();
  501. $opt['DomainName'] = $domain_name;
  502. $opt['ItemName'] = $item_name;
  503. if ($attribute_name)
  504. {
  505. $opt = array_merge($opt, CFComplexType::map(array(
  506. 'AttributeName' => (is_array($attribute_name) ? $attribute_name : array($attribute_name))
  507. )));
  508. }
  509. return $this->authenticate('GetAttributes', $opt, $this->hostname);
  510. }
  511. /**
  512. * The BatchPutAttributes operation creates or replaces attributes within one or more items.
  513. *
  514. * Attributes are uniquely identified within an item by their name/value combination. For example, a single item can
  515. * have the attributes <code>{ "first_name", "first_value" }</code> and <code>{"first_name", "second_value" }</code>.
  516. * However, it cannot have two attribute instances where both the item attribute name and item attribute value are
  517. * the same.
  518. *
  519. * Optionally, the requester can supply the <code>Replace</code> parameter for each individual value. Setting this value to
  520. * true will cause the new attribute value to replace the existing attribute value(s). For example, if an item I has the
  521. * attributes <code>{ 'a', '1' }, { 'b', '2'}</code> and <code>{ 'b', '3' }</code> and the requester does a
  522. * <code>BatchPutAttributes</code> of <code>{'I', 'b', '4' }</code> with the <code>Replace</code> parameter set to true,
  523. * the final attributes of the item will be { 'a', '1' } and { 'b', '4' }, replacing the previous values of the 'b'
  524. * attribute with the new value. You cannot specify an empty string as an item or attribute name.
  525. *
  526. * The BatchPutAttributes operation succeeds or fails in its entirety. There are no partial puts. You can execute multiple
  527. * BatchPutAttributes operations and other operations in parallel. However, large numbers of concurrent BatchPutAttributes
  528. * calls can result in Service Unavailable (503) responses. The following limitations are enforced for this operation:
  529. *
  530. * <ul>
  531. * <li>256 attribute name-value pairs per item</li>
  532. * <li>1 MB request size</li>
  533. * <li>1 billion attributes per domain</li>
  534. * <li>10 GB of total user data storage per domain</li>
  535. * <li>25 item limit per BatchPutAttributes operation</li>
  536. * </ul>
  537. *
  538. * @param string $domain_name (Required) The name of the domain in which the attributes are being deleted.
  539. * @param array $item_keypairs (Required) Associative array of parameters which are treated as item-key-value and item-key-multivalue pairs (i.e. a key can have one or more values; think tags). <ul>
  540. * <li><code>[item]</code> - <code>array</code> - Set the custom item name as the key for this value. <ul>
  541. * <li><code>[key]</code> - <code>array</code> - Set the custom key name as the key for this value. For the value, pass a string for a single value, or an indexed array for multiple values.</li>
  542. * </ul></li>
  543. * </ul>
  544. * @param boolean|array $replace (Optional) Whether to replace a key-value pair if a matching key already exists. Supports either a boolean (which affects ALL key-value pairs) or an indexed array of key names (which affects only the keys specified). Defaults to boolean <code>false</code>.
  545. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  546. * <li><code>Item</code> - <code>array</code> - Optional - A list of items on which to perform the operation. <ul>
  547. * <li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
  548. * <li><code>ItemName</code> - <code>string</code> - Optional - This is the parameter format supported by the web service API. This is the item name to use.</li>
  549. * <li><code>Attribute</code> - <code>array</code> - Optional - This is the parameter format supported by the web service API. This is the attribute node. <ul>
  550. * <li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
  551. * <li><code>Name</code> - <code>string</code> - Required - The name of the attribute. </li>
  552. * <li><code>AlternateNameEncoding</code> - <code>string</code> - Optional - This is the parameter format supported by the web service API. This is the alternate name encoding to use.</li>
  553. * <li><code>Value</code> - <code>string</code> - Required - The value of the attribute. </li>
  554. * <li><code>AlternateValueEncoding</code> - <code>string</code> - Optional - This is the parameter format supported by the web service API. This is the alternate value encoding to use.</li>
  555. * </ul></li>
  556. * </ul></li>
  557. * </ul></li>
  558. * </ul></li>
  559. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  560. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This is useful for manually-managed batch requests.</li></ul>
  561. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  562. */
  563. public function batch_put_attributes($domain_name, $item_keypairs, $replace = null, $opt = null)
  564. {
  565. if (!$opt) $opt = array();
  566. $opt['DomainName'] = $domain_name;
  567. $opt = array_merge($opt, CFComplexType::map(
  568. self::remap_batch_items_for_complextype($item_keypairs, $replace)
  569. ));
  570. if (isset($opt['Item']))
  571. {
  572. $opt = array_merge($opt, CFComplexType::map(array(
  573. 'Item' => $opt['Item']
  574. )));
  575. unset($opt['Item']);
  576. }
  577. return $this->authenticate('BatchPutAttributes', $opt, $this->hostname);
  578. }
  579. /**
  580. *
  581. * Returns information about the domain, including when the domain was created, the number of items and attributes in the domain, and the size
  582. * of the attribute names and values.
  583. *
  584. * @param string $domain_name (Required) The name of the domain for which to display the metadata of.
  585. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  586. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  587. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  588. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  589. */
  590. public function domain_metadata($domain_name, $opt = null)
  591. {
  592. if (!$opt) $opt = array();
  593. $opt['DomainName'] = $domain_name;
  594. return $this->authenticate('DomainMetadata', $opt, $this->hostname);
  595. }
  596. }
  597. /*%******************************************************************************************%*/
  598. // EXCEPTIONS
  599. /**
  600. * Default SDB Exception.
  601. */
  602. class SDB_Exception extends Exception {}