Skip to content

Commit 37612d3

Browse files
authored
Remove legacy code for Response calls (joomla#45825)
1 parent f235e2f commit 37612d3

File tree

18 files changed

+54
-43
lines changed

18 files changed

+54
-43
lines changed

administrator/components/com_config/src/Model/ApplicationModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public function save($data)
367367
$response = HttpFactory::getHttp($options)->get('https://' . $host . Uri::root(true) . '/', ['Host' => $host], 10);
368368

369369
// If available in HTTPS check also the status code.
370-
if (!\in_array($response->code, [200, 503, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 401], true)) {
370+
if (!\in_array($response->getStatusCode(), [200, 503, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 401], true)) {
371371
throw new \RuntimeException(Text::_('COM_CONFIG_ERROR_SSL_NOT_AVAILABLE_HTTP_CODE'));
372372
}
373373
} catch (\RuntimeException $e) {

administrator/components/com_installer/src/Model/LanguagesModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ protected function getLanguages()
140140
$response = null;
141141
}
142142

143-
if ($response === null || $response->code !== 200) {
143+
if ($response === null || $response->getStatusCode() !== 200) {
144144
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_INSTALLER_MSG_ERROR_CANT_CONNECT_TO_UPDATESERVER', $updateSite), 'error');
145145

146146
return;
147147
}
148148

149-
$updateSiteXML = simplexml_load_string($response->body);
149+
$updateSiteXML = simplexml_load_string((string) $response->getBody());
150150

151151
if (!$updateSiteXML) {
152152
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_INSTALLER_MSG_ERROR_CANT_RETRIEVE_XML', $updateSite), 'error');

administrator/components/com_joomlaupdate/src/Model/UpdateModel.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ public function download()
395395
}
396396

397397
// Follow the Location headers until the actual download URL is known
398-
while (isset($head->headers['location'])) {
399-
$packageURL = (string) $head->headers['location'][0];
398+
while (isset($head->getHeaders()['location'])) {
399+
$packageURL = (string) $head->getHeaders()['location'][0];
400400

401401
try {
402402
$head = HttpFactory::getHttp($httpOptions)->head($packageURL);
@@ -589,7 +589,7 @@ public function changeAutoUpdateRegistration(AutoupdateRegisterState $targetStat
589589
}
590590

591591
// Decode response
592-
$result = json_decode((string)$response->getBody(), true);
592+
$result = json_decode((string) $response->getBody(), true);
593593

594594
// Handle validation issue
595595
if ($response->getStatusCode() === 422) {
@@ -765,12 +765,12 @@ protected function downloadPackage($url, $target)
765765
return false;
766766
}
767767

768-
if (!$result || ($result->code != 200 && $result->code != 310)) {
768+
if (!$result || ($result->getStatusCode() != 200 && $result->getStatusCode() != 310)) {
769769
return false;
770770
}
771771

772772
// Fix Indirect Modification of Overloaded Property
773-
$body = $result->body;
773+
$body = (string) $result->getBody();
774774

775775
// Write the file to disk
776776
try {
@@ -1858,11 +1858,11 @@ private function getCollectionDetailsUrls($updateSiteInfo, $joomlaTargetVersion)
18581858
$response = null;
18591859
}
18601860

1861-
if ($response === null || $response->code !== 200) {
1861+
if ($response === null || $response->getStatusCode() !== 200) {
18621862
return $return;
18631863
}
18641864

1865-
$updateSiteXML = simplexml_load_string($response->body);
1865+
$updateSiteXML = simplexml_load_string((string) $response->getBody());
18661866

18671867
foreach ($updateSiteXML->extension as $extension) {
18681868
$attribs = new \stdClass();

libraries/src/Changelog/Changelog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public function loadFromXml($url)
357357
$response = null;
358358
}
359359

360-
if ($response === null || $response->code !== 200) {
360+
if ($response === null || $response->getStatusCode() !== 200) {
361361
// @todo: Add a 'mark bad' setting here somehow
362362
Log::add(Text::sprintf('JLIB_UPDATER_ERROR_EXTENSION_OPEN_URL', $url), Log::WARNING, 'jerror');
363363

@@ -370,7 +370,7 @@ public function loadFromXml($url)
370370
xml_set_element_handler($this->xmlParser, [$this, 'startElement'], [$this, 'endElement']);
371371
xml_set_character_data_handler($this->xmlParser, [$this, 'characterData']);
372372

373-
if (!xml_parse($this->xmlParser, $response->body)) {
373+
if (!xml_parse($this->xmlParser, (string) $response->getBody())) {
374374
Log::add(
375375
\sprintf(
376376
'XML error: %s at line %d',

libraries/src/Feed/FeedFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public function getFeed($uri)
5959
throw new \RuntimeException('Unable to open the feed.', $e->getCode(), $e);
6060
}
6161

62-
if ($response->code != 200) {
62+
if ($response->getStatusCode() != 200) {
6363
throw new \RuntimeException('Unable to open the feed.');
6464
}
6565

6666
// Set the value to the XMLReader parser
67-
if (!$reader->XML($response->body, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) {
67+
if (!$reader->XML((string) $response->getBody(), null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) {
6868
throw new \RuntimeException('Unable to parse the feed.');
6969
}
7070
}

libraries/src/Http/Transport/CurlTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ public function request($method, UriInterface $uri, $data = null, array $headers
189189
$response = $this->getResponse($content, $info);
190190

191191
// Manually follow redirects if server doesn't allow to follow location using curl
192-
if ($response->code >= 301 && $response->code < 400 && isset($response->headers['Location']) && (bool) $this->getOption('follow_location', true)) {
193-
$redirect_uri = new Uri($response->headers['Location'][0]);
192+
if ($response->getStatusCode() >= 301 && $response->getStatusCode() < 400 && isset($response->getHeaders()['Location']) && (bool) $this->getOption('follow_location', true)) {
193+
$redirect_uri = new Uri($response->getHeaders()['Location'][0]);
194194

195195
if (\in_array($redirect_uri->getScheme(), ['file', 'scp'])) {
196196
throw new \RuntimeException('Curl redirect cannot be used in file or scp requests.');

libraries/src/Http/Transport/SocketTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ public function request($method, UriInterface $uri, $data = null, array $headers
130130
$content = $this->getResponse($content);
131131

132132
// Follow Http redirects
133-
if ($content->code >= 301 && $content->code < 400 && isset($content->headers['Location'][0])) {
134-
return $this->request($method, new Uri($content->headers['Location'][0]), $data, $headers, $timeout, $userAgent);
133+
if ($content->getStatusCode() >= 301 && $content->getStatusCode() < 400 && isset($content->getHeaders()['Location'][0])) {
134+
return $this->request($method, new Uri($content->getHeaders()['Location'][0]), $data, $headers, $timeout, $userAgent);
135135
}
136136

137137
return $content;

libraries/src/Installer/InstallerHelper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ public static function downloadPackage($url, $target = false)
9494
}
9595

9696
// Convert keys of headers to lowercase, to accommodate for case variations
97-
$headers = array_change_key_case($response->headers, CASE_LOWER);
97+
$headers = array_change_key_case($response->getHeaders(), CASE_LOWER);
9898

99-
if (302 == $response->code && !empty($headers['location'])) {
99+
if (302 == $response->getStatusCode() && !empty($headers['location'])) {
100100
return self::downloadPackage($headers['location']);
101101
}
102102

103-
if (200 != $response->code) {
104-
Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT', $response->code), Log::WARNING, 'jerror');
103+
if (200 != $response->getStatusCode()) {
104+
Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_DOWNLOAD_SERVER_CONNECT', $response->getStatusCode()), Log::WARNING, 'jerror');
105105

106106
return false;
107107
}
@@ -125,7 +125,7 @@ public static function downloadPackage($url, $target = false)
125125
}
126126

127127
// Fix Indirect Modification of Overloaded Property
128-
$body = $response->body;
128+
$body = (string) $response->getBody();
129129

130130
// Write buffer to file
131131
File::write($target, $body);

libraries/src/TUF/HttpLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function load(string $locator, int $maxBytes): PromiseInterface
3737
throw new HttpLoaderException($e->getMessage(), $e->getCode(), $e);
3838
}
3939

40-
if ($response->code !== 200) {
40+
if ($response->getStatusCode() !== 200) {
4141
throw new RepoFileNotFound();
4242
}
4343

libraries/src/Updater/Adapter/CollectionAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public function findUpdate($options)
224224
$this->xmlParser = xml_parser_create('');
225225
xml_set_element_handler($this->xmlParser, [$this, '_startElement'], [$this, '_endElement']);
226226

227-
if (!xml_parse($this->xmlParser, $response->body)) {
227+
if (!xml_parse($this->xmlParser, (string) $response->getBody())) {
228228
// If the URL is missing the .xml extension, try appending it and retry loading the update
229229
if (!$this->appendExtension && (!str_ends_with($this->_url, '.xml'))) {
230230
$options['append_extension'] = true;

0 commit comments

Comments
 (0)