1 | <?php |
||
21 | class Agent |
||
22 | { |
||
23 | /** |
||
24 | * @var array results |
||
25 | */ |
||
26 | protected $result; |
||
27 | |||
28 | /** |
||
29 | * @var array responses |
||
30 | */ |
||
31 | protected $response; |
||
32 | |||
33 | /** |
||
34 | * @var int The maximum number of simultaneous connections allowed |
||
35 | */ |
||
36 | protected $maxConcurrent = 0; |
||
37 | |||
38 | /** |
||
39 | * @var RequestInterface[] array of Requests |
||
40 | */ |
||
41 | protected $requests; |
||
42 | |||
43 | /** |
||
44 | * @var Request default request |
||
45 | */ |
||
46 | protected $defaultRequest; |
||
47 | |||
48 | /** |
||
49 | * @var resource cUrl Multi Handle |
||
50 | */ |
||
51 | protected $mh; |
||
52 | |||
53 | /** |
||
54 | * Agent constructor. |
||
55 | * @param int $max_concurrent max current requests |
||
56 | */ |
||
57 | function __construct($max_concurrent = 10) |
||
62 | |||
63 | /** |
||
64 | * Magic setter function |
||
65 | * @param string $name attribute to set |
||
66 | * @param mixed $value the new value |
||
67 | * @return void |
||
68 | */ |
||
69 | public function __set($name, $value) |
||
79 | |||
80 | /** |
||
81 | * Magic getter function |
||
82 | * @param string $name of the attribute to get |
||
83 | * @return mixed the attribute's value |
||
84 | */ |
||
85 | public function __get($name) |
||
95 | |||
96 | /** |
||
97 | * Set the maximum number of concurrent requests |
||
98 | * @param int $max_requests maximum concurrent requests |
||
99 | */ |
||
100 | public function setMaxConcurrent($max_requests) |
||
106 | |||
107 | /** |
||
108 | * Get the currently set value of maxConcurrent |
||
109 | * @return int maximum number of concurrent requests |
||
110 | */ |
||
111 | public function getMaxConcurrent() |
||
115 | |||
116 | /** |
||
117 | * Adds a new request to the queue and returns it |
||
118 | * this request will have its default options set to global options |
||
119 | * @param null $url URL to send the request to |
||
120 | * @return RequestInterface the newly added request object |
||
121 | */ |
||
122 | public function newRequest($url = null) |
||
128 | |||
129 | /** |
||
130 | * Add a request to the request queue |
||
131 | * @param RequestInterface $request the request to add |
||
132 | * @return RequestInterface |
||
133 | */ |
||
134 | public function addRequest(RequestInterface $request) |
||
139 | |||
140 | /** |
||
141 | * Returns the Request object for a give cUrl handle |
||
142 | * @param mixed $handle |
||
143 | * @return RequestInterface request with handle |
||
144 | */ |
||
145 | private function getRequestByHandle($handle) |
||
153 | |||
154 | /** |
||
155 | * Execute the request queue |
||
156 | */ |
||
157 | public function execute() |
||
190 | } |
||
191 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.