summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/webservices/TranslationQueryResponse.php
blob: a8f9f6ddb3bb6e1cba7551ada4e5fdab9be69828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
 * Contains code related to web services support.
 *
 * @file
 * @author Niklas Laxström
 * @license GPL-2.0-or-later
 */

/**
 * Value object that represents a HTTP(S) query response.
 * @since 2015.02
 */
class TranslationQueryResponse {
	protected $code;
	protected $reason;
	protected $headers;
	protected $body;
	protected $error;

	/**
	 * @var TranslationQuery
	 */
	protected $query;

	protected function __construct() {
	}

	public static function newFromMultiHttp( array $data, TranslationQuery $query ) {
		$response = $data['response'];
		$obj = new self();
		$obj->code = (int)$response['code'];
		$obj->reason = $response['reason'];
		$obj->headers = $response['headers'];
		$obj->body = $response['body'];
		$obj->error = $response['error'];
		$obj->query = $query;
		return $obj;
	}

	public function getStatusCode() {
		return $this->code;
	}

	public function getStatusMessage() {
		if ( $this->code === 0 ) {
			return $this->error;
		} else {
			return $this->reason;
		}
	}

	public function getBody() {
		return $this->body;
	}

	/**
	 * Get the TranslationQuery that was made for this request.
	 * @return TranslationQuery
	 * @since 2017.04
	 */
	public function getQuery() {
		return $this->query;
	}
}