summaryrefslogtreecommitdiffstats
path: root/3rdparty/aws-sdk/utilities/batchrequest.class.php
blob: 978283471a40ced684b6006482d6a53219f76cf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/*
 * Copyright 2010-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */


/*%******************************************************************************************%*/
// EXCEPTIONS

/**
 * Default CFBatchRequest Exception.
 */
class CFBatchRequest_Exception extends Exception {}


/*%******************************************************************************************%*/
// CLASS

/**
 * Simplifies the flow involved with managing and executing a batch request queue. Batch requesting is the
 * ability to queue up a series of requests and execute them all in parallel. This allows for faster
 * application performance when a lot of requests are involved.
 *
 * @version 2011.12.02
 * @license See the included NOTICE.md file for more information.
 * @copyright See the included NOTICE.md file for more information.
 * @link http://aws.amazon.com/php/ PHP Developer Center
 */
class CFBatchRequest extends CFRuntime
{
	/**
	 * Stores the cURL handles that are to be processed.
	 */
	public $queue;

	/**
	 * Stores the size of the request window.
	 */
	public $limit;

	/**
	 * The proxy to use for connecting.
	 */
	public $proxy = null;

	/**
	 * The helpers to use when connecting.
	 */
	public $helpers = null;

	/**
	 * The active credential set.
	 */
	public $credentials;


	/*%******************************************************************************************%*/
	// CONSTRUCTOR

	/**
	 * Constructs a new instance of this class.
	 *
	 * @param integer $limit (Optional) The size of the request window. Defaults to unlimited.
	 * @return boolean `false` if no valid values are set, otherwise `true`.
	 */
	public function __construct($limit = null)
	{
		$this->queue = array();
		$this->limit = $limit ? $limit : -1;
		$this->credentials = new CFCredential(array());
		return $this;
	}

	/**
	 * Sets the AWS credentials to use for the batch request.
	 *
	 * @param CFCredential $credentials (Required) The credentials to use for signing and making requests.
	 * @return $this A reference to the current instance.
	 */
	public function use_credentials(CFCredential $credentials)
	{
		$this->credentials = $credentials;
		return $this;
	}

	/**
	 * Adds a new cURL handle to the request queue.
	 *
	 * @param resource $handle (Required) A cURL resource to add to the queue.
	 * @return $this A reference to the current instance.
	 */
	public function add($handle)
	{
		$this->queue[] = $handle;
		return $this;
	}

	/**
	 * Executes the batch request queue.
	 *
	 * @param array $opt (DO NOT USE) Enabled for compatibility with the method this overrides, although any values passed will be ignored.
	 * @return array An indexed array of <CFResponse> objects.
	 */
	public function send($opt = null)
	{
		$http = new $this->request_class(null, $this->proxy, null, $this->credentials);

		// Make the request
		$response = $http->send_multi_request($this->queue, array(
			'limit' => $this->limit
		));

		return $response;
	}
}