1 | <?php |
||
36 | class PageIndexerRequest |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * List of actions to perform during page rendering. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $actions = []; |
||
45 | |||
46 | /** |
||
47 | * Parameters as sent from the Index Queue page indexer. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $parameters = []; |
||
52 | |||
53 | /** |
||
54 | * Headers as sent from the Index Queue page indexer. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $header = []; |
||
59 | |||
60 | /** |
||
61 | * Unique request ID. |
||
62 | * |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $requestId; |
||
66 | |||
67 | /** |
||
68 | * Username to use for basic auth protected URLs. |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | protected $username = ''; |
||
73 | |||
74 | /** |
||
75 | * Password to use for basic auth protected URLs. |
||
76 | * |
||
77 | * @var string |
||
78 | */ |
||
79 | protected $password = ''; |
||
80 | |||
81 | /** |
||
82 | * An Index Queue item related to this request. |
||
83 | * |
||
84 | * @var Item |
||
85 | */ |
||
86 | protected $indexQueueItem = null; |
||
87 | |||
88 | /** |
||
89 | * Request timeout in seconds |
||
90 | * |
||
91 | * @var float |
||
92 | */ |
||
93 | protected $timeout; |
||
94 | |||
95 | /** |
||
96 | * @var \ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager |
||
97 | */ |
||
98 | protected $logger = null; |
||
99 | |||
100 | /** |
||
101 | * @var ExtensionConfiguration |
||
102 | */ |
||
103 | protected $extensionConfiguration; |
||
104 | |||
105 | /** |
||
106 | * PageIndexerRequest constructor. |
||
107 | * |
||
108 | * @param string $jsonEncodedParameters json encoded header |
||
109 | * @param SolrLogManager|null $solrLogManager |
||
110 | * @param ExtensionConfiguration|null $extensionConfiguration |
||
111 | */ |
||
112 | 21 | public function __construct($jsonEncodedParameters = null, SolrLogManager $solrLogManager = null, ExtensionConfiguration $extensionConfiguration = null) |
|
134 | |||
135 | /** |
||
136 | * Adds an action to perform during page rendering. |
||
137 | * |
||
138 | * @param string $action Action name. |
||
139 | */ |
||
140 | 8 | public function addAction($action) |
|
144 | |||
145 | /** |
||
146 | * Executes the request. |
||
147 | * |
||
148 | * Uses headers to submit additional data and avoiding to have these |
||
149 | * arguments integrated into the URL when created by RealURL. |
||
150 | * |
||
151 | * @param string $url The URL to request. |
||
152 | * @return PageIndexerResponse Response |
||
153 | */ |
||
154 | 5 | public function send($url) |
|
180 | |||
181 | /** |
||
182 | * This method is used to retrieve an url from the frontend and decode the response. |
||
183 | * |
||
184 | * @param string $url |
||
185 | * @param PageIndexerResponse $response |
||
186 | * @return mixed |
||
187 | */ |
||
188 | 5 | protected function getUrlAndDecodeResponse($url, PageIndexerResponse $response) |
|
212 | |||
213 | /** |
||
214 | * Generates the headers to be send with the request. |
||
215 | * |
||
216 | * @return string[] Array of HTTP headers. |
||
217 | */ |
||
218 | 6 | public function getHeaders() |
|
246 | |||
247 | /** |
||
248 | * @return string |
||
249 | */ |
||
250 | 6 | protected function getUserAgent() |
|
254 | |||
255 | /** |
||
256 | * Adds an HTTP header to be send with the request. |
||
257 | * |
||
258 | * @param string $header HTTP header |
||
259 | */ |
||
260 | public function addHeader($header) |
||
264 | |||
265 | /** |
||
266 | * Checks whether this is a legitimate request coming from the Index Queue |
||
267 | * page indexer worker task. |
||
268 | * |
||
269 | * @return bool TRUE if it's a legitimate request, FALSE otherwise. |
||
270 | */ |
||
271 | 2 | public function isAuthenticated() |
|
291 | |||
292 | /** |
||
293 | * Gets the list of actions to perform during page rendering. |
||
294 | * |
||
295 | * @return array List of actions |
||
296 | */ |
||
297 | public function getActions() |
||
301 | |||
302 | /** |
||
303 | * Gets the request's parameters. |
||
304 | * |
||
305 | * @return array Request parameters. |
||
306 | */ |
||
307 | public function getParameters() |
||
311 | |||
312 | /** |
||
313 | * Gets the request's unique ID. |
||
314 | * |
||
315 | * @return string Unique request ID. |
||
316 | */ |
||
317 | 3 | public function getRequestId() |
|
321 | |||
322 | /** |
||
323 | * Gets a specific parameter's value. |
||
324 | * |
||
325 | * @param string $parameterName The parameter to retrieve. |
||
326 | * @return mixed NULL if a parameter was not set or it's value otherwise. |
||
327 | */ |
||
328 | 11 | public function getParameter($parameterName) |
|
332 | |||
333 | /** |
||
334 | * Sets a request's parameter and its value. |
||
335 | * |
||
336 | * @param string $parameter Parameter name |
||
337 | * @param string $value Parameter value. |
||
338 | */ |
||
339 | 12 | public function setParameter($parameter, $value) |
|
347 | |||
348 | /** |
||
349 | * Sets username and password to be used for a basic auth request header. |
||
350 | * |
||
351 | * @param string $username username. |
||
352 | * @param string $password password. |
||
353 | */ |
||
354 | 1 | public function setAuthorizationCredentials($username, $password) |
|
359 | |||
360 | /** |
||
361 | * Sets the Index Queue item this request is related to. |
||
362 | * |
||
363 | * @param Item $item Related Index Queue item. |
||
364 | */ |
||
365 | 6 | public function setIndexQueueItem(Item $item) |
|
369 | |||
370 | /** |
||
371 | * Returns the request timeout in seconds |
||
372 | * |
||
373 | * @return float |
||
374 | */ |
||
375 | 1 | public function getTimeout() |
|
379 | |||
380 | /** |
||
381 | * Sets the request timeout in seconds |
||
382 | * |
||
383 | * @param float $timeout Timeout seconds |
||
384 | */ |
||
385 | public function setTimeout($timeout) |
||
389 | |||
390 | /** |
||
391 | * Fetches a page by sending the configured headers. |
||
392 | * |
||
393 | * @param string $url |
||
394 | * @param string[] $headers |
||
395 | * @param float $timeout |
||
396 | * @return string |
||
397 | */ |
||
398 | 1 | protected function getUrl($url, $headers, $timeout) |
|
418 | } |
||
419 |