You are here

public function HttpClientBaseFormatter::unserialize in Http Client 7.2

Same name and namespace in other branches
  1. 6.2 includes/HttpClient.inc \HttpClientBaseFormatter::unserialize()

Unserializes data.

Parameters

string $data: The data that should be unserialized.

Return value

mixed The unserialized data.

Overrides HttpClientFormatter::unserialize

File

includes/HttpClient.inc, line 362

Class

HttpClientBaseFormatter
A base formatter to format php and json.

Code

public function unserialize($data) {
  switch ($this->format) {
    case self::FORMAT_PHP:
      if (($response = @unserialize($data)) !== FALSE || $data === serialize(FALSE)) {
        return $response;
      }
      else {
        throw new Exception(t('Unserialization of response body failed.'), 1);
      }
      break;
    case self::FORMAT_JSON:
      $response = drupal_json_decode($data);
      if ($response === NULL && json_last_error() != JSON_ERROR_NONE) {
        throw new Exception(t('Unserialization of response body failed.'), 1);
      }
      return $response;
      break;
    case self::FORMAT_FORM:
      $response = array();
      parse_str($data, $response);
      return $response;
      break;
  }
}