Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
simonschaufi opened this issue Oct 15, 2024 · 0 comments

Comments

@simonschaufi
Copy link
Collaborator

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

https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/10.4/Deprecation-90956-AlternativeFetchMethodsAndReportsForGeneralUtilitygetUrl.html

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

See 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();
}

PHP-API, FullyScanned, ext:core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant