Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 * Copyright 2010-2012 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
 * Amazon SimpleDB is a web service providing the core database functions of data indexing and
19
 * querying in the cloud. By offloading the time and effort associated with building and operating
20
 * a web-scale database, SimpleDB provides developers the freedom to focus on application
21
 * development.
22
 *
23
 * A traditional, clustered relational database requires a sizable upfront capital outlay, is
24
 * complex to design, and often requires extensive and repetitive database administration. Amazon
25
 * SimpleDB is dramatically simpler, requiring no schema, automatically indexing your data and
26
 * providing a simple API for storage and access. This approach eliminates the administrative
27
 * burden of data modeling, index maintenance, and performance tuning. Developers gain access to
28
 * 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
32
 * information.
33
 *
34
 * @version 2012.01.16
35
 * @license See the included NOTICE.md file for complete information.
36
 * @copyright See the included NOTICE.md file for complete information.
37
 * @link http://aws.amazon.com/simpledb/ Amazon SimpleDB
38
 * @link http://aws.amazon.com/simpledb/documentation/ Amazon SimpleDB documentation
39
 */
40
class AmazonSDB extends CFRuntime
41
{
42
	/*%******************************************************************************************%*/
43
	// CLASS CONSTANTS
44
 
45
	/**
46
	 * Specify the queue URL for the United States East (Northern Virginia) Region.
47
	 */
48
	const REGION_US_E1 = 'sdb.amazonaws.com';
49
 
50
	/**
51
	 * Specify the queue URL for the United States East (Northern Virginia) Region.
52
	 */
53
	const REGION_VIRGINIA = self::REGION_US_E1;
54
 
55
	/**
56
	 * Specify the queue URL for the United States West (Northern California) Region.
57
	 */
58
	const REGION_US_W1 = 'sdb.us-west-1.amazonaws.com';
59
 
60
	/**
61
	 * Specify the queue URL for the United States West (Northern California) Region.
62
	 */
63
	const REGION_CALIFORNIA = self::REGION_US_W1;
64
 
65
	/**
66
	 * Specify the queue URL for the United States West (Oregon) Region.
67
	 */
68
	const REGION_US_W2 = 'sdb.us-west-2.amazonaws.com';
69
 
70
	/**
71
	 * Specify the queue URL for the United States West (Oregon) Region.
72
	 */
73
	const REGION_OREGON = self::REGION_US_W2;
74
 
75
	/**
76
	 * Specify the queue URL for the Europe West (Ireland) Region.
77
	 */
78
	const REGION_EU_W1 = 'sdb.eu-west-1.amazonaws.com';
79
 
80
	/**
81
	 * Specify the queue URL for the Europe West (Ireland) Region.
82
	 */
83
	const REGION_IRELAND = self::REGION_EU_W1;
84
 
85
	/**
86
	 * Specify the queue URL for the Asia Pacific Southeast (Singapore) Region.
87
	 */
88
	const REGION_APAC_SE1 = 'sdb.ap-southeast-1.amazonaws.com';
89
 
90
	/**
91
	 * Specify the queue URL for the Asia Pacific Southeast (Singapore) Region.
92
	 */
93
	const REGION_SINGAPORE = self::REGION_APAC_SE1;
94
 
95
	/**
96
	 * Specify the queue URL for the Asia Pacific Northeast (Tokyo) Region.
97
	 */
98
	const REGION_APAC_NE1 = 'sdb.ap-northeast-1.amazonaws.com';
99
 
100
	/**
101
	 * Specify the queue URL for the Asia Pacific Northeast (Tokyo) Region.
102
	 */
103
	const REGION_TOKYO = self::REGION_APAC_NE1;
104
 
105
	/**
106
	 * Specify the queue URL for the South America (Sao Paulo) Region.
107
	 */
108
	const REGION_SA_E1 = 'sdb.sa-east-1.amazonaws.com';
109
 
110
	/**
111
	 * Specify the queue URL for the South America (Sao Paulo) Region.
112
	 */
113
	const REGION_SAO_PAULO = self::REGION_SA_E1;
114
 
115
	/**
116
	 * Default service endpoint.
117
	 */
118
	const DEFAULT_URL = self::REGION_US_E1;
119
 
120
 
121
	/*%******************************************************************************************%*/
122
	// CONSTRUCTOR
123
 
124
	/**
125
	 * Constructs a new instance of <AmazonSDB>.
126
	 *
127
	 * @param array $options (Optional) An associative array of parameters that can have the following keys: <ul>
128
	 * 	<li><code>certificate_authority</code> - <code>boolean</code> - Optional - Determines which Cerificate Authority file to use. A value of boolean <code>false</code> will use the Certificate Authority file available on the system. A value of boolean <code>true</code> will use the Certificate Authority provided by the SDK. Passing a file system path to a Certificate Authority file (chmodded to <code>0755</code>) will use that. Leave this set to <code>false</code> if you're not sure.</li>
129
	 * 	<li><code>credentials</code> - <code>string</code> - Optional - The name of the credential set to use for authentication.</li>
130
	 * 	<li><code>default_cache_config</code> - <code>string</code> - Optional - This option allows a preferred storage type to be configured for long-term caching. This can be changed later using the <set_cache_config()> method. Valid values are: <code>apc</code>, <code>xcache</code>, or a file system path such as <code>./cache</code> or <code>/tmp/cache/</code>.</li>
131
	 * 	<li><code>key</code> - <code>string</code> - Optional - Your AWS key, or a session key. If blank, the default credential set will be used.</li>
132
	 * 	<li><code>secret</code> - <code>string</code> - Optional - Your AWS secret key, or a session secret key. If blank, the default credential set will be used.</li>
133
	 * 	<li><code>token</code> - <code>string</code> - Optional - An AWS session token.</li></ul>
134
	 * @return void
135
	 */
136
	public function __construct(array $options = array())
137
	{
138
		$this->api_version = '2009-04-15';
139
		$this->hostname = self::DEFAULT_URL;
140
		$this->auth_class = 'AuthV2Query';
141
 
142
		return parent::__construct($options);
143
	}
144
 
145
 
146
	/*%******************************************************************************************%*/
147
	// SETTERS
148
 
149
	/**
150
	 * This allows you to explicitly sets the region for the service to use.
151
	 *
152
	 * @param string $region (Required) The region to explicitly set. Available options are <REGION_US_E1>, <REGION_US_W1>, <REGION_US_W2>, <REGION_EU_W1>, <REGION_APAC_SE1>, <REGION_APAC_NE1>, <REGION_SA_E1>.
153
	 * @return $this A reference to the current instance.
154
	 */
155
	public function set_region($region)
156
	{
157
		// @codeCoverageIgnoreStart
158
		$this->set_hostname($region);
159
		return $this;
160
		// @codeCoverageIgnoreEnd
161
	}
162
 
163
 
164
	/*%******************************************************************************************%*/
165
	// CONVENIENCE METHODS
166
 
167
	/**
168
	 * ONLY lists the domains, as an array, on the SimpleDB account.
169
	 *
170
	 * @param string $pcre (Optional) A Perl-Compatible Regular Expression (PCRE) to filter the names against.
171
	 * @return array The list of matching queue names. If there are no results, the method will return an empty array.
172
	 * @link http://php.net/pcre Perl-Compatible Regular Expression (PCRE) Docs
173
	 */
174
	public function get_domain_list($pcre = null)
175
	{
176
		if ($this->use_batch_flow)
177
		{
178
			throw new SDB_Exception(__FUNCTION__ . '() cannot be batch requested');
179
		}
180
 
181
		// Get a list of domains.
182
		$list = $this->list_domains();
183
		if ($list = $list->body->DomainName())
184
		{
185
			$list = $list->map_string($pcre);
186
			return $list;
187
		}
188
 
189
		return array();
190
	}
191
 
192
	/**
193
	 * Remaps the custom item-key-value format used by Batch* operations to the more common ComplexList
194
	 * format. Internal use only.
195
	 *
196
	 * @param array $items (Required) The item-key-value format passed by <batch_put_attributes()> and <batch_delete_attributes()>.
197
	 * @param boolean|array $replace (Optional) The `$replace` value passed by <batch_put_attributes()> and <batch_delete_attributes()>.
198
	 * @return array A <CFComplexType>-compatible mapping of parameters.
199
	 */
200
	public static function remap_batch_items_for_complextype($items, $replace = false)
201
	{
202
		$map = array(
203
			'Item' => array()
204
		);
205
 
206
		foreach ($items as $key => $value)
207
		{
208
			$node = array();
209
			$node['ItemName'] = $key;
210
 
211
			if (is_array($value))
212
			{
213
				$node['Attribute'] = array();
214
 
215
				foreach ($value as $k => $v)
216
				{
217
					$v = is_array($v) ? $v : array($v);
218
 
219
					foreach ($v as $vv)
220
					{
221
						$n = array();
222
						$n['Name'] = $k;
223
						$n['Value'] = $vv;
224
 
225
						if (
226
							$replace === (boolean) true ||
227
							(isset($replace[$key]) && array_search($k, $replace[$key], true) !== false)
228
						)
229
						{
230
							$n['Replace'] = 'true';
231
						}
232
 
233
						$node['Attribute'][] = $n;
234
					}
235
				}
236
			}
237
 
238
			$map['Item'][] = $node;
239
		}
240
 
241
		return $map;
242
	}
243
 
244
	/**
245
	 * Remaps the custom item-key-value format used by Batch* operations to the more common ComplexList
246
	 * format. Internal use only.
247
	 *
248
	 * @param array $keys (Required) The key-value format passed by <put_attributes()>.
249
	 * @param boolean|array $replace (Optional) The `$replace` value passed by <batch_put_attributes()> and <batch_delete_attributes()>.
250
	 * @return array A <CFComplexType>-compatible mapping of parameters.
251
	 */
252
	public static function remap_attribute_items_for_complextype($keys, $replace = false)
253
	{
254
		$map = array(
255
			'Attribute' => array()
256
		);
257
 
258
		foreach ($keys as $k => $v)
259
		{
260
			$v = is_array($v) ? $v : array($v);
261
 
262
			foreach ($v as $vv)
263
			{
264
				$n = array();
265
				$n['Name'] = $k;
266
				$n['Value'] = $vv;
267
 
268
				if (
269
					$replace === (boolean) true ||
270
					(is_array($replace) && array_search($k, $replace, true) !== false)
271
				)
272
				{
273
					$n['Replace'] = 'true';
274
				}
275
 
276
				$map['Attribute'][] = $n;
277
			}
278
		}
279
 
280
		return $map;
281
	}
282
 
283
 
284
	/*%******************************************************************************************%*/
285
	// SERVICE METHODS
286
 
287
	/**
288
	 * Performs multiple DeleteAttributes operations in a single call, which reduces round trips and latencies.
289
	 * This enables Amazon SimpleDB to optimize requests, which generally yields better throughput.
290
	 *
291
	 * If you specify BatchDeleteAttributes without attributes or values, all the attributes for the item are
292
	 * deleted. BatchDeleteAttributes is an idempotent operation; running it multiple times on the same item
293
	 * or attribute doesn't result in an error. The BatchDeleteAttributes operation succeeds or fails in its
294
	 * entirety. There are no partial deletes.
295
	 *
296
	 * You can execute multiple BatchDeleteAttributes operations and other operations in parallel. However,
297
	 * large numbers of concurrent BatchDeleteAttributes calls can result in Service Unavailable (503) responses.
298
	 * This operation does not support conditions using <code>Expected.X.Name</code>, <code>Expected.X.Value</code>,
299
	 * or <code>Expected.X.Exists</code>.
300
	 *
301
	 * The following limitations are enforced for this operation:
302
	 *
303
	 * <ul>
304
	 * 	<li>1 MB request size</li>
305
	 * 	<li>25 item limit per BatchDeleteAttributes operation</li>
306
	 * </ul>
307
	 *
308
	 * @param string $domain_name (Required) The name of the domain in which the attributes are being deleted.
309
	 * @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>
310
	 * 	<li><code>[item]</code> - <code>array</code> - Set the custom item name as the key for this value.<ul>
311
	 * 		<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>
312
	 * 	</ul></li>
313
	 * </ul>
314
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
315
	 * 	<li><code>Item</code> - <code>array</code> - Optional - A list of items on which to perform the operation. <ul>
316
	 * 		<li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
317
	 * 			<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>
318
	 * 			<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>
319
	 * 				<li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
320
	 * 					<li><code>Name</code> - <code>string</code> - Required - The name of the attribute. </li>
321
	 * 					<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>
322
	 * 					<li><code>Value</code> - <code>string</code> - Required - The value of the attribute. </li>
323
	 * 					<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>
324
	 * 				</ul></li>
325
	 * 			</ul></li>
326
	 * 		</ul></li>
327
	 * 	</ul></li>
328
	 * 	<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>
329
	 *  <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>
330
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
331
	 */
332
	public function batch_delete_attributes($domain_name, $item_keypairs, $opt = null)
333
	{
334
		if (!$opt) $opt = array();
335
		$opt['DomainName'] = $domain_name;
336
 
337
		$opt = array_merge($opt, CFComplexType::map(
338
			self::remap_batch_items_for_complextype($item_keypairs)
339
		));
340
 
341
		if (isset($opt['Item']))
342
		{
343
			$opt = array_merge($opt, CFComplexType::map(array(
344
				'Item' => $opt['Item']
345
			)));
346
			unset($opt['Item']);
347
		}
348
 
349
		return $this->authenticate('BatchDeleteAttributes', $opt, $this->hostname);
350
	}
351
 
352
	/**
353
	 * The BatchPutAttributes operation creates or replaces attributes within one or more items.
354
	 *
355
	 * Attributes are uniquely identified within an item by their name/value combination. For example, a single item can
356
	 * have the attributes <code>{ "first_name", "first_value" }</code> and <code>{"first_name", "second_value" }</code>.
357
	 * However, it cannot have two attribute instances where both the item attribute name and item attribute value are
358
	 * the same.
359
	 *
360
	 * Optionally, the requester can supply the <code>Replace</code> parameter for each individual value. Setting this value to
361
	 * true will cause the new attribute value to replace the existing attribute value(s). For example, if an item I has the
362
	 * attributes <code>{ 'a', '1' }, { 'b', '2'}</code> and <code>{ 'b', '3' }</code> and the requester does a
363
	 * <code>BatchPutAttributes</code> of <code>{'I', 'b', '4' }</code> with the <code>Replace</code> parameter set to true,
364
	 * the final attributes of the item will be { 'a', '1' } and { 'b', '4' }, replacing the previous values of the 'b'
365
	 * attribute with the new value. You cannot specify an empty string as an item or attribute name.
366
	 *
367
	 * The BatchPutAttributes operation succeeds or fails in its entirety. There are no partial puts. You can execute multiple
368
	 * BatchPutAttributes operations and other operations in parallel. However, large numbers of concurrent BatchPutAttributes
369
	 * calls can result in Service Unavailable (503) responses. The following limitations are enforced for this operation:
370
	 *
371
	 * <ul>
372
	 * 	<li>256 attribute name-value pairs per item</li>
373
	 * 	<li>1 MB request size</li>
374
	 * 	<li>1 billion attributes per domain</li>
375
	 * 	<li>10 GB of total user data storage per domain</li>
376
	 * 	<li>25 item limit per BatchPutAttributes operation</li>
377
	 * </ul>
378
	 *
379
	 * @param string $domain_name (Required) The name of the domain in which the attributes are being deleted.
380
	 * @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>
381
	 * 	<li><code>[item]</code> - <code>array</code> - Set the custom item name as the key for this value.<ul>
382
	 * 		<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></ul>
383
	 * 	</li></ul>
384
	 * @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>.
385
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
386
	 * 	<li><code>Item</code> - <code>array</code> - Optional - A list of items on which to perform the operation. <ul>
387
	 * 		<li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
388
	 * 			<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>
389
	 * 			<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>
390
	 * 				<li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
391
	 * 					<li><code>Name</code> - <code>string</code> - Required - The name of the attribute. </li>
392
	 * 					<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>
393
	 * 					<li><code>Value</code> - <code>string</code> - Required - The value of the attribute. </li>
394
	 * 					<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>
395
	 * 				</ul></li>
396
	 * 			</ul></li>
397
	 * 		</ul></li>
398
	 * 	</ul></li>
399
	 * 	<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>
400
	 *  <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>
401
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
402
	 */
403
	public function batch_put_attributes($domain_name, $item_keypairs, $replace = null, $opt = null)
404
	{
405
		if (!$opt) $opt = array();
406
		$opt['DomainName'] = $domain_name;
407
 
408
		$opt = array_merge($opt, CFComplexType::map(
409
			self::remap_batch_items_for_complextype($item_keypairs, $replace)
410
		));
411
 
412
		if (isset($opt['Item']))
413
		{
414
			$opt = array_merge($opt, CFComplexType::map(array(
415
				'Item' => $opt['Item']
416
			)));
417
			unset($opt['Item']);
418
		}
419
 
420
		return $this->authenticate('BatchPutAttributes', $opt, $this->hostname);
421
	}
422
 
423
	/**
424
	 * The <code>CreateDomain</code> operation creates a new domain. The domain name should be unique
425
	 * among the domains associated with the Access Key ID provided in the request. The
426
	 * <code>CreateDomain</code> operation may take 10 or more seconds to complete.
427
	 *
428
	 * <p class="note">
429
	 * CreateDomain is an idempotent operation; running it multiple times using the same domain name
430
	 * will not result in an error response.
431
	 * </p>
432
	 * The client can create up to 100 domains per account.
433
	 *
434
	 * If the client requires additional domains, go to <a href=
435
	 * "http://aws.amazon.com/contact-us/simpledb-limit-request/">http://aws.amazon.com/contact-us/simpledb-limit-request/</a>.
436
	 *
437
	 * @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 '.'.
438
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
439
	 * 	<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>
440
	 * 	<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>
441
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
442
	 */
443
	public function create_domain($domain_name, $opt = null)
444
	{
445
		if (!$opt) $opt = array();
446
		$opt['DomainName'] = $domain_name;
447
 
448
		return $this->authenticate('CreateDomain', $opt);
449
	}
450
 
451
	/**
452
	 * Deletes one or more attributes associated with the item. If all attributes of an item are deleted,
453
	 * the item is deleted.
454
	 *
455
	 * If you specify DeleteAttributes without attributes or values, all the attributes for the item are
456
	 * deleted.
457
	 *
458
	 * DeleteAttributes is an idempotent operation; running it multiple times on the same item or
459
	 * attribute does not result in an error response.
460
	 *
461
	 * Because Amazon SimpleDB makes multiple copies of your data and uses an eventual consistency update
462
	 * model, performing a GetAttributes or Select request (read) immediately after a DeleteAttributes or
463
	 * PutAttributes request (write) might not return the updated data.
464
	 *
465
	 * @param string $domain_name (Required) The name of the domain in which the attributes are being deleted.
466
	 * @param string $item_name (Required) The name of the base item which will contain the series of keypairs.
467
	 * @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>
468
	 * 	<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>
469
	 * 		<li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
470
	 * 			<li><code>Name</code> - <code>string</code> - Required - The name of the attribute. </li>
471
	 * 			<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>
472
	 * 			<li><code>Value</code> - <code>string</code> - Required - The value of the attribute. </li>
473
	 * 			<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>
474
	 * 		</ul></li>
475
	 * 	</ul></li></ul>
476
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
477
	 * 	<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>
478
	 * 		<li><code>Name</code> - <code>string</code> - Optional - The name of the attribute involved in the condition.</li>
479
	 * 		<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>
480
	 * 		<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>
481
	 * 	</ul></li>
482
	 * 	<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>
483
	 *  <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>
484
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
485
	 */
486
	public function delete_attributes($domain_name, $item_name, $attributes = null, $opt = null)
487
	{
488
		if (!$opt) $opt = array();
489
		$opt['DomainName'] = $domain_name;
490
		$opt['ItemName'] = $item_name;
491
 
492
		if ($attributes)
493
		{
494
			$opt = array_merge($opt, CFComplexType::map(array(
495
				'Attribute' => (is_array($attributes) ? $attributes : array($attributes))
496
			)));
497
		}
498
 
499
		if (isset($opt['Expected']))
500
		{
501
			$opt = array_merge($opt, CFComplexType::map(array(
502
				'Expected' => $opt['Expected']
503
			)));
504
			unset($opt['Expected']);
505
		}
506
 
507
		return $this->authenticate('DeleteAttributes', $opt, $this->hostname);
508
	}
509
 
510
	/**
511
	 * The <code>DeleteDomain</code> operation deletes a domain. Any items (and their attributes) in
512
	 * the domain are deleted as well. The <code>DeleteDomain</code> operation might take 10 or more
513
	 * seconds to complete.
514
	 *
515
	 * <p class="note">
516
	 * Running <code>DeleteDomain</code> on a domain that does not exist or running the function
517
	 * multiple times using the same domain name will not result in an error response.
518
	 * </p>
519
	 *
520
	 * @param string $domain_name (Required) The name of the domain to delete.
521
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
522
	 * 	<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>
523
	 * 	<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>
524
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
525
	 */
526
	public function delete_domain($domain_name, $opt = null)
527
	{
528
		if (!$opt) $opt = array();
529
		$opt['DomainName'] = $domain_name;
530
 
531
		return $this->authenticate('DeleteDomain', $opt);
532
	}
533
 
534
	/**
535
	 * Returns information about the domain, including when the domain was created, the number of
536
	 * items and attributes in the domain, and the size of the attribute names and values.
537
	 *
538
	 * @param string $domain_name (Required) The name of the domain for which to display the metadata of.
539
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
540
	 * 	<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>
541
	 * 	<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>
542
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
543
	 */
544
	public function domain_metadata($domain_name, $opt = null)
545
	{
546
		if (!$opt) $opt = array();
547
		$opt['DomainName'] = $domain_name;
548
 
549
		return $this->authenticate('DomainMetadata', $opt);
550
	}
551
 
552
	/**
553
	 * Returns all of the attributes associated with the item. Optionally, the attributes returned can be
554
	 * limited to one or more specified attribute name parameters.
555
	 *
556
	 * If the item does not exist on the replica that was accessed for this operation, an empty set is
557
	 * returned. The system does not return an error as it cannot guarantee the item does not exist on
558
	 * other replicas.
559
	 *
560
	 * If you specify GetAttributes without any attribute names, all the attributes for the item are
561
	 * returned.
562
	 *
563
	 * @param string $domain_name (Required) The name of the domain in which to perform the operation.
564
	 * @param string $item_name (Required) The name of the base item which will contain the series of keypairs.
565
	 * @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.
566
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
567
	 * 	<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>
568
	 * 	<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>
569
	 *  <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>
570
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
571
	 */
572
	public function get_attributes($domain_name, $item_name, $attribute_name = null, $opt = null)
573
	{
574
		if (!$opt) $opt = array();
575
		$opt['DomainName'] = $domain_name;
576
		$opt['ItemName'] = $item_name;
577
 
578
		if ($attribute_name)
579
		{
580
			$opt = array_merge($opt, CFComplexType::map(array(
581
				'AttributeName' => (is_array($attribute_name) ? $attribute_name : array($attribute_name))
582
			)));
583
		}
584
 
585
		return $this->authenticate('GetAttributes', $opt, $this->hostname);
586
	}
587
 
588
	/**
589
	 * The <code>ListDomains</code> operation lists all domains associated with the Access Key ID. It
590
	 * returns domain names up to the limit set by <a href=
591
	 * "#MaxNumberOfDomains">MaxNumberOfDomains</a>. A <a href="#NextToken">NextToken</a> is returned
592
	 * if there are more than <code>MaxNumberOfDomains</code> domains. Calling
593
	 * <code>ListDomains</code> successive times with the <code>NextToken</code> provided by the
594
	 * operation returns up to <code>MaxNumberOfDomains</code> more domain names with each successive
595
	 * operation call.
596
	 *
597
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
598
	 * 	<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>
599
	 * 	<li><code>NextToken</code> - <code>string</code> - Optional - A string informing Amazon SimpleDB where to start the next list of domain names.</li>
600
	 * 	<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>
601
	 * 	<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>
602
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
603
	 */
604
	public function list_domains($opt = null)
605
	{
606
		if (!$opt) $opt = array();
607
 
608
		return $this->authenticate('ListDomains', $opt);
609
	}
610
 
611
	/**
612
	 * The PutAttributes operation creates or replaces attributes in an item.
613
	 *
614
	 * A single item can have the attributes <code>{ "first_name", "first_value" }</code> and
615
	 * <code>{ "first_name", "second_value" }</code>. However, it cannot have two attribute instances where
616
	 * both the attribute name and attribute value are the same. Optionally, the requestor can supply the
617
	 * <code>Replace</code> parameter for each individual attribute. Setting this value to true causes the
618
	 * new attribute value to replace the existing attribute value(s).
619
	 *
620
	 * For example, if an item has the attributes <code>{ 'a', '1' }, { 'b', '2'}</code> and <code>{ 'b', '3' }</code>
621
	 * and the requestor calls <code>PutAttributes</code> using the attributes <code>{ 'b', '4' }</code> with
622
	 * the <code>Replace</code> parameter set to <code>true</code>, the final attributes of the item are changed
623
	 * to <code>{ 'a', '1' }</code> and <code>{ 'b', '4' }</code>, which replaces the previous values of the 'b'
624
	 * attribute with the new value.
625
	 *
626
	 * Using PutAttributes to replace attribute values that do not exist will not result in an error
627
	 * response.
628
	 *
629
	 * You cannot specify an empty string as an attribute name.
630
	 *
631
	 * Because Amazon SimpleDB makes multiple copies of your data and uses an eventual consistency update
632
	 * model, an immediate GetAttributes or Select request (read) immediately after a DeleteAttributes
633
	 * request (write) might not return the updated data.
634
	 *
635
	 * The following limitations are enforced for this operation:
636
	 *
637
	 * <ul>
638
	 * 	<li>256 attribute name-value pairs per item</li>
639
	 * 	<li>1 billion attributes per domain</li>
640
	 * 	<li>10 GB of total user data storage per domain</li>
641
	 * </ul>
642
	 *
643
	 * @param string $domain_name (Required) The name of the domain in which the attributes are being deleted.
644
	 * @param string $item_name (Required) The name of the base item which will contain the series of keypairs.
645
	 * @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>
646
	 * 	<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>
647
	 * </ul>
648
	 * @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>.
649
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
650
	 * 	<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>
651
	 * 		<li><code>Name</code> - <code>string</code> - Optional - The name of the attribute involved in the condition.</li>
652
	 * 		<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>
653
	 * 		<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>
654
	 * 	</ul></li>
655
	 * 	<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>
656
	 *  <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>
657
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
658
	 */
659
	public function put_attributes($domain_name, $item_name, $keypairs, $replace = null, $opt = null)
660
	{
661
		if (!$opt) $opt = array();
662
		$opt['DomainName'] = $domain_name;
663
		$opt['ItemName'] = $item_name;
664
 
665
		$opt = array_merge($opt, CFComplexType::map(
666
			self::remap_attribute_items_for_complextype($keypairs, $replace)
667
		));
668
 
669
		if (isset($opt['Expected']))
670
		{
671
			$opt = array_merge($opt, CFComplexType::map(array(
672
				'Expected' => $opt['Expected']
673
			)));
674
			unset($opt['Expected']);
675
		}
676
 
677
		return $this->authenticate('PutAttributes', $opt, $this->hostname);
678
	}
679
 
680
	/**
681
	 * The <code>Select</code> operation returns a set of attributes for <code>ItemNames</code> that
682
	 * match the select expression. <code>Select</code> is similar to the standard SQL SELECT
683
	 * statement.
684
	 *
685
	 * The total size of the response cannot exceed 1 MB in total size. Amazon SimpleDB automatically
686
	 * adjusts the number of items returned per page to enforce this limit. For example, if the client
687
	 * asks to retrieve 2500 items, but each individual item is 10 kB in size, the system returns 100
688
	 * items and an appropriate <code>NextToken</code> so the client can access the next page of
689
	 * results.
690
	 *
691
	 * For information on how to construct select expressions, see Using Select to Create Amazon
692
	 * SimpleDB Queries in the Developer Guide.
693
	 *
694
	 * @param string $select_expression (Required) The expression used to query the domain.
695
	 * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
696
	 * 	<li><code>NextToken</code> - <code>string</code> - Optional - A string informing Amazon SimpleDB where to start the next list of <code>ItemNames</code> .</li>
697
	 * 	<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>
698
	 * 	<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>
699
	 * 	<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>
700
	 * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
701
	 */
702
	public function select($select_expression, $opt = null)
703
	{
704
		if (!$opt) $opt = array();
705
		$opt['SelectExpression'] = $select_expression;
706
 
707
		return $this->authenticate('Select', $opt);
708
	}
709
}
710
 
711
 
712
/*%******************************************************************************************%*/
713
// EXCEPTIONS
714
 
715
class SDB_Exception extends Exception {}