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

Have the Response::json and Response::xml been removed #1238

Closed
gmponos opened this Issue Sep 3, 2015 · 6 comments

Comments

Projects
None yet
6 participants
@gmponos
Copy link
Contributor

gmponos commented Sep 3, 2015

Are these two functions removed from Guzzle 6? If they are removed I can't find any reference to the Upgrading.md and to changelog.md. If they are not I can find any reference to the documentation.

@jeskew

This comment has been minimized.

Copy link
Member

jeskew commented Sep 3, 2015

They were removed as part of the adoption of PSR-7.

@mtdowling

This comment has been minimized.

Copy link
Member

mtdowling commented Sep 3, 2015

These were removed, but you're right in that this was not called out in the upgrade guide. It should be documented there though.

@mtdowling mtdowling added the area/docs label Sep 3, 2015

@mtdowling mtdowling closed this in 5f741e5 Sep 6, 2015

@dragonwize

This comment has been minimized.

Copy link

dragonwize commented Oct 8, 2015

The mention in the "upgrade" doc gives a reason for removal, which is nice but not required, but does not specify how to upgrade from the change.

Is the upgrade to now call getBody(), cast to a string, and pass to json_decode()?

@jeremeamia

This comment has been minimized.

Copy link
Member

jeremeamia commented Oct 8, 2015

  • json: json_decode($response->getBody(), ...);
  • xml: simplexml_load_string($response->getBody(), ...);
@jeremeamia

This comment has been minimized.

Copy link
Member

jeremeamia commented Oct 8, 2015

Full Guzzle 5 implementations of the json and xml functions:

public function json(array $config = [])
{
try {
return Utils::jsonDecode(
(string) $this->getBody(),
isset($config['object']) ? !$config['object'] : true,
512,
isset($config['big_int_strings']) ? JSON_BIGINT_AS_STRING : 0
);
} catch (\InvalidArgumentException $e) {
throw new ParseException(
$e->getMessage(),
$this
);
}
}
public function xml(array $config = [])
{
$disableEntities = libxml_disable_entity_loader(true);
$internalErrors = libxml_use_internal_errors(true);
try {
// Allow XML to be retrieved even if there is no response body
$xml = new \SimpleXMLElement(
(string) $this->getBody() ?: '<root />',
isset($config['libxml_options']) ? $config['libxml_options'] : LIBXML_NONET,
false,
isset($config['ns']) ? $config['ns'] : '',
isset($config['ns_is_prefix']) ? $config['ns_is_prefix'] : false
);
libxml_disable_entity_loader($disableEntities);
libxml_use_internal_errors($internalErrors);
} catch (\Exception $e) {
libxml_disable_entity_loader($disableEntities);
libxml_use_internal_errors($internalErrors);
throw new XmlParseException(
'Unable to parse response body into XML: ' . $e->getMessage(),
$this,
$e,
(libxml_get_last_error()) ?: null
);
}
return $xml;
}
. These are a little more robust, but may handle more than what you actually need.

@kpcyrd

This comment has been minimized.

Copy link

kpcyrd commented Apr 18, 2016

I'd like to point out that this change might cause a regression to #418.

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