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 | protected $requestCounter = 0; |
||
54 | |||
55 | /** |
||
56 | * Agent constructor. |
||
57 | * @param int $maxConcurrent max current requests |
||
58 | */ |
||
59 | public function __construct($maxConcurrent = 10) |
||
60 | { |
||
61 | $this->setMaxConcurrent($maxConcurrent); |
||
62 | $this->defaultRequest = new Request(); |
||
63 | $this->mh = curl_multi_init(); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Destructor |
||
68 | */ |
||
69 | public function __destruct() |
||
70 | { |
||
71 | curl_multi_close($this->mh); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Magic setter function |
||
76 | * @param string $name attribute to set |
||
77 | * @param mixed $value the new value |
||
78 | * @return void |
||
79 | */ |
||
80 | public function __set($name, $value) |
||
90 | |||
91 | /** |
||
92 | * Magic getter function |
||
93 | * @param string $name of the attribute to get |
||
94 | * @return mixed the attribute's value |
||
95 | */ |
||
96 | public function __get($name) |
||
106 | |||
107 | /** |
||
108 | * Add a default listener to be added to all new Requests |
||
109 | * @param callable $listener the listener |
||
110 | * @return void |
||
111 | */ |
||
112 | public function addListener(callable $listener) |
||
116 | |||
117 | /** |
||
118 | * Set the maximum number of concurrent requests |
||
119 | * @param int $maxConcurrent maximum concurrent requests |
||
120 | * @return void |
||
121 | */ |
||
122 | public function setMaxConcurrent($maxConcurrent) |
||
128 | |||
129 | /** |
||
130 | * Get the currently set value of maxConcurrent |
||
131 | * @return int maximum number of concurrent requests |
||
132 | */ |
||
133 | public function getMaxConcurrent() |
||
137 | |||
138 | /** |
||
139 | * Adds a new request to the queue and returns it |
||
140 | * this request will have its default options set to global options |
||
141 | * @param null $url URL to send the request to |
||
142 | * @return RequestInterface the newly added request object |
||
143 | */ |
||
144 | public function newRequest($url = null) |
||
150 | |||
151 | /** |
||
152 | * Add a request to the request queue |
||
153 | * @param RequestInterface $request the request to add |
||
154 | * @return RequestInterface |
||
155 | */ |
||
156 | public function addRequest(RequestInterface $request) |
||
161 | |||
162 | /** |
||
163 | * Returns the Request object for a give cUrl handle |
||
164 | * @param resource $handle cUrl handle |
||
165 | * @return RequestInterface Request with handle |
||
166 | */ |
||
167 | protected function getRequestByHandle($handle) |
||
175 | |||
176 | /** |
||
177 | * Execute the request queue |
||
178 | * @return void |
||
179 | */ |
||
180 | public function execute() |
||
213 | } |
||
214 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: