Deprecation: #90956 - Alternative fetch methods and reports for GeneralUtility::getUrl()

See forge#90956

Description

The short-hand method GeneralUtility::getUrl() provides a fast way to fetch the contents of a local file or remote URL.

For Remote URLs, TYPO3 v8 provides an object-oriented (PSR-7 compatible) way by using the RequestFactory->request($url, $method, $options) API. Under the hood, the PHP library GuzzleHTTP is used, which evaluates what best option (e.g. curl library) should handle the download to TYPO3.

In general, it is recommended for any third-party extension developer to use either PHP's native file_get_contents($file) method or the RequestFactory->request() method to fetch a PSR-7 ResponseInterface object.

The additional arguments in GeneralUtility::getUrl() which allowed to send headers to the content or just do a HEAD request, or find reports on why the request did not succeed have been marked as deprecated.

PHP's native Exception Handling and the response object give enough insights already to load the HTTP headers as well, or even do HTTP POST requests.

Impact

Calling the method GeneralUtility::getUrl() with more than one method argument will trigger a PHP E_USER_DEPRECATED error.

Affected Installations

TYPO3 installations using a third-party extension with GeneralUtility::getUrl() and more than one parameter in the call.

Migration

Depending on the use-case of using the additional method parameters, certain alternatives exist since TYPO3 v8 already:

Fetching the headers (as array) from a HTTP response:

$response = GeneralUtility::makeInstance(RequestFactory::class)->request($url);
$allHeaders = $response->getHeaders();
// Also see $response->getHeader($headerName) and $response->getHeaderLine($headerName)

Sending additional headers with the HTTP request:

$response = GeneralUtility::makeInstance(RequestFactory::class)->request($url, 'GET', ['headers' => ['accept' => 'application/json']]);

Finding additional information about the response:

$response = GeneralUtility::makeInstance(RequestFactory::class)->request($url, 'GET', ['headers' => ['accept' => 'application/json']]);
if ($response->getStatusCode() >= 300) {
   $content = $response->getReasonPhrase();
} else {
   $content = $response->getBody()->getContents();
}